예제 #1
0
    def __init__(self, fixed_register: FixRegister):
        import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
        import cmk.base.inventory_plugins as inventory_plugins
        assert isinstance(fixed_register, FixRegister)  # make sure plugins are loaded

        self._check_info = copy.deepcopy(config.check_info)
        self._snmp_info = copy.deepcopy(config.snmp_info)
        self._inv_info = copy.deepcopy(inventory_plugins.inv_info)
        self._active_check_info = copy.deepcopy(config.active_check_info)
        self._snmp_scan_functions = copy.deepcopy(config.snmp_scan_functions)
        self._check_variables = copy.deepcopy(config.get_check_variables())
예제 #2
0
def update_service_info(config_cache, hostnames):
    pnp_files_present = False
    check_variables = config.get_check_variables()
    cmc_capable = importlib.util.find_spec('cmk.base.cee')

    for hostname in hostnames:
        for service in cmk.base.autochecks.parse_autochecks_file(
                hostname,
                config.service_description,
                check_variables,
        ):
            if service.check_plugin_name in CHECKS_USING_DF_INCLUDE:
                if cmc_capable:
                    update_files(hostname, service.description, service.item, 'cmc')
                pnp_files_present |= update_files(hostname, service.description, service.item,
                                                  'pnp4nagios')
예제 #3
0
def update_service_info(config_cache, hostnames):
    check_variables = config.get_check_variables()
    cmc_capable = not cmk.utils.version.is_raw_edition()

    rename_journal = {}
    for hostname in hostnames:
        for service in cmk.base.autochecks.parse_autochecks_file(
                hostname,
                config.service_description,
                check_variables,
        ):
            if service.check_plugin_name in CHECKS_USING_DF_INCLUDE:
                if cmc_capable:
                    update_files(hostname, service.description, service.item,
                                 'cmc')
                rename_journal.update(
                    update_files(hostname, service.description, service.item,
                                 'pnp4nagios'))

    update_journal(rename_journal)
예제 #4
0
def config_check_variables(config_load_all_checks):
    import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
    return copy.deepcopy(config.get_check_variables())
예제 #5
0
    def _read_raw_autochecks_of(self, hostname):
        # type: (HostName) -> List[Service]
        """Read automatically discovered checks of one host"""
        basedir = cmk.utils.paths.autochecks_dir
        filepath = basedir + '/' + hostname + '.mk'

        result = []  # type: List[Service]
        if not os.path.exists(filepath):
            return result

        check_config = config.get_check_variables()
        try:
            cmk.base.console.vverbose("Loading autochecks from %s\n", filepath)
            autochecks_raw = eval(
                open(filepath).read().decode("utf-8"), check_config,
                check_config)  # type: List[Dict]
        except SyntaxError as e:
            cmk.base.console.verbose("Syntax error in file %s: %s\n",
                                     filepath,
                                     e,
                                     stream=sys.stderr)
            if cmk.utils.debug.enabled():
                raise
            return result
        except Exception as e:
            cmk.base.console.verbose("Error in file %s:\n%s\n", filepath, e, stream=sys.stderr)
            if cmk.utils.debug.enabled():
                raise
            return result

        for entry in autochecks_raw:
            if isinstance(entry, tuple):
                raise MKGeneralException(
                    "Invalid check entry '%r' of host '%s' (%s) found. This "
                    "entry is in pre Checkmk 1.6 format and needs to be converted. This is "
                    "normally done by \"cmk-update-config -v\" during \"omd update\". Please "
                    "execute \"cmk-update-config -v\" for convertig the old configuration." %
                    (entry, hostname, filepath))

            labels = DiscoveredServiceLabels()
            for label_id, label_value in entry["service_labels"].items():
                labels.add_label(ServiceLabel(label_id, label_value))

            # With Check_MK 1.2.7i3 items are now defined to be unicode strings. Convert
            # items from existing autocheck files for compatibility. TODO remove this one day
            item = entry["item"]
            if isinstance(item, str):
                item = convert_to_unicode(item)

            if not isinstance(entry["check_plugin_name"], six.string_types):
                raise MKGeneralException("Invalid entry '%r' in check table of host '%s': "
                                         "The check type must be a string." % (entry, hostname))

            check_plugin_name = str(entry["check_plugin_name"])

            try:
                description = config.service_description(hostname, check_plugin_name, item)
            except Exception:
                continue  # ignore

            result.append(
                Service(
                    check_plugin_name=check_plugin_name,
                    item=item,
                    description=description,
                    parameters=entry["parameters"],
                    service_labels=labels,
                ))

        return result
예제 #6
0
def config_check_variables(config_load_all_checks):
    # Local import to have faster pytest initialization
    import cmk.base.config as config  # pylint: disable=bad-option-value,import-outside-toplevel
    return copy.deepcopy(config.get_check_variables())