def test_get_ruleset(web): response = web.get_ruleset("extra_host_conf:notification_options") assert response == { 'ruleset': { '': [{ 'value': 'd,r,f,s', 'condition': {} }] }, 'configuration_hash': 'b76f205bbe674300f677a282d9ccd71f', } # TODO: Move testing of initial wato rules to unit tests response = web.get_ruleset("inventory_df_rules") assert response == { 'ruleset': { '': [{ 'condition': { 'host_labels': { u'cmk/check_mk_server': u'yes', }, }, 'value': { 'ignore_fs_types': ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'], 'never_ignore_mountpoints': [u'~.*/omd/sites/[^/]+/tmp$'] } }] }, 'configuration_hash': '0ef816195d483f9ed828a4dc84bdf706', }
def test_get_ruleset(web): # noqa: F811 # pylint: disable=redefined-outer-name response = web.get_ruleset("extra_host_conf:notification_options") assert response == { 'ruleset': { '': [{ 'id': '814bf932-6341-4f96-983d-283525b5416d', 'value': 'd,r,f,s', 'condition': {} }] }, 'configuration_hash': 'a8ee55e0ced14609df741e5a82462e3a', } # TODO: Move testing of initial wato rules to unit tests response = web.get_ruleset("inventory_df_rules") assert response == { 'ruleset': { '': [{ 'id': 'b0ee8a51-703c-47e4-aec4-76430281604d', 'condition': { 'host_labels': { u'cmk/check_mk_server': u'yes', }, }, 'value': { 'ignore_fs_types': ['tmpfs', 'nfs', 'smbfs', 'cifs', 'iso9660'], 'never_ignore_mountpoints': [u'~.*/omd/sites/[^/]+/tmp$'] } }] }, 'configuration_hash': '68e05dd8ab82cea5bebc9c6184c0ee08', }
def test_get_ruleset(web): response = web.get_ruleset("extra_host_conf:notification_options") assert response == { 'ruleset': { '': [{ 'value': 'd,r,f,s', 'condition': {} }] }, 'configuration_hash': 'b76f205bbe674300f677a282d9ccd71f', }
def test_set_ruleset(web): # noqa: F811 # pylint: disable=redefined-outer-name orig_ruleset = web.get_ruleset("bulkwalk_hosts") assert orig_ruleset == { 'ruleset': { '': [{ 'id': 'b92a5406-1d57-4f1d-953d-225b111239e5', 'value': True, 'condition': { 'host_tags': { 'snmp': 'snmp', 'snmp_ds': { '$ne': 'snmp-v1' } } }, 'options': { 'description': u'Hosts with the tag "snmp-v1" must not use bulkwalk' } }] }, 'configuration_hash': '9abf6316805b3daf10ac7745864f13f8', } # Now modify something ruleset = copy.deepcopy(orig_ruleset) ruleset["ruleset"][""][0]["value"] = False response = web.set_ruleset("bulkwalk_hosts", ruleset) assert response is None try: changed = web.get_ruleset("bulkwalk_hosts") assert changed["ruleset"][""][0]["value"] is False finally: # revert it back del orig_ruleset["configuration_hash"] response = web.set_ruleset("bulkwalk_hosts", orig_ruleset) assert response is None
def test_set_ruleset(web): orig_ruleset = web.get_ruleset("bulkwalk_hosts") assert orig_ruleset == { 'ruleset': { '': [{ 'value': True, 'condition': { 'host_tags': { 'snmp': 'snmp', 'snmp_ds': { '$ne': 'snmp-v1' } } }, 'options': { 'description': u'Hosts with the tag "snmp-v1" must not use bulkwalk' } }] }, 'configuration_hash': '0cca93426feb558f7c9f09631340c63c', } # Now modify something ruleset = copy.deepcopy(orig_ruleset) ruleset["ruleset"][""][0]["value"] = False response = web.set_ruleset("bulkwalk_hosts", ruleset) assert response is None try: changed = web.get_ruleset("bulkwalk_hosts") assert changed["ruleset"][""][0]["value"] is False finally: # revert it back del orig_ruleset["configuration_hash"] response = web.set_ruleset("bulkwalk_hosts", orig_ruleset) assert response is None
def scenario_fixture(request, web, site): # noqa: F811 # pylint: disable=redefined-outer-name core = request.param.core unreachable_enabled = request.param.unreachable_enabled site.set_core(core) try: print("Applying test config") web.add_host("notify-test-parent", attributes={ "ipaddress": "127.0.0.1", }) web.add_host("notify-test-child", attributes={ "ipaddress": "127.0.0.1", "parents": ["notify-test-parent"], }) if unreachable_enabled: notification_options = 'd,u,r,f,s' else: notification_options = 'd,r,f,s' rule_result = web.get_ruleset("extra_host_conf:notification_options") rule_result["ruleset"] = { "": [{ 'condition': {}, 'options': {}, 'value': notification_options }] } web.set_ruleset("extra_host_conf:notification_options", rule_result) web.activate_changes() site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-parent" % time.time()) site.live.command("[%d] DISABLE_SVC_CHECK;notify-test-parent;PING" % time.time()) site.live.command( "[%d] DISABLE_SVC_CHECK;notify-test-parent;Check_MK Discovery" % time.time()) site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-child" % time.time()) site.live.command("[%d] DISABLE_SVC_CHECK;notify-test-child;PING" % time.time()) site.live.command( "[%d] DISABLE_SVC_CHECK;notify-test-child;Check_MK Discovery" % time.time()) site.live.command("[%d] DISABLE_FLAP_DETECTION" % time.time()) yield request.param finally: # # Cleanup code # print("Cleaning up default config") site.live.command("[%d] ENABLE_FLAP_DETECTION" % time.time()) site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-child" % time.time()) site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-parent" % time.time()) web.delete_host("notify-test-child") web.delete_host("notify-test-parent") web.activate_changes()
def scenario(request, web, site): core = request.param.core unreachable_enabled = request.param.unreachable_enabled site.set_core(core) try: print("Applying test config") web.add_host("notify-test-parent", attributes={ "ipaddress": "127.0.0.1", }) web.add_host("notify-test-child", attributes={ "ipaddress": "127.0.0.1", "parents": ["notify-test-parent"], }) if unreachable_enabled: notification_options = 'd,u,r,f,s' else: notification_options = 'd,r,f,s' rule_result = web.get_ruleset("extra_host_conf:notification_options") rule_result["ruleset"] = { "": [{ 'condition': {}, 'options': {}, 'value': notification_options }] } web.set_ruleset("extra_host_conf:notification_options", rule_result) # Make nagios check more often for incoming commands and add more # details to the log site.write_file( "etc/nagios/nagios.d/zzz_test_unreachable_notifications.cfg", "log_passive_checks=1\n" "command_check_interval=1s\n") web.activate_changes() site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-parent" % time.time()) site.live.command("[%d] DISABLE_HOST_CHECK;notify-test-child" % time.time()) site.live.command("[%d] DISABLE_FLAP_DETECTION" % time.time()) yield request.param finally: # # Cleanup code # print("Cleaning up default config") site.live.command("[%d] ENABLE_FLAP_DETECTION" % time.time()) site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-child" % time.time()) site.live.command("[%d] ENABLE_HOST_CHECK;notify-test-parent" % time.time()) site.delete_file( "etc/nagios/nagios.d/zzz_test_unreachable_notifications.cfg") web.delete_host("notify-test-child") web.delete_host("notify-test-parent") web.activate_changes()