def test_attribute_defaults(self, mode, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

        ts = Scenario()
        ts.add_host(hostname)
        ts.set_option("management_protocol", {hostname: "snmp"})
        ts.set_option(
            "host_attributes",
            {
                hostname: {
                    "management_address": ipaddress
                },
            },
        )
        ts.apply(monkeypatch)

        source = SNMPSource.management_board(
            hostname,
            ipaddress,
            mode=mode,
        )
        assert source.description == (
            "Management board - SNMP "
            "(Community: 'public', Bulk walk: no, Port: 161, Backend: Classic)"
        )
Esempio n. 2
0
    def test_one_snmp_source(self, hostname, ipaddress, mode, config_cache, host_config):
        mhs = MultiHostSections()
        update_host_sections(
            mhs,
            make_nodes(
                config_cache,
                host_config,
                ipaddress,
                mode=mode,
                sources=[
                    SNMPSource.snmp(
                        hostname,
                        ipaddress,
                        mode=mode,
                    ),
                ],
            ),
            max_cachefile_age=0,
            selected_raw_sections=None,
            host_config=host_config,
        )
        assert len(mhs) == 1

        key = HostKey(hostname, ipaddress, SourceType.HOST)
        assert key in mhs

        section = mhs[key]
        assert isinstance(section, SNMPHostSections)

        assert len(section.sections) == 1
        assert section.sections[SectionName("section_name_%s" % hostname)] == [["section_content"]]
Esempio n. 3
0
    def test_attribute_defaults(self, mode, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

        ts = Scenario()
        ts.add_host(hostname)
        ts.set_option("management_protocol", {hostname: "snmp"})
        ts.set_option(
            "host_attributes",
            {
                hostname: {
                    "management_address": ipaddress
                },
            },
        )
        ts.apply(monkeypatch)

        source = SNMPSource.management_board(
            hostname,
            ipaddress,
            mode=mode,
            selected_sections=NO_SELECTION,
            on_scan_error="raise",
        )
        assert source.description == (
            "Management board - SNMP "
            "(Community: 'public', Bulk walk: no, Port: 161, Backend: %s)" %
            ("Classic" if cmk_version.is_raw_edition() else "Inline"))
Esempio n. 4
0
def source_fixture(scenario, hostname, ipaddress, mode):
    return SNMPSource.snmp(
        hostname,
        ipaddress,
        mode=mode,
        selected_sections=NO_SELECTION,
        on_scan_error="raise",
    )
Esempio n. 5
0
    def test_attribute_defaults(self, mode, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

        Scenario().add_host(hostname).apply(monkeypatch)

        source = SNMPSource.snmp(hostname, ipaddress, mode=mode)
        assert source.description == (
            "SNMP (Community: 'public', Bulk walk: no, Port: 161, Inline: no)")
Esempio n. 6
0
 def do_monkeypatch_and_make_source(monkeypatch, plugin, hostname,
                                    ipaddress):
     monkeypatch.setattr(
         register,
         'iter_all_snmp_sections',
         lambda: [plugin],
     )
     Scenario().add_host(hostname).apply(monkeypatch)
     return SNMPSource.snmp(hostname, ipaddress, mode=Mode.DISCOVERY)
Esempio n. 7
0
 def source(self, hostname, mode):
     return SNMPSource(
         hostname,
         "1.2.3.4",
         mode=mode,
         source_type=SourceType.HOST,
         id_="snmp_id",
         title="snmp title",
     )
 def source(self, hostname, mode):
     return SNMPSource(
         hostname,
         "1.2.3.4",
         mode=mode,
         selected_sections=NO_SELECTION,
         source_type=SourceType.HOST,
         id_="snmp_id",
         title="snmp title",
     )
Esempio n. 9
0
 def source(self, hostname, mode):
     return SNMPSource(
         hostname,
         "1.2.3.4",
         mode=mode,
         preselected_sections=AUTO_DETECT,
         source_type=SourceType.HOST,
         id_="snmp_id",
         title="snmp title",
     )
    def test_attribute_defaults(self, mode, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

        Scenario().add_host(hostname).apply(monkeypatch)

        source = SNMPSource.snmp(hostname,
                                 ipaddress,
                                 mode=mode,
                                 selected_sections=NO_SELECTION)
        assert source.description == (
            "SNMP (Community: 'public', Bulk walk: no, Port: 161, Backend: Classic)"
        )
Esempio n. 11
0
    def test_attribute_defaults(self, mode, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

        Scenario().add_host(hostname).apply(monkeypatch)

        source = SNMPSource.snmp(
            hostname,
            ipaddress,
            mode=mode,
            selected_sections=NO_SELECTION,
            on_scan_error="raise",
        )
        assert source.description == (
            "SNMP (Community: 'public', Bulk walk: no, Port: 161, Backend: %s)"
            % ("Classic" if cmk_version.is_raw_edition() else "Inline"))
Esempio n. 12
0
def test_make_snmp_section_detects_for_inventory(monkeypatch, hostname, ipaddress, check_plugin):
    plugin = section_plugins.create_snmp_section_plugin(
        name="norris",
        parse_function=lambda string_table: None,
        fetch=[
            SNMPTree(
                base='.1.2.3',
                oids=['2.3'],
            ),
        ],
        detect_spec=SNMPDetectSpec([[('.1.2.3.4.5', 'Foo.*', True)]]),
    )
    monkeypatch.setattr(_config, 'registered_snmp_sections', {plugin.name: plugin})
    monkeypatch.setattr(_config, 'registered_inventory_plugins', {check_plugin.name: check_plugin})

    Scenario().add_host(hostname).apply(monkeypatch)
    source = SNMPSource.snmp(hostname, ipaddress, mode=Mode.INVENTORY)
    assert source._make_snmp_section_detects() == {plugin.name: plugin.detect_spec}
Esempio n. 13
0
def test_make_snmp_section_detects(monkeypatch, hostname, ipaddress):
    plugin = section_plugins.create_snmp_section_plugin(
        name="norris",
        parse_function=lambda string_table: None,
        fetch=[
            SNMPTree(
                base='.1.2.3',
                oids=['2.3'],
            ),
        ],
        detect_spec=SNMPDetectSpec([[('.1.2.3.4.5', 'Foo.*', True)]]),
    )
    monkeypatch.setattr(
        register,
        'iter_all_snmp_sections',
        lambda: [plugin],
    )
    Scenario().add_host(hostname).apply(monkeypatch)
    source = SNMPSource.snmp(hostname, ipaddress, mode=Mode.DISCOVERY)
    assert source._make_snmp_section_detects() == {plugin.name: plugin.detect_spec}
Esempio n. 14
0
    def test_one_snmp_source(self, hostname, ipaddress, mode, config_cache,
                             host_config):
        mhs = MultiHostSections()
        update_host_sections(
            mhs,
            make_nodes(
                config_cache,
                host_config,
                ipaddress,
                mode=mode,
                sources=[
                    SNMPSource.snmp(
                        hostname,
                        ipaddress,
                        mode=mode,
                        selected_sections=NO_SELECTION,
                        on_scan_error="raise",
                    ),
                ],
            ),
            max_cachefile_age=0,
            host_config=host_config,
            fetcher_messages=[
                FetcherMessage.from_raw_data(
                    result.OK({}),
                    Snapshot.null(),
                    FetcherType.SNMP,
                ),
            ],
            selected_sections=NO_SELECTION,
        )
        assert len(mhs) == 1

        key = HostKey(hostname, ipaddress, SourceType.HOST)
        assert key in mhs

        section = mhs[key]

        assert len(section.sections) == 1
        assert section.sections[SectionName("section_name_%s" %
                                            hostname)] == [["section_content"]]
Esempio n. 15
0
def source_fixture(scenario, hostname, ipaddress, mode):
    return SNMPSource.snmp(hostname, ipaddress, mode=mode)
Esempio n. 16
0
def source_fixture(scenario, hostname, ipaddress, mode):
    return SNMPSource.snmp(hostname,
                           ipaddress,
                           mode=mode,
                           preselected_sections=AUTO_DETECT)