Exemple #1
0
def snmp_config_fixture(request, snmpsim, monkeypatch):
    backend_name = request.param

    if backend_name == "stored_snmp":
        source_data_dir = Path(
            request.fspath.dirname) / "snmp_data" / "cmk-walk"
        monkeypatch.setattr(cmk.utils.paths, "snmpwalks_dir",
                            str(source_data_dir))

    return SNMPHostConfig(
        is_ipv6_primary=False,
        ipaddress="127.0.0.1",
        hostname="localhost",
        credentials="public",
        port=1337,
        # TODO: Use SNMPv2 over v1 for the moment
        is_bulkwalk_host=False,
        is_snmpv2or3_without_bulkwalk_host=True,
        bulk_walk_size_of=10,
        timing={},
        oid_range_limits=[],
        snmpv3_contexts=[],
        character_encoding=None,
        is_usewalk_host=backend_name == "stored_snmp",
        is_inline_snmp_host=backend_name == "inline_snmp",
        record_stats=False,
    )
Exemple #2
0
def test_snmp_proto_spec(monkeypatch, is_ipv6, expected):
    snmp_config = SNMPHostConfig(
        is_ipv6_primary=is_ipv6,
        hostname="localhost",
        ipaddress="127.0.0.1",
        credentials="public",
        port=161,
        is_bulkwalk_host=False,
        is_snmpv2or3_without_bulkwalk_host=False,
        bulk_walk_size_of=10,
        timing={},
        oid_range_limits=[],
        snmpv3_contexts=[],
        character_encoding=None,
        is_usewalk_host=False,
        is_inline_snmp_host=False,
    )
    assert ClassicSNMPBackend()._snmp_proto_spec(snmp_config) == expected
from cmk.utils.type_defs import ABCSNMPBackend, OID_END, OIDBytes, OIDEnd, SNMPHostConfig

import cmk.base.config as config
from cmk.base.api.agent_based.register.section_plugins_legacy import _create_snmp_trees
from cmk.base.api.agent_based.section_types import SNMPTree
from cmk.base.check_api import BINARY

SNMPConfig = SNMPHostConfig(
    is_ipv6_primary=False,
    hostname="testhost",
    ipaddress="1.2.3.4",
    credentials="",
    port=42,
    is_bulkwalk_host=False,
    is_snmpv2or3_without_bulkwalk_host=False,
    bulk_walk_size_of=0,
    timing={},
    oid_range_limits=[],
    snmpv3_contexts=[],
    character_encoding="ascii",
    is_usewalk_host=False,
    is_inline_snmp_host=False,
    record_stats=False,
)


class SNMPTestBackend(ABCSNMPBackend):
    def get(self, snmp_config, oid, context_name=None):
        pass

    def walk(self,
    "context_name",
])


@pytest.mark.parametrize("settings,expected", [
    (SNMPSettings(
        snmp_config=SNMPHostConfig(
            is_ipv6_primary=False,
            hostname="localhost",
            ipaddress="127.0.0.1",
            credentials="public",
            port=161,
            is_bulkwalk_host=True,
            is_snmpv2or3_without_bulkwalk_host=True,
            bulk_walk_size_of=10,
            timing={
                "timeout": 2,
                "retries": 3
            },
            oid_range_limits=[],
            snmpv3_contexts=[],
            character_encoding=None,
            is_usewalk_host=False,
            is_inline_snmp_host=False,
            record_stats=False,
        ),
        context_name=None,
    ), [
        'snmpbulkwalk', '-Cr10', '-v2c', '-c', 'public', '-m', '', '-M', '',
        '-t', '2.00', '-r', '3', '-Cc'
    ]),
    (SNMPSettings(