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 !')
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')
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")
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_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)
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)
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')
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)
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)
def test_most_significant_state(): r = Results() r.add(Result(Ok)) assert Ok == r.most_significant_state r.add(Result(Critical)) assert Critical == r.most_significant_state r.add(Result(Warn)) assert Critical == r.most_significant_state
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])
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)
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)
def test_len(self): r = Results() r.add(Result(Ok), Result(Ok), Result(Ok)) self.assertEqual(3, len(r))
def test_first_significant(): r = Results() r.add(Result(Critical), Result(Unknown, 'r1'), Result(Unknown, 'r2'), Result(Ok)) assert Result(Unknown, 'r1') == r.first_significant
def test_lookup_by_index(): r = Results() result = Result(Ok, '', nagiosplugin.Metric('met1', 0)) r.add(Result(Ok, 'other'), result) assert r[1] == result
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)
def test_len(): r = Results() r.add(Result(Ok), Result(Ok), Result(Ok)) assert 3 == len(r)
def test_add_should_fail_unless_result_passed(self): with self.assertRaises(ValueError): Results(True)
def test_add_in_init(self): results = Results(Result(Unknown, 'r1'), Result(Unknown, 'r2')) self.assertEqual(2, len(results))
def test_lookup_by_metric_name(): r = Results() result = Result(Ok, '', nagiosplugin.Metric('met1', 0)) r.add(result, Result(Ok, 'other')) assert r['met1'] == result
def test_contains(): results = Results() r1 = Result(Unknown, 'r1', nagiosplugin.Metric('m1', 1)) results.add(r1) assert 'm1' in results assert 'm2' not in results
def test_most_signigicant(): r = Results() r.add(Result(Ok), Result(Warn), Result(Ok), Result(Warn)) assert [Warn, Warn] == [result.state for result in r.most_significant]
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])
def test_most_significant_should_return_empty_set_if_empty(self): self.assertEqual([], Results().most_significant)
def test_iterate_in_order_of_descending_states(): r = Results() r.add(Result(Warn), Result(Ok), Result(Critical), Result(Warn)) assert [Critical, Warn, Warn, Ok] == [result.state for result in r]
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)
def test_most_significant_state_shoud_raise_valueerror_if_empty(self): with self.assertRaises(ValueError): Results().most_significant_state