def test_simple_rbn_host_notification(test_config, site, core, log): site.set_config("CORE", core, with_restart=True) # Open the log file and scan to end l = WatchLog(site, log) # Set object down to trigger a notification site.send_host_check_result("notify-test", 1, "FAKE DOWN", expected_state=1) # Now check for appearing log lines - one after the other # NOTE: "] " is necessary to get the actual log line and not the external command execution l.check_logged( "] HOST NOTIFICATION: check-mk-notify;notify-test;DOWN;check-mk-notify;FAKE DOWN", timeout=20, ) l.check_logged( "] HOST NOTIFICATION: hh;notify-test;DOWN;mail;FAKE DOWN", timeout=20, ) l.check_logged( "] HOST NOTIFICATION RESULT: hh;notify-test;OK;mail;Spooled mail to local mail transmission agent;", timeout=20, )
def test_child_down_and_up_while_not_reachable(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set parent down, expect DOWN notification _send_parent_down(scenario, site, log) log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # - set child down, expect UNREACHABLE notification _send_child_down_expect_unreachable(scenario, site, log) # - Set child up, expect no notification site.send_host_check_result("notify-test-child", STATE_UP, "UP") log.check_logged("HOST ALERT: notify-test-child;UP;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UP;check-mk-notify;" ) else: log.check_not_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UP") # - Set parent up, expect UP notification _send_parent_recovery(scenario, site, log)
def test_child_down_after_parent_recovers(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set parent down, expect DOWN notification _send_parent_down(scenario, site, log) log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # - set child down, expect UNREACHABLE notification _send_child_down_expect_unreachable(scenario, site, log) # - Set parent up, expect UP notification _send_parent_recovery(scenario, site, log) # - Next child check DOWN, expect no notification (till next parent check confirms UP) site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN") log.check_logged("HOST ALERT: notify-test-child;DOWN;HARD;1;") if scenario.core == "cmc": # - Set parent UP (again), expect DOWN notification for child site.send_host_check_result("notify-test-parent", STATE_UP, "UP") log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;DOWN;check-mk-notify;" )
def test_log(request, web, site, fake_sendmail): core, log = request.param site.set_config("CORE", core, with_restart=True) users = { "hh": { "alias": "Harry Hirsch", "password": "******", "email": u"%s@localhost" % web.site.id, 'contactgroups': ['all'], }, } expected_users = set(["cmkadmin", "automation"] + list(users.keys())) web.add_htpasswd_users(users) all_users = web.get_all_users() assert not expected_users - set(all_users.keys()) site.live.command("[%d] STOP_EXECUTING_HOST_CHECKS" % time.time()) site.live.command("[%d] STOP_EXECUTING_SVC_CHECKS" % time.time()) web.add_host("notify-test", attributes={ "ipaddress": "127.0.0.1", }) web.activate_changes() with WatchLog(site, log, default_timeout=20) as l: yield l site.live.command("[%d] START_EXECUTING_HOST_CHECKS" % time.time()) site.live.command("[%d] START_EXECUTING_SVC_CHECKS" % time.time()) web.delete_host("notify-test") web.delete_htpasswd_users(list(users.keys())) web.activate_changes()
def test_unreachable_child_after_parent_is_down(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set parent down, expect DOWN notification _send_parent_down(scenario, site, log) log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # - set child down, expect UNREACHABLE notification _send_child_down_expect_unreachable(scenario, site, log)
def test_parent_down_child_state_changes(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set parent down, expect DOWN notification _send_parent_down(scenario, site, log) log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # - set child down, expect UNREACHABLE notification assert site.get_host_state("notify-test-child") == STATE_UP site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN", expected_state=STATE_UNREACHABLE) log.check_logged("HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) else: log.check_not_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) # - set child up, expect UP notification site.send_host_check_result("notify-test-child", STATE_UP, "UP") log.check_logged("HOST ALERT: notify-test-child;UP;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;") else: log.check_not_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;") # - set child down, expect UNREACHABLE notification assert site.get_host_state("notify-test-child") == STATE_UP site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN", expected_state=STATE_UNREACHABLE) log.check_logged("HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) else: log.check_not_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" )
def test_parent_down_child_up_on_up_result(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set child down, expect DOWN notification _send_child_down(scenario, site, log) # - Set parent down, expect DOWN notification _send_parent_down(scenario, site, log) log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # - Set child up, expect UP notification _send_child_recovery(scenario, site, log)
def test_simple_rbn_service_notification(test_config, site, core, log): site.set_config("CORE", core, with_restart=True) with WatchLog(site, log, default_timeout=20) as l: site.send_service_check_result("notify-test", "PING", 2, "FAKE CRIT") # NOTE: "] " is necessary to get the actual log line and not the external command execution l.check_logged( "] SERVICE NOTIFICATION: check-mk-notify;notify-test;PING;CRITICAL;check-mk-notify;FAKE CRIT" ) l.check_logged( "] SERVICE NOTIFICATION: hh;notify-test;PING;CRITICAL;mail;FAKE CRIT" ) l.check_logged( "] SERVICE NOTIFICATION RESULT: hh;notify-test;PING;OK;mail;Spooled mail to local mail transmission agent;" )
def test_simple_rbn_host_notification(test_config, site, core, log): site.set_config("CORE", core, with_restart=True) with WatchLog(site, log, default_timeout=20) as l: site.send_host_check_result("notify-test", 1, "FAKE DOWN", expected_state=1) # NOTE: "] " is necessary to get the actual log line and not the external command execution l.check_logged( "] HOST NOTIFICATION: check-mk-notify;notify-test;DOWN;check-mk-notify;FAKE DOWN" ) l.check_logged( "] HOST NOTIFICATION: hh;notify-test;DOWN;mail;FAKE DOWN") l.check_logged( "] HOST NOTIFICATION RESULT: hh;notify-test;OK;mail;Spooled mail to local mail transmission agent;" )
def test_unreachable_child_down_before_parent_down(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set child down, expect DOWN notification _send_child_down(scenario, site, log) # - Set parent down, expect DOWN notification for parent and UNREACHABLE notification for child _send_parent_down(scenario, site, log) if scenario.core == "cmc": log.check_logged( "HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) # TODO: Can not check this at the moment #else: # log.check_not_logged("HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;") log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) elif scenario.core == "nagios": log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) # Difference beween nagios/cmc: when sending DOWN via PROCESS_HOST_CHECK_RESULT # the nagios core needs another child down check result to report it as unreachable. site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN", expected_state=STATE_UNREACHABLE) log.check_logged( "HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" )
def test_down_child_becomes_unreachable_then_up(scenario, site, initial_state): with WatchLog(site, scenario.log, default_timeout=10) as log: # - Set child down, expect DOWN notification site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN") log.check_logged("HOST ALERT: notify-test-child;DOWN;HARD;1;DOWN") if scenario.core == "cmc": # CMC: Send a new check result for the parent to make the CMC create the host notification # for the child site.send_host_check_result("notify-test-parent", STATE_UP, "UP") log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;DOWN;check-mk-notify;" ) # - Set parent down, expect DOWN notification for parent and UNREACHABLE notification for child site.send_host_check_result("notify-test-parent", STATE_DOWN, "DOWN") log.check_logged("HOST ALERT: notify-test-parent;DOWN;HARD;1;DOWN") # Difference beween nagios/cmc: when sending DOWN via PROCESS_HOST_CHECK_RESULT # the nagios core needs another child down check result to report it as unreachable. if scenario.core == "cmc": log.check_logged( "HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) # TODO: Can not test this because it drains too many entries from the log. WatchLog could deal # with this by readding the read lines after succeeded test or similar #else: # log.check_not_logged("HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;") log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) elif scenario.core == "nagios": log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-parent;DOWN;check-mk-notify;" ) site.send_host_check_result("notify-test-child", STATE_DOWN, "DOWN", expected_state=STATE_UNREACHABLE) log.check_logged( "HOST ALERT: notify-test-child;UNREACHABLE;HARD;1;") if scenario.unreachable_enabled: log.check_logged( "HOST NOTIFICATION: check-mk-notify;notify-test-child;UNREACHABLE;check-mk-notify;" ) # - Set child up, expect: # cmc: pending UP notification, and sent up notification after next parent check # nagios: UP notification _send_child_recovery(scenario, site, log) # - Set parent up, expect UP notification _send_parent_recovery(scenario, site, log)
def test_simple_rbn_notification(test_config, site, core): site.set_config("CORE", core, with_restart=True) # Open the log file and scan to end l = WatchLog(site, "var/log/notify.log") # Set object down to trigger a notification site.send_host_check_result("notify-test", 1, "FAKE DOWN", expected_state=1) # Now check for appearing log lines - one after the other l.check_logged("Got raw notification (notify-test)", timeout=20) l.check_logged("notifying hh via mail", timeout=20) l.check_logged("Creating spoolfile:", timeout=20) l.check_logged("(notify-test) for local delivery", timeout=20) l.check_logged("Output: Spooled mail to local mail transmission agent", timeout=20)