Пример #1
0
 def test_verbose(self):
     self.assertEqual(['critical: reason1', 'warning: reason2'],
                      Summary().verbose(
                          nagiosplugin.Results(
                              nagiosplugin.Result(nagiosplugin.Critical,
                                                  'reason1'),
                              nagiosplugin.Result(nagiosplugin.Ok,
                                                  'ignore'),
                              nagiosplugin.Result(nagiosplugin.Warn,
                                                  'reason2'))))
Пример #2
0
 def evaluate(self, metric, resource):
     r_state = nagiosplugin.Ok
     if metric.value is None:
         return nagiosplugin.Result(r_state, 'No RRSIGs', metric)
     if self.warn_seconds >= metric.value:
         r_state = nagiosplugin.Warn
     if self.crit_seconds >= metric.value:
         r_state = nagiosplugin.Critical
     return nagiosplugin.Result(r_state, 'RRSIGs expiring in {} seconds ({} hours)'.format(
         metric.value, metric.value/3600), metric)
Пример #3
0
 def evaluate(self, metric, resource):
     delegation = metric.value.get('delegation')
     dnssec = metric.value.get('dnssec')
     if delegation['status'] > status.DELEGATION_STATUS_SECURE:
         if delegation['status'] == status.DELEGATION_STATUS_BOGUS:
             return nagiosplugin.Result(nagiosplugin.Critical, 'Delegation is BOGUS', metric)
         if delegation['status'] == status.DELEGATION_STATUS_INSECURE:
             if resource.insecure_ok:
                 return nagiosplugin.Result(nagiosplugin.Ok, 'Delegation is INSECURE', metric)
         return nagiosplugin.Result(nagiosplugin.Warn, 'Delegation is {}'.format(
             status.delegation_status_mapping[delegation['status']]), metric)
     return nagiosplugin.Result(nagiosplugin.Ok, 'Delegation is SECURE', metric)
Пример #4
0
    def evaluate(self, metric, resource):
        open_ports_critical = []
        for port in resource.open_ports:
            if not port in resource.allowed_ports:
                open_ports_critical.append(port)

        if len(open_ports_critical) > 0:
            return nagiosplugin.Result(
                nagiosplugin.Critical,
                'open port(s) found: {}'.format(str.join(',', open_ports_critical))
            )
        else:
            return nagiosplugin.Result(nagiosplugin.Ok)
Пример #5
0
    def evaluate(self, metric, resource):
        if len(metric.value) > 0:
            state = nagiosplugin.state.Critical
        else:
            state = nagiosplugin.state.Ok

        return nagiosplugin.Result(state, metric=metric)
Пример #6
0
 def evaluate(self, metric: nagiosplugin.Metric,
              resource: nagiosplugin.Resource) -> nagiosplugin.Result:
     if self.check_lifetime and metric.value is not None:
         if self.critical.match(metric.value):
             return nagiosplugin.Result(
                 nagiosplugin.Critical,
                 hint=self.fmt_hint.format(value=self.critical_days),
                 metric=metric)
         elif self.warning.match(metric.value):
             return nagiosplugin.Result(
                 nagiosplugin.Warn,
                 hint=self.fmt_hint.format(value=self.warning_days),
                 metric=metric)
         else:
             return super(DaysValidContext, self).evaluate(metric, resource)
     else:
         return nagiosplugin.Result(nagiosplugin.Ok)
Пример #7
0
 def test_state_ranges_values(self):
     test_cases = [
         (1, nagiosplugin.Ok, None),
         (3, nagiosplugin.Warn, 'outside range 0:2'),
         (5, nagiosplugin.Critical, 'outside range 0:4'),
     ]
     c = ScalarContext('ctx', '0:2', '0:4')
     for value, exp_state, exp_reason in test_cases:
         m = nagiosplugin.Metric('time', value)
         self.assertEqual(nagiosplugin.Result(exp_state, exp_reason, m),
                          c.evaluate(m, None))
Пример #8
0
 def test_ok_returns_first_result(self):
     results = nagiosplugin.Results(
         nagiosplugin.Result(nagiosplugin.Ok, 'result 1'),
         nagiosplugin.Result(nagiosplugin.Ok, 'result 2'))
     self.assertEqual('result 1', Summary().ok(results))
Пример #9
0
 def test_problem_returns_first_significant(self):
     results = nagiosplugin.Results(
         nagiosplugin.Result(nagiosplugin.Ok, 'result 1'),
         nagiosplugin.Result(nagiosplugin.Critical, 'result 2'))
     self.assertEqual('result 2', Summary().problem(results))
Пример #10
0
 def test_summary_str_calls_problem_if_state_not_ok(self):
     c = Check(FakeSummary())
     c.results.add(nagiosplugin.Result(nagiosplugin.Critical))
     self.assertEqual('Houston, we have a problem', c.summary_str)
Пример #11
0
 def addResult(self, state, message):
     self.results.add(nagiosplugin.Result(state, message))
Пример #12
0
 def evaluate(self, metric, resource):
     if metric.value['errors']:
         return nagiosplugin.Result(nagiosplugin.Critical, 'RRSIG error', metric)
     if metric.value['warnings']:
         return nagiosplugin.Result(nagiosplugin.Warn, 'RRSIG issue', metric)
     return nagiosplugin.Result(nagiosplugin.Ok, 'RRSIGs validate correctly', metric)
Пример #13
0
 def evaluate(self, metric, resource):
     return nagiosplugin.Result(nagiosplugin.Critical, metric.value)
Пример #14
0
    def probe(self):
        try:
            self.monitorDict.update(
                self.analyzeData(self.solrCore,
                                 [self.statusData, self.summaryData]))
        except ValueError as valueErr:
            nagiosplugin.Result(
                nagiosplugin.Unknown,
                hint='something went wrong gathering data from Solr')
            return

        if self.monitor in 'index' 'fts':
            monitorData = self.monitorDict[self.solrCore][self.monitor]
        else:
            monitorData = self.monitorDict[self.solrCore][self.monitor][
                self.item]

        if self.monitor == 'handlers':
            for key, value in monitorData.items():
                if key in 'errors' 'timeouts' 'requests':
                    uom = 'c'
                    if key == 'errors':
                        context = 'nonZeroCrit' if not self.relaxed else 'noCtx'
                    elif key == 'timeouts':
                        context = 'nonZeroWarn' if not self.relaxed else 'noCtx'
                    else:
                        context = 'noCtx'
                    self.metrics.append(
                        nagiosplugin.Metric(key,
                                            float(value),
                                            uom=uom,
                                            context=context))
                elif key in '75thPcRequestTime' '99thPcRequestTime' 'avgTimePerRequest':
                    uom = 'ms'
                    if key == 'avgTimePerRequest':
                        context = context = self.monitor + ':' + self.item
                        self.metrics.insert(
                            0,
                            nagiosplugin.Metric(key,
                                                float(value),
                                                uom=uom,
                                                context=context))
                    else:
                        context = 'noCtx'
                        self.metrics.append(
                            nagiosplugin.Metric(key,
                                                float(value),
                                                uom=uom,
                                                context=context))

        elif self.monitor == 'caches':
            for key, value in monitorData.items():
                if key == 'hitratio':
                    uom = '%'
                    context = context = self.monitor + ':' + self.item
                    value = float(value) * 100
                    self.metrics.insert(
                        0,
                        nagiosplugin.Metric(key,
                                            float(value),
                                            uom=uom,
                                            context=context))
                else:
                    uom = 'c'
                    context = 'noCtx'
                    self.metrics.append(
                        nagiosplugin.Metric(key,
                                            float(value),
                                            uom=uom,
                                            context=context))

        elif self.monitor in 'index' 'fts':
            for key, value in monitorData.items():
                uom = 'b' if key == 'indexSize' else 'c'
                if key == self.item:
                    self.metrics.insert(
                        0,
                        nagiosplugin.Metric(key,
                                            float(value),
                                            uom=uom,
                                            context=self.monitor + ':' +
                                            self.item))
                else:
                    self.metrics.append(
                        nagiosplugin.Metric(key,
                                            float(value),
                                            uom=uom,
                                            context='noCtx'))

        for metric in self.metrics:
            yield metric