def inventory_plugin( *, name: str, sections: Optional[List[str]] = None, inventory_function: InventoryFunction, inventory_default_parameters: Optional[Dict[str, Any]] = None, inventory_ruleset_name: Optional[str] = None, ) -> None: """Register an inventory plugin to checkmk. Args: name: The unique name of the check plugin. It must only contain the characters 'A-Z', 'a-z', '0-9' and the underscore. sections: An optional list of section names that this plugin subscribes to. They correspond to the 'parsed_section_name' specified in :meth:`agent_section` and :meth:`snmp_section`. The corresponding sections are passed to the discovery and check function. The functions arguments must be called 'section_<name1>, section_<name2>' ect. Defaults to a list containing as only element a name equal to the name of the inventory plugin. inventory_function: The inventory_function. Arguments must be 'params' (if inventory parameters are defined) and 'section' (if the plugin subscribes to a single section), or 'section_<name1>, section_<name2>' ect. corresponding to the `sections`. It is expected to be a generator of :class:`Attributes` or :class:`TableRow` instances. inventory_default_parameters: Default parameters for the inventory function. Must match the ValueSpec of the corresponding WATO ruleset, if it exists. inventory_ruleset_name: The name of the inventory ruleset. """ plugin = create_inventory_plugin( name=name, sections=sections, inventory_function=inventory_function, inventory_default_parameters=inventory_default_parameters, inventory_ruleset_name=inventory_ruleset_name, module=get_validated_plugin_module_name(), ) if is_registered_inventory_plugin(plugin.name): raise ValueError("duplicate inventory plugin definition: %s" % plugin.name) add_inventory_plugin(plugin)
def _extract_inventory_plugins(inf_info: Dict[InventoryPluginNameStr, InventoryInfo],) -> None: for plugin_name, plugin_info in sorted(inv_info.items()): try: agent_based_register.add_inventory_plugin( create_inventory_plugin_from_legacy( plugin_name, plugin_info, # count inherited extra sections from check plugin: len(config.check_info.get(plugin_name, {}).get("extra_sections", [])), )) except NotImplementedError: msg = config.AUTO_MIGRATION_ERR_MSG % ('inventory', plugin_name) if cmk.utils.debug.enabled(): raise MKGeneralException(msg) console.warning(msg)
def _extract_inventory_plugins(inf_info: Dict[InventoryPluginNameStr, InventoryInfo],) -> List[str]: errors = [] for plugin_name, plugin_info in sorted(inv_info.items()): try: agent_based_register.add_inventory_plugin( create_inventory_plugin_from_legacy( plugin_name, plugin_info, )) except NotImplementedError: msg = config.AUTO_MIGRATION_ERR_MSG % ('inventory', plugin_name) if cmk.utils.debug.enabled(): raise MKGeneralException(msg) errors.append(msg) return errors
def inventory_plugin( *, name: str, sections: Optional[List[str]] = None, inventory_function: InventoryFunction, inventory_default_parameters: Optional[Dict[str, Any]] = None, inventory_ruleset_name: Optional[str] = None, ) -> None: """Register a check plugin to checkmk. :param name: The name of the check plugin. It must be unique. And contain only the characters A-Z, a-z, 0-9 and the underscore. :param sections: An optional list of section names that this plugin subscribes to. The corresponding sections are passed to the inventory function. The functions arguments must be called 'section_<name1>, section_<name2>' ect. Default: [<name>] :param inventory_function: The check_function. Arguments must be 'params' (if inventory parameters are defined) and 'section_<name1>, section_<name2>' ect. corresponding to the `sections`. :param inventory_parameters: Default parameters for the inventory function. Must match the ValueSpec of the corresponding WATO ruleset. :param inventory_ruleset_name: The name of the inventory ruleset. """ plugin = create_inventory_plugin( name=name, sections=sections, inventory_function=inventory_function, inventory_default_parameters=inventory_default_parameters, inventory_ruleset_name=inventory_ruleset_name, module=get_validated_plugin_module_name(), ) if is_registered_inventory_plugin(plugin.name): raise ValueError("duplicate inventory plugin definition: %s" % plugin.name) add_inventory_plugin(plugin)