Example #1
0
 def test_most_significant_state(self):
     r = Results()
     r.add(Result(Ok))
     self.assertEqual(Ok, r.most_significant_state)
     r.add(Result(Critical))
     self.assertEqual(Critical, r.most_significant_state)
     r.add(Result(Warn))
     self.assertEqual(Critical, r.most_significant_state)
Example #2
0
 def test_ok(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Ok
     from check_dns_sync.check_dns_sync import AuditSummary
     results = Results()
     ok_r1 = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     ok_r2 = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     results.add(ok_r1)
     results.add(ok_r2)
     summary = AuditSummary(None)
     sum_ok = summary.ok(results)
     self.assertEqual(sum_ok, "All zone are in sync")
Example #3
0
 def test_ok(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Ok
     from checkpkgaudit.checkpkgaudit import AuditSummary
     results = Results()
     ok_r1 = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     ok_r2 = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     results.add(ok_r1)
     results.add(ok_r2)
     summary = AuditSummary()
     sum_ok = summary.ok(results)
     self.assertEqual(sum_ok, '0 vulnerabilities found !')
Example #4
0
 def test_ok(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Ok
     from checkopenbgpd.checkopenbgpd import AuditSummary
     results = Results()
     ok_r1 = Result(Ok, '', nagiosplugin.Metric('met1', 529001))
     ok_r2 = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     results.add(ok_r1)
     results.add(ok_r2)
     summary = AuditSummary()
     sum_ok = summary.ok(results)
     self.assertEqual(sum_ok, 'All bgp sessions in correct state')
Example #5
0
 def test_problem_unknown(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Critical, Unknown
     from check_dns_sync.check_dns_sync import AuditSummary
     hint = "No result. Domain probably does not exist"
     results = Results()
     r1 = Result(Critical, '', nagiosplugin.Metric('met1', 1))
     r2 = Result(Unknown, hint, nagiosplugin.Metric('met1', 0))
     results.add(r1)
     results.add(r2)
     summary = AuditSummary(None)
     sum_unknown = summary.problem(results)
     self.assertEqual(sum_unknown, hint)
Example #6
0
 def test_problem_crit_non_metric(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Critical
     from check_dns_sync.check_dns_sync import AuditSummary
     message = "ns1,ns2 are behind"
     results = Results()
     r1 = Result(Critical, '', nagiosplugin.Metric('ns1', 1))
     r2 = Result(Critical, '', nagiosplugin.Metric('ns2', 1))
     results.add(r1)
     results.add(r2)
     summary = AuditSummary(False)
     sum_crit = summary.problem(results)
     self.assertEqual(sum_crit, message)
Example #7
0
 def test_problem_unknown(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Critical, Unknown
     from checkpkgaudit.checkpkgaudit import AuditSummary
     hint = 'masterdns pkg: jail_attach(masterdns): Operation not permitted'
     results = Results()
     r1 = Result(Critical, '', nagiosplugin.Metric('met1', 1))
     r2 = Result(Unknown, hint, nagiosplugin.Metric('met1', 0))
     results.add(r1)
     results.add(r2)
     summary = AuditSummary()
     sum_unknown = summary.problem(results)
     self.assertEqual(sum_unknown, hint)
Example #8
0
 def test_problem_crit(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Critical
     from checkpkgaudit.checkpkgaudit import AuditSummary
     message = "found 2 vulnerable(s) pkg(s) in : ns1, ns2"
     results = Results()
     r1 = Result(Critical, '', nagiosplugin.Metric('ns1', 1))
     r2 = Result(Critical, '', nagiosplugin.Metric('ns2', 1))
     results.add(r1)
     results.add(r2)
     summary = AuditSummary()
     sum_crit = summary.problem(results)
     self.assertEqual(sum_crit, message)
 def test_critical(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Critical
     from checklayer2link.checklayer2link import AuditSummary
     from checklayer2link.checklayer2link import CheckLayer2Link
     resource = CheckLayer2Link('192.168.0.1')
     results = Results()
     crit_r1 = Result(Critical, '', nagiosplugin.Metric('mac', 0,
                      context='arp', resource=resource))
     results.add(crit_r1)
     summary = AuditSummary()
     sum_pb = summary.problem(results)
     self.assertEquals(sum_pb, 'layer 2 for ip 192.168.0.1 is down')
 def test_ok(self):
     from nagiosplugin.result import Result, Results
     from nagiosplugin.state import Ok
     from checklayer2link.checklayer2link import AuditSummary
     from checklayer2link.checklayer2link import CheckLayer2Link
     resource = CheckLayer2Link('192.168.0.1')
     results = Results()
     ok_r1 = Result(Ok, '', nagiosplugin.Metric('mac', 1, context='arp',
                    resource=resource))
     results.add(ok_r1)
     summary = AuditSummary()
     sum_ok = summary.ok(results)
     self.assertEquals(sum_ok, 'layer 2 for ip 192.168.0.1 is up')
Example #11
0
 def test_metric_resorce(self):
     res = object()
     m = nagiosplugin.Metric('foo', 1, resource=res)
     self.assertEqual(Result(Ok, metric=m).resource, res)
Example #12
0
 def test_context_should_be_none_for_contextless_metric(self):
     self.assertIsNone(Result(Ok).context)
Example #13
0
 def test_metric_context(self):
     ctx = object()
     m = nagiosplugin.Metric('foo', 1, contextobj=ctx)
     self.assertEqual(Result(Ok, metric=m).context, ctx)
Example #14
0
 def test_str_metric_with_hint(self):
     self.assertEqual('2 (unexpected)',
                      str(Result(Warn, 'unexpected',
                                 nagiosplugin.Metric('foo', 2))))
Example #15
0
 def test_str_metric_only(self):
     self.assertEqual(
         '3', str(Result(Warn, metric=nagiosplugin.Metric('foo', 3))))
Example #16
0
 def test_str_hint_only(self):
     self.assertEqual('how come?', str(Result(Warn, 'how come?')))
Example #17
0
 def test_lookup_by_index(self):
     r = Results()
     result = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     r.add(Result(Ok, 'other'), result)
     self.assertEqual(r[1], result)
Example #18
0
 def test_contains(self):
     results = Results()
     r1 = Result(Unknown, 'r1', nagiosplugin.Metric('m1', 1))
     results.add(r1)
     self.assertTrue('m1' in results)
     self.assertFalse('m2' in results)
Example #19
0
 def test_first_significant(self):
     r = Results()
     r.add(Result(Critical), Result(Unknown, 'r1'), Result(Unknown, 'r2'),
           Result(Ok))
     self.assertEqual(Result(Unknown, 'r1'), r.first_significant)
Example #20
0
 def test_most_signigicant(self):
     r = Results()
     r.add(Result(Ok), Result(Warn), Result(Ok), Result(Warn))
     self.assertEqual([Warn, Warn],
                      [result.state for result in r.most_significant])
Example #21
0
 def test_resorce_should_be_none_for_resourceless_metric(self):
     self.assertIsNone(Result(Ok).resource)
Example #22
0
 def test_iterate_in_order_of_descending_states(self):
     r = Results()
     r.add(Result(Warn), Result(Ok), Result(Critical), Result(Warn))
     self.assertEqual([Critical, Warn, Warn, Ok],
                      [result.state for result in r])
Example #23
0
 def test_len(self):
     r = Results()
     r.add(Result(Ok), Result(Ok), Result(Ok))
     self.assertEqual(3, len(r))
Example #24
0
 def test_str_empty(self):
     self.assertEqual('', str(Result(Warn)))
Example #25
0
 def test_add_in_init(self):
     results = Results(Result(Unknown, 'r1'), Result(Unknown, 'r2'))
     self.assertEqual(2, len(results))
Example #26
0
 def test_lookup_by_metric_name(self):
     r = Results()
     result = Result(Ok, '', nagiosplugin.Metric('met1', 0))
     r.add(result, Result(Ok, 'other'))
     self.assertEqual(r['met1'], result)