Exemple #1
0
    def _make_snmp_scan_sections(self) -> Iterable[SNMPScanSection]:
        """Create list of all SNMP scan specifications.

        Here, we evaluate the rule_dependent_detect_spec-attribute of SNMPSectionPlugin. This
        attribute is not an official part of the API. It allows for dynamically computing SNMP
        detection specifications based on user-defined discovery rulesets. This is needed by some
        check plugins, such as if and if64.

        In case this attribute is not set, we simply use SNMPSectionPlugin.detect_spec, which is
        the official way for specifying detection conditions.
        """
        snmp_scan_sections = []
        config_cache = config.get_config_cache()

        for snmp_section_plugin in agent_based_register.iter_all_snmp_sections(
        ):
            if snmp_section_plugin.rule_dependent_detect_spec is None:
                detect_spec = snmp_section_plugin.detect_spec
            else:
                # fetch user-defined discovery rules
                rules_for_host = [
                    config_cache.host_extra_conf(
                        self.hostname,
                        agent_based_register.get_discovery_ruleset(ruleset),
                    ) for ruleset in
                    snmp_section_plugin.rule_dependent_detect_spec.rulesets
                ]
                # call evaluator with these rules, returning an SNMPDetectSpec
                detect_spec = snmp_section_plugin.rule_dependent_detect_spec.evaluator(
                    *rules_for_host)

            snmp_scan_sections.append(
                SNMPScanSection(snmp_section_plugin.name, detect_spec))

        return snmp_scan_sections
Exemple #2
0
def _get_discovery_ruleset() -> Any:
    # NOTE: THIS AN API VIOLATION, DO NOT REPLICATE THIS
    # This is needed because inventory_ipmi_rules was once not a dict, which is not allowed by the
    # API for discovery rulesets
    # ==============================================================================================
    rules_all_hosts = get_discovery_ruleset(RuleSetName("inventory_ipmi_rules"))
    rules_this_host = get_config_cache().host_extra_conf(host_name(), rules_all_hosts)
    rules_this_host += [{"discovery_mode": ("summarize", {})}]  # default parameters
    return rules_this_host[0]