Beispiel #1
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: Classic)"
        )
Beispiel #2
0
    def test_one_snmp_source(self, hostname, ipaddress, config_cache, host_config):
        raw_data: SNMPRawData = {}
        host_sections = _collect_host_sections(
            fetched=[
                (
                    SNMPSource.snmp(
                        hostname,
                        ipaddress,
                        selected_sections=NO_SELECTION,
                        force_cache_refresh=False,
                        on_scan_error=OnError.RAISE,
                    ),
                    FetcherMessage.from_raw_data(
                        result.OK(raw_data),
                        Snapshot.null(),
                        FetcherType.SNMP,
                    ),
                )
            ],
            file_cache_max_age=file_cache.MaxAge.none(),
            selected_sections=NO_SELECTION,
        )[0]
        assert len(host_sections) == 1

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

        section = host_sections[key]

        assert len(section.sections) == 1
        assert section.sections[SectionName("section_name_%s" % hostname)] == [["section_content"]]
Beispiel #3
0
def source_fixture(scenario, hostname, ipaddress, mode):
    return SNMPSource.snmp(
        hostname,
        ipaddress,
        mode=mode,
        selected_sections=NO_SELECTION,
        on_scan_error="raise",
    )
Beispiel #4
0
def source_fixture(scenario, hostname, ipaddress):
    return SNMPSource.snmp(
        hostname,
        ipaddress,
        selected_sections=NO_SELECTION,
        on_scan_error=OnError.RAISE,
        force_cache_refresh=False,
    )
Beispiel #5
0
 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",
         on_scan_error="raise",
     )
Beispiel #6
0
 def source(self, hostname):
     return SNMPSource(
         hostname,
         "1.2.3.4",
         force_cache_refresh=False,
         selected_sections=NO_SELECTION,
         source_type=SourceType.HOST,
         id_="snmp_id",
         title="snmp title",
         on_scan_error=OnError.RAISE,
     )
Beispiel #7
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: Classic)"
        )
    def test_attribute_defaults(self, monkeypatch):
        hostname = "testhost"
        ipaddress = "1.2.3.4"

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

        source = SNMPSource.snmp(
            HostName(hostname),
            ipaddress,
            selected_sections=NO_SELECTION,
            on_scan_error=OnError.RAISE,
            force_cache_refresh=False,
        )
        assert source.description == (
            "SNMP (Community: 'public', Bulk walk: no, Port: 161, Backend: Classic)"
        )
    def test_one_snmp_source(self, hostname, ipaddress, mode, config_cache,
                             host_config):
        broker = ParsedSectionsBroker()
        update_host_sections(
            broker,
            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(broker) == 1

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

        section = broker[key]

        assert len(section.sections) == 1
        assert section.sections[SectionName("section_name_%s" %
                                            hostname)] == [["section_content"]]
Beispiel #10
0
    def test_one_snmp_source(self, hostname, ipaddress, mode, config_cache,
                             host_config):
        host_sections = _collect_host_sections(
            nodes=make_nodes(
                config_cache,
                host_config,
                ipaddress,
                mode=mode,
                sources=[
                    SNMPSource.snmp(
                        hostname,
                        ipaddress,
                        mode=mode,
                        selected_sections=NO_SELECTION,
                        force_cache_refresh=False,
                        on_scan_error="raise",
                    ),
                ],
            ),
            file_cache_max_age=0,
            fetcher_messages=[
                FetcherMessage.from_raw_data(
                    result.OK({}),
                    Snapshot.null(),
                    FetcherType.SNMP,
                ),
            ],
            selected_sections=NO_SELECTION,
        )[0]
        assert len(host_sections) == 1

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

        section = host_sections[key]

        assert len(section.sections) == 1
        assert section.sections[SectionName("section_name_%s" %
                                            hostname)] == [["section_content"]]