Esempio n. 1
0
def test__find_candidates():
    mhs = MultiHostSections()
    mhs._data = {
        # we just care about the keys here, content set to [] for simplicity
        # section names have been are chosen arbitrarily.
        # any HostSections type is fine.
        HostKey("test_node", "1.2.3.4", SourceType.HOST): AgentHostSections({
            SectionName("kernel"): [],  # host only
            SectionName("uptime"): [['123']],  # host & mgmt
        }),
        HostKey("test_node", "1.2.3.4", SourceType.MANAGEMENT): AgentHostSections({
            SectionName("uptime"): [['123']],  # host & mgmt
            SectionName("liebert_fans"): [[]],  # mgmt only
            SectionName("mgmt_snmp_info"): [[]],  # is already mgmt_ prefixed
        }),
    }

    preliminary_candidates = list(agent_based_register.iter_all_check_plugins())
    parsed_sections_of_interest = {
        parsed_section_name for plugin in preliminary_candidates
        for parsed_section_name in plugin.sections
    }

    assert discovery._find_host_candidates(
        mhs,
        preliminary_candidates,
        parsed_sections_of_interest,
    ) == {
        CheckPluginName('docker_container_status_uptime'),
        CheckPluginName("kernel"),
        CheckPluginName('kernel_performance'),
        CheckPluginName('kernel_util'),
        CheckPluginName("uptime"),
    }

    assert discovery._find_mgmt_candidates(
        mhs,
        preliminary_candidates,
        parsed_sections_of_interest,
    ) == {
        CheckPluginName('mgmt_docker_container_status_uptime'),
        CheckPluginName("mgmt_liebert_fans"),
        CheckPluginName("mgmt_uptime"),
        CheckPluginName("mgmt_snmp_info"),  # not mgmt_mgmt_...
    }

    assert discovery._find_candidates(
        mhs,
        selected_check_plugins=None,
    ) == {
        CheckPluginName('docker_container_status_uptime'),
        CheckPluginName("kernel"),
        CheckPluginName('kernel_performance'),
        CheckPluginName('kernel_util'),
        CheckPluginName('mgmt_docker_container_status_uptime'),
        CheckPluginName("mgmt_liebert_fans"),
        CheckPluginName("mgmt_uptime"),
        CheckPluginName("mgmt_snmp_info"),  # not mgmt_mgmt_...
        CheckPluginName("uptime"),
    }
Esempio n. 2
0
def test__find_candidates():
    mhs = MultiHostSections()
    mhs._data = {
        # we just care about the keys here, content set to [] for simplicity
        # section names have been are chosen arbitrarily.
        # any HostSections type is fine.
        HostKey("test_node", "1.2.3.4", SourceType.HOST):
        AgentHostSections({
            SectionName("kernel"): [],  # host only
            SectionName("uptime"): [],  # host & mgmt
        }),
        HostKey("test_node", "1.2.3.4", SourceType.MANAGEMENT):
        AgentHostSections({
            SectionName("uptime"): [],  # host & mgmt
            SectionName("liebert_fans"): [],  # mgmt only
            SectionName("mgmt_snmp_info"): [],  # is already mgmt_ prefixed
        }),
    }

    assert discovery._find_candidates_by_source_type(mhs, SourceType.HOST) == {
        CheckPluginName("kernel"),
        CheckPluginName('kernel_performance'),
        CheckPluginName('kernel_util'),
        CheckPluginName("uptime"),
    }

    assert discovery._find_candidates_by_source_type(
        mhs, SourceType.MANAGEMENT) == {
            CheckPluginName("liebert_fans"),
            CheckPluginName("uptime"),
            CheckPluginName("mgmt_snmp_info"),
        }

    assert discovery._find_candidates(mhs) == {
        CheckPluginName("kernel"),
        CheckPluginName('kernel_performance'),
        CheckPluginName('kernel_util'),
        CheckPluginName("uptime"),
        CheckPluginName("mgmt_liebert_fans"),
        CheckPluginName("mgmt_uptime"),
        CheckPluginName("mgmt_snmp_info"),  # not mgmt_mgmt_...
    }