def test_oidspec(): oid_base = snmp_utils.OIDSpec(".1.2.3") oid_column = snmp_utils.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, snmp_utils.OIDBytes) assert str(oid_sum) == ".1.2.3.4.5"
def test_execute_with_canned_responses(monkeypatch): # Beginning of setup. tree = SNMPTree( base='.1.3.6.1.4.1.13595.2.2.3.1', oids=[ OIDEnd(), snmp_utils.OIDBytes("16"), ], ) name = "acme_agent_sessions" # Must be in config.registered_snmp_sections # Replace I/O with canned responses. monkeypatch.setattr(SNMPDataSource, "get_check_plugin_names", lambda *args, **kwargs: {name}) monkeypatch.setattr(snmp, "get_snmp_table_cached", lambda *args: tree) hostname = "testhost" ipaddress = "127.0.0.1" Scenario().add_host(hostname).apply(monkeypatch) source = SNMPDataSource(hostname, ipaddress) # End of setup. assert source._execute() == {name: [tree]}
# .--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: _snmp_utils.OIDBytes(str(x)) CACHED_OID = lambda x: _snmp_utils.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 # pylint: disable=unused-import def saveint(i):
['2.C0FEFE', 'C0FEFE'], ] @pytest.mark.parametrize("column", snmp.SPECIAL_COLUMNS) def test_value_encoding(column): assert snmp._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(), snmp_utils.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): monkeypatch.setattr(snmp, "SNMPBackendFactory", _SNMPTestFactory) monkeypatch.setattr(snmp_utils, "is_snmpv3_host", lambda _x: False) snmp_cfg = _SNMPTestConfig() def get_all_snmp_tables(info): if not isinstance(info, list):
@pytest.mark.parametrize("value", ["", "foo", "1."]) def test_oidspec_invalid_value(value): with pytest.raises(ValueError): _ = snmp_utils.OIDSpec(value) @pytest.mark.parametrize("value", ["foo", 1]) def test_oidspec_invalid_adding_type(value): oid = snmp_utils.OIDSpec(".1.2.3") with pytest.raises(TypeError): _ = oid + value @pytest.mark.parametrize("left, right", [ (snmp_utils.OIDBytes("4.5"), snmp_utils.OIDBytes("4.5")), (snmp_utils.OIDSpec(".1.2.3"), snmp_utils.OIDSpec(".1.2.3")), ]) def test_oidspec_invalid_adding_value(left, right): with pytest.raises(ValueError): _ = left + right def test_oidspec(): oid_base = snmp_utils.OIDSpec(".1.2.3") oid_column = snmp_utils.OIDBytes("4.5") assert str(oid_base) == ".1.2.3" assert str(oid_column) == "4.5"