def test_icingaNotification_getOutput2(): o = test_objects.icingaNotifGen(1).getObj("list")[0] o["_source"]["icinga"]["notification_type"] = "RECOVERY" o["_source"]["icinga"]["check_result"]["state"] = 0 assert (icingaNotification.icingaNotification( o, "user").getNormalOutput() == "test.ls.intra - OK: HOST - test text")
def test_parseNotifications_OKArgs2(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=3).getObj("class") tmp = map(lambda x: x.getNormalOutput(), nl) o = list(tmp) print(o) assert parsing.parseNotifications(nl, "sms") == o
def test_parseNotifications_OKArgs9(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=1, serviceCount=1).getObj("class") o = "*Icinga alert:*\n:green_heart: *OK:*\n\ttest.ls.intra0 - " \ "<test.com/dashboard#!/monitoring/service/show?host=test.ls.intra0&service=service|service>: dummy output. " \ "test text\n" assert parsing.parseNotifications(nl, "slack", "test.com") == o
def test_icingaNotification_getOutput1(): o = test_objects.icingaNotifGen(1).getObj("list")[0] o["_source"]["icinga"]["check_result"]["state"] = "44" o["_source"]["icinga"]["check_result"]["vars_before"]["state"] = "55" o["_source"]["icinga"]["notification_type"] = "PROBLEM" assert (icingaNotification.icingaNotification(o, "user").getNormalOutput() == "test.ls.intra - CRITICAL: HOST dummy output. test text")
def test_parseNotifications_OKArgs5(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=5, serviceCount=5).getObj("class") o = [ "test.ls.intra: test.ls.intra0!service test.ls.intra1!service test.ls.intra2!service test.ls.intra3!service " "test.ls.intra4!service " ] assert parsing.parseNotifications(nl, "sms") == o
def test_parseNotifications_OKArgs7(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=5, hostCount=1, serviceCount=1).getObj("class") o = [ 'test.ls.intra0!service: test.ls.intra0 test.ls.intra0 test.ls.intra0 test.ls.intra0 test.ls.intra0 ' ] assert parsing.parseNotifications(nl, "sms") == o
def test_aggregateBy_AggregationBasic3(): e = dict() by = "c" c = test_objects.icingaNotifGen(15).getObj("list") e = {"Host(UP)": c} assert aggregation.aggregateBy(c, by) == e
def test_aggregateBy_AggregationBasic5(): e = dict() by = "d" c = test_objects.icingaNotifGen(5).getObj("class") e = {"one": c, "two": c} print(aggregation.aggregateBy(c, by)) assert aggregation.aggregateBy(c, by) == e
def test_aggregateBy_AggregationBasic2(): # basic check if everything works as it should (second usage) e = dict() by = "a" c = test_objects.icingaNotifGen().getObj("class") e = {"1": c} assert aggregation.aggregateBy(c, by) == e
def test_parseNotifications_OKArgs3(caplog): c = 3 caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=c).getObj("class") out = parsing.parseNotifications(nl, "email").get_payload()[0].get_payload() assert len(out.split("\n")) == 8 and out.split("\n")[0:3] == [ "OK: 1x", "WARNING: 1x", "CRITICAL: 1x" ]
def test_handleNotifications_BadArgs4(): u = test_objects.icingaUserGen(10, False).generateOne() u["vars"].pop("notification_options") uo = {"testuser": u} us = "TestUser" l = test_objects.icingaNotifGen().getObj("list") (r, lc) = handling.handleNotifications(l, uo, us, None, None, None, None, None, None) assert r == 1 assert lc == None
def test_parseNotifications_OKArgs8(caplog): caplog.set_level(logging.DEBUG) for notif_type in [ "ACKNOWLEDGEMENT", "CUSTOM", "DOWNTIMESTART", "DOWNTIMEEND", "DOWNTIMEREMOVED", "FLAPPINGSTART", "FLAPPINGEND" ]: nl = test_objects.icingaNotifGen( count=1, hostCount=1, serviceCount=1, notificationType=notif_type).getObj("class") o = [ 'test.ls.intra0 - ' + notif_type + ': test.ls.intra0!service - test text' ] assert parsing.parseNotifications(nl, "sms") == o
def test_handleNotifications_BadArgs5( mock_parseNotifications, mock_sendSlackMessage, mock_sendCall, mock_sendMail, mock_sendSMS ): u = test_objects.icingaUserGen(10, False).generateOne() u["vars"]["notification_options"] = {"sms": ["ok"], "email": ["ok"], "call": ["ok"]} uo = {"testuser": u} us = "TestUser" l = test_objects.icingaNotifGen().getObj("list") mock_parseNotifications.return_value = "Testing_output" mock_sendSMS.return_value = 1 mock_sendCall.return_value = (1, dict()) mock_sendMail.return_value = 1 mock_sendSlackMessage.return_value = 1 (r, lc) = handling.handleNotifications(l, uo, us, None, None, None, None, None, None) assert r >= 1 assert lc == dict()
def test_handleNotifications_BadArgs2_call(): # args: try some wrong data types # prepare test data lst = {"pershing": test_objects.icingaUserGen(1).generateOne()} for e in ["email", "sms"]: lst["pershing"]["vars"]["notification_options"].pop(e) assert ( handling.handleNotifications( test_objects.icingaNotifGen().getObj("list"), lst, "pershing", {"bad": "modemdict"}, "mailserver.something", ["this should be dict"], ["this should be dict"], ["this should be dict"], None )[0] == 1 )
def test_handleNotifications_OKArgs1( mock_parseNotifications, mock_sendSlackMessage, mock_sendCall, mock_sendMail, mock_sendSMS ): # try some correct things l = test_objects.icingaNotifGen().getObj("list") u = test_objects.icingaUserGen(10, False).generateOne() uo = {"testuser": u} us = "TestUser" mock_parseNotifications.return_value = "Testing_output" mock_sendSMS.return_value = 1 mock_sendCall.return_value = (1, dict()) mock_sendMail.return_value = 1 mock_sendSlackMessage.return_value = 1 (r, lc) = handling.handleNotifications(l, uo, us, None, None, None, None, None, None) assert r >= 2 assert lc == dict() mock_parseNotifications.assert_called() mock_sendSMS.assert_called() mock_sendCall.assert_called() mock_sendMail.assert_called()
def test_parseNotifications_OKArgs6(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(count=5, hostCount=3, serviceCount=2).getObj("class") o = ['test.ls.intra0: 2', 'test.ls.intra1: 2', 'test.ls.intra2: 1'] assert parsing.parseNotifications(nl, "sms") == o
def test_parseNotifications_OKArgs4(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen(serviceCount=3).getObj("class") o = ["test.ls.intra: 2000x SERVICE"] assert parsing.parseNotifications(nl, "sms") == o
def test_parseNotifications_OKArgs1(caplog): caplog.set_level(logging.DEBUG) nl = test_objects.icingaNotifGen().getObj("class") o = ["Host(UP): 2000x HOST"] assert parsing.parseNotifications(nl, "sms") == o
def test_icingaNotification_getOutput3(): o = test_objects.icingaNotifGen(1).getObj("list")[0] o["_source"]["icinga"]["notification_type"] = "CUSTOM" assert (icingaNotification.icingaNotification(o, "user").getNormalOutput() == "test.ls.intra - CUSTOM: HOST - test text")
def test_icingaNotification_getOutput4(): o = test_objects.icingaNotifGen(1).getObj("list")[0] o["_source"]["icinga"]["notification_type"] = "IMPOSSIBLE" assert (icingaNotification.icingaNotification(o, "user").getNormalOutput() == "test.ls.intra - PROBLEM: HOST dummy output. test text")
def test_icingaNotification_BadArgs2(): o = test_objects.icingaNotifGen().getObj("list") with pytest.raises(TypeError): assert icingaNotification.icingaNotification(o, None)
def test_icingaNotification_BadArgs3(): o = test_objects.icingaNotifGen().getObj( "list")[0]["_source"]["icinga"].pop("host") with pytest.raises(TypeError): assert icingaNotification.icingaNotification(o, "user")
def test_icingaNotification_BasicInit2(): o = test_objects.icingaNotifGen(1).getObj("list")[0] o["_source"]["icinga"]["service"] = "Dummy" assert icingaNotification.icingaNotification(o, "user")
def test_icingaNotification_BasicInit1(): o = test_objects.icingaNotifGen(1).getObj("list")[0] assert icingaNotification.icingaNotification(o, "user")
def test_icingaNotification_getNormalOutput_BadArgs1(): o = (test_objects.icingaNotifGen().getObj("list")[0]["_source"] ["icinga"].pop("check_result")) with pytest.raises(KeyError): assert icingaNotification.icingaNotification(o, None).getNormalOutput()