Exemplo n.º 1
0
def test_oidspec():
    oid_base = OIDSpec(".1.2.3")
    oid_column = OIDBytes("4.5")

    assert str(oid_base) == ".1.2.3"
    assert str(oid_column) == "4.5"

    assert repr(oid_base) == "OIDSpec('.1.2.3')"
    assert repr(oid_column) == "OIDBytes('4.5')"

    oid_sum = oid_base + oid_column
    assert isinstance(oid_sum, OIDBytes)
    assert str(oid_sum) == ".1.2.3.4.5"
Exemplo n.º 2
0
    ['2.C0FEFE', 'C0FEFE'],
]


@pytest.mark.parametrize("column", snmp_table.SPECIAL_COLUMNS)
def test_value_encoding(column):
    assert snmp_table._value_encoding(column) == "string"


@pytest.mark.parametrize("snmp_info, expected_values", [
    (
        SNMPTree(
            base='.1.3.6.1.4.1.13595.2.2.3.1',
            oids=[
                OIDEnd(),
                OIDBytes("16"),
            ],
        ),
        DATA_2TUPLE,
    ),
    (TREE_2TUPLE, DATA_2TUPLE),
    (TREE_3TUPLE, DATA_3TUPLE),
    ([TREE_2TUPLE, TREE_3TUPLE], [DATA_2TUPLE, DATA_3TUPLE]),
])
def test_get_snmp_table(monkeypatch, snmp_info, expected_values):
    def get_all_snmp_tables(info):
        backend = SNMPTestBackend()
        if not isinstance(info, list):
            return snmp_table.get_snmp_table(SNMPConfig,
                                             "unit-test",
                                             info,
Exemplo n.º 3
0
    assert oide == OID_END


@pytest.mark.parametrize(
    "base, oids",
    [
        ('1.2', ['1', '2']),  # base no leading dot
        ('.1.2', '12'),  # oids not a list
        # TODO: this should fail once CompatibleOIDEnd is not needed anymore
        # ('.1.2', ['1', 2]),  # int in list
        ('.1.2', ['42.1', '42.2']),  # 42 should be in base
    ])
def test_snmptree_valid(base, oids):
    with pytest.raises((ValueError, TypeError)):
        SNMPTree(base=base, oids=oids)


@pytest.mark.parametrize("base, oids", [
    ('.1.2', ['1', '2']),
    ('.1.2', ['1', OIDCached('2')]),
    ('.1.2', ['1', OIDBytes('2')]),
    ('.1.2', ['1', OIDEnd()]),
])
def test_snmptree(base, oids):
    tree = SNMPTree(base=base, oids=oids)

    assert tree.base == OIDSpec(base)
    assert isinstance(tree.oids, list)
    for oid in tree.oids:
        assert isinstance(oid, (OIDSpec, OIDEnd))
Exemplo n.º 4
0
@pytest.mark.parametrize("value", ["", "foo", "1."])
def test_oidspec_invalid_value(value):
    with pytest.raises(ValueError):
        _ = OIDSpec(value)


@pytest.mark.parametrize("value", ["foo", 1])
def test_oidspec_invalid_adding_type(value):
    oid = OIDSpec(".1.2.3")
    with pytest.raises(TypeError):
        _ = oid + value


@pytest.mark.parametrize("left, right", [
    (OIDBytes("4.5"), OIDBytes("4.5")),
    (OIDSpec(".1.2.3"), OIDSpec(".1.2.3")),
])
def test_oidspec_invalid_adding_value(left, right):
    with pytest.raises(ValueError):
        _ = left + right


def test_oidspec():
    oid_base = OIDSpec(".1.2.3")
    oid_column = OIDBytes("4.5")

    assert str(oid_base) == ".1.2.3"
    assert str(oid_column) == "4.5"

    assert repr(oid_base) == "OIDSpec('.1.2.3')"
Exemplo n.º 5
0
#   .--Check API-----------------------------------------------------------.
#   |             ____ _               _         _    ____ ___             |
#   |            / ___| |__   ___  ___| | __    / \  |  _ \_ _|            |
#   |           | |   | '_ \ / _ \/ __| |/ /   / _ \ | |_) | |             |
#   |           | |___| | | |  __/ (__|   <   / ___ \|  __/| |             |
#   |            \____|_| |_|\___|\___|_|\_\ /_/   \_\_|  |___|            |
#   |                                                                      |
#   +----------------------------------------------------------------------+
#   |  Helper API for being used in checks                                 |
#   '----------------------------------------------------------------------'

# Names of texts usually output by checks
core_state_names = _defines.short_service_state_names()

# backwards compatibility: allow to pass integer.
BINARY = lambda x: OIDBytes(str(x))
CACHED_OID = lambda x: OIDCached(str(x))

from cmk.base.discovered_labels import (  # noqa: F401 # pylint: disable=unused-import
    DiscoveredServiceLabels as ServiceLabels, ServiceLabel,
    DiscoveredHostLabels as HostLabels, HostLabel,
)

network_interface_scan_registry = _snmp_utils.MutexScanRegistry()

# The class 'as_float' has been moved to the cmk.base.api domain.
# import it here under the old name
from cmk.base.api.agent_based.checking_types import MetricFloat as as_float


def saveint(i):