Пример #1
0
def test_create_snmp_section_plugin():

    trees: List[SNMPTree] = [
        SNMPTree(
            base=".1.2.3",
            oids=[OIDEnd(), "2.3"],
        ),
    ]

    detect = SNMPDetectSpecification([
        [(".1.2.3.4.5", "Foo.*", True)],
    ])

    plugin = section_plugins.create_snmp_section_plugin(
        name="norris",
        parsed_section_name="chuck",
        parse_function=_parse_dummy,
        fetch=trees,
        detect_spec=detect,
        supersedes=["foo", "bar"],
    )

    assert isinstance(plugin, SNMPSectionPlugin)
    assert len(plugin) == 11
    assert plugin.name == SectionName("norris")
    assert plugin.parsed_section_name == ParsedSectionName("chuck")
    assert plugin.parse_function is _parse_dummy
    assert plugin.host_label_function is section_plugins._noop_host_label_function
    assert plugin.host_label_default_parameters is None
    assert plugin.host_label_ruleset_name is None
    assert plugin.host_label_ruleset_type == "merged"
    assert plugin.detect_spec == detect
    assert plugin.trees == trees
    assert plugin.supersedes == {SectionName("bar"), SectionName("foo")}
Пример #2
0
def test_create_snmp_section_plugin():

    trees: List[SNMPTree] = [
        SNMPTree(
            base='.1.2.3',
            oids=[OIDEnd(), '2.3'],
        ),
    ]

    detect = SNMPDetectSpecification([
        [('.1.2.3.4.5', 'Foo.*', True)],
    ])

    plugin = section_plugins.create_snmp_section_plugin(
        name="norris",
        parsed_section_name="chuck",
        parse_function=_parse_dummy,
        fetch=trees,
        detect_spec=detect,
        supersedes=["foo", "bar"],
    )

    assert isinstance(plugin, SNMPSectionPlugin)
    assert len(plugin) == 8
    assert plugin.name == SectionName("norris")
    assert plugin.parsed_section_name == ParsedSectionName("chuck")
    assert plugin.parse_function is _parse_dummy
    assert plugin.host_label_function is section_plugins._noop_host_label_function
    assert plugin.detect_spec == detect
    assert plugin.trees == trees
    assert plugin.supersedes == {SectionName("bar"), SectionName("foo")}
Пример #3
0
def test_create_snmp_section_plugin_single_tree():

    single_tree = SNMPTree(base=".1.2.3", oids=[OIDEnd(), "2.3"])

    plugin = section_plugins.create_snmp_section_plugin(
        name="norris",
        parse_function=lambda string_table: string_table,
        # just one, no list:
        fetch=single_tree,
        detect_spec=SNMPDetectSpecification([[(".1.2.3.4.5", "Foo.*", True)]]),
    )

    assert plugin.trees == [single_tree]
    # the plugin only specified a single tree (not a list),
    # so a wrapper should unpack the argument:
    assert plugin.parse_function([[["A", "B"]]]) == [["A", "B"]]
     [SNMPTree(base=".1.2", oids=["3.4", "3"])],
     None,
 ),
 (
     (".1.2", ["3.4", "3.5"]),
     [SNMPTree(base=".1.2.3", oids=["4", "5"])],
     None,
 ),
 (
     (".1.2.3", list(range(4, 6))),
     [SNMPTree(base=".1.2.3", oids=["4", "5"])],
     None,
 ),
 (
     (".1.2.3", [OID_END]),
     [SNMPTree(base=".1.2.3", oids=[OIDEnd()])],
     None,
 ),
 (
     (".1.2.3", ["4", 5], ["1", "2", "3"]),
     [
         SNMPTree(base=".1.2.3.4", oids=["1", "2", "3"]),
         SNMPTree(base=".1.2.3.5", oids=["1", "2", "3"]),
     ],
     ["4", 5],
 ),
 # not used in mainline code, but test it anyway:
 (
     (".1.2.3", [OID_STRING]),
     # discouraged by typing, but will still work:
     [SNMPTree(base=".1.2.3", oids=[SpecialColumn.STRING])
Пример #5
0
def test_oid_end_compat_with_backend():
    assert OIDEnd().column == SpecialColumn.END
Пример #6
0
def test_oid_end_repr():
    assert repr(OIDEnd()) == "OIDEnd()"