def wsgi(): LOG.info("Loading check_mk module...") watch = StopWatch() config.load_all_checks(check_api.get_check_api_context) config.load() count = len(config.check_info) LOG.info("%d checks loaded in %s." % (count, watch.elapsed())) app = flask.Flask(__name__) @app.route("/check/<hostname>") @input_output_fixup def check(hostname): return checking.do_check(hostname, None, None) @app.route("/detail/<hostname>") @input_output_fixup def detail(hostname): try: cmk.debug.enable() cmk.log.set_verbosity(verbosity=2) return checking.do_check(hostname, None, None) finally: cmk.log.set_verbosity(verbosity=0) cmk.debug.disable() @app.route("/inventory/<hostname>") @input_output_fixup def inventory(hostname): return discovery.check_discovery(hostname, None) return app
def reload_config(): # Needs to be done together, even when the checks are not directly needed import cmk_base.check_api as check_api config.load_all_checks(check_api.get_check_api_context) config.load() config_cache = config.get_config_cache() config_cache.initialize() return config_cache
def test_is_tcp_check(): config.load_all_checks(check_api.get_check_api_context) assert cmk_base.check_utils.is_tcp_check("xxx") == False assert cmk_base.check_utils.is_tcp_check("uptime") == True assert cmk_base.check_utils.is_tcp_check("uptime") == True assert cmk_base.check_utils.is_tcp_check("snmp_uptime") == False assert cmk_base.check_utils.is_tcp_check("mem") == True assert cmk_base.check_utils.is_tcp_check("mem.linux") == True assert cmk_base.check_utils.is_tcp_check("mem.ding") == True assert cmk_base.check_utils.is_tcp_check("apc_humidity") == False
def test_find_missing_manpages(): all_check_manuals = man_pages.all_man_pages() import cmk_base.check_api as check_api config.load_all_checks(check_api.get_check_api_context) checks_sorted = sorted([ (name, entry) for (name, entry) in config.check_info.items() if not _is_pure_section_declaration(entry) ] + \ [ ("check_" + name, entry) for (name, entry) in config.active_check_info.items() ]) assert len(checks_sorted) > 1000 for check_plugin_name, check in checks_sorted: assert check_plugin_name in all_check_manuals, "Manpage missing: %s" % check_plugin_name
def test_find_missing_manpages(): all_check_manuals = man_pages.all_man_pages() import cmk_base.check_api as check_api config.load_all_checks(check_api.get_check_api_context) checks_sorted = sorted([ (name, entry) for (name, entry) in config.check_info.items() if not _is_pure_section_declaration(entry) ] + \ [ ("check_" + name, entry) for (name, entry) in config.active_check_info.items() ]) assert len(checks_sorted) > 1000 for check_plugin_name, check in checks_sorted: if check_plugin_name in ["labels", "esx_systeminfo"]: continue # this check's discovery function can only create labels, never a service assert check_plugin_name in all_check_manuals, "Manpage missing: %s" % check_plugin_name
def test_is_snmp_check(): config.load_all_checks(check_api.get_check_api_context) assert cmk_base.check_utils.is_snmp_check("xxx") is False assert cmk_base.check_utils.is_snmp_check("uptime") is False assert cmk_base.check_utils.is_snmp_check("uptime") is False assert cmk_base.check_utils.is_snmp_check("snmp_uptime") is True assert cmk_base.check_utils.is_snmp_check("mem") is False assert cmk_base.check_utils.is_snmp_check("mem.linux") is False assert cmk_base.check_utils.is_snmp_check("mem.ding") is False assert cmk_base.check_utils.is_snmp_check("apc_humidity") is True assert cmk_base.check_utils.is_snmp_check("brocade.power") is True assert cmk_base.check_utils.is_snmp_check("brocade.fan") is True assert cmk_base.check_utils.is_snmp_check("brocade.xy") is True assert cmk_base.check_utils.is_snmp_check("brocade") is True
def load(self, file_names=None): """Load either all check plugins or the given file_names""" import cmk_base.config as config import cmk_base.check_api as check_api import cmk.utils.paths if file_names is None: config.load_all_checks( check_api.get_check_api_context) # loads all checks else: config._initialize_data_structures() config.load_checks(check_api.get_check_api_context, [ os.path.join(cmk.utils.paths.checks_dir, f) for f in file_names ]) return self
def execute(self, cmd, args): self._handle_generic_arguments(args) try: try: automation = self._automations[cmd] except KeyError: raise MKAutomationError( "Automation command '%s' is not implemented." % cmd) if automation.needs_checks: config.load_all_checks(check_api.get_check_api_context) if automation.needs_config: config.load(validate_hosts=False) result = automation.execute(args) except (MKAutomationError, MKTimeout) as e: console.error("%s\n" % cmk.utils.make_utf8("%s" % e)) if cmk.utils.debug.enabled(): raise return 1 except Exception as e: if cmk.utils.debug.enabled(): raise console.error("%s\n" % cmk.utils.make_utf8("%s" % e)) return 2 finally: profiling.output_profile() if cmk.utils.debug.enabled(): console.output(pprint.pformat(result) + "\n") else: console.output("%r\n" % (result, )) return 0
from pathlib2 import Path import six from omdlib.main import SiteContext, site_name import cmk_base.autochecks import cmk_base.cee.rrd import cmk_base.config as config import cmk_base.check_api as check_api import cmk.utils import cmk.utils.store as store import cmk.utils.debug cmk.utils.debug.enable() config.load_all_checks(check_api.get_check_api_context) config.load() logger = logging.getLogger("RRD INFO Metric Migration") logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) CHECKS_USING_DF_INCLUDE = [ "3par_capacity", "3par_cpgs", "3par_cpgs.usage", "3par_system", "3par_volumes", "ceph_df", "datapower_fs", "db2_logsizes", "dell_compellent_folder", "df", "df_netapp", "df_netapp32", "df_netscaler", "df_zos", "emc_datadomain_fs", "emc_isilon_ifs", "emc_isilon_quota", "emcvnx_raidgroups.capacity", "emcvnx_raidgroups.capacity_contiguous", "esx_vsphere_counters.ramdisk", "esx_vsphere_datastores", "fast_lta_silent_cubes.capacity", "fast_lta_volumes", "hitachi_hnas_span", "hitachi_hnas_volume", "hp_msa_volume.df", "hr_fs", "ibm_svc_mdiskgrp", "k8s_stats.fs", "libelle_business_shadow.archive_dir", "lvm_vgs", "mgmt_hr_fs", "netapp_api_aggr", "netapp_api_luns", "netapp_api_qtree_quota",
def test_cfg(web, site): print("Applying default config") web.add_host("ds-test-host1", attributes={ "ipaddress": "127.0.0.1", }) web.add_host("ds-test-host2", attributes={ "ipaddress": "127.0.0.1", }) web.add_host("ds-test-node1", attributes={ "ipaddress": "127.0.0.1", }) web.add_host("ds-test-node2", attributes={ "ipaddress": "127.0.0.1", }) web.add_host( "ds-test-cluster1", attributes={ "ipaddress": "127.0.0.1", }, cluster_nodes=[ "ds-test-node1", "ds-test-node2", ], ) site.write_file( "etc/check_mk/conf.d/ds-test-host.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ALL_HOSTS))\n" ) site.makedirs("var/check_mk/agent_output/") for h in [ "ds-test-host1", "ds-test-host2", "ds-test-node1", "ds-test-node2" ]: site.write_file( "var/check_mk/agent_output/%s" % h, file( "%s/tests/integration/cmk_base/test-files/linux-agent-output" % repo_path()).read()) web.activate_changes() import cmk.utils.debug cmk.utils.debug.enable() # Needs to be done together, even when the checks are not directly needed import cmk_base.check_api as check_api config.load_all_checks(check_api.get_check_api_context) config.load() yield None # # Cleanup code # print("Cleaning up test config") cmk.utils.debug.disable() site.delete_dir("var/check_mk/agent_output") site.delete_file("etc/check_mk/conf.d/ds-test-host.mk") web.delete_host("ds-test-host1") web.delete_host("ds-test-host2") web.delete_host("ds-test-node1") web.delete_host("ds-test-node2") web.delete_host("ds-test-cluster1") web.activate_changes()
def test_discoverable_tcp_checks(): config.load_all_checks(check_api.get_check_api_context) assert "uptime" in config.discoverable_tcp_checks() assert "snmp_uptime" not in config.discoverable_tcp_checks() assert "logwatch" in config.discoverable_tcp_checks()
def test_load_checks(): config._initialize_data_structures() assert config.check_info == {} config.load_all_checks(check_api.get_check_api_context) assert len(config.check_info) > 1000
def __init__(self): config.load_all_checks(check_api.get_check_api_context) self.info = copy.deepcopy(config.check_info) self.cache = {}