Module: check_mk
Branch: master
Commit: 3208c7d2c345b8ed5d649dd46575d0ac323bc367
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3208c7d2c345b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 21 20:53:37 2019 +0100
Moved bulk_walk_size_of attribute to SNMPHostConfig
Change-Id: Ife961919a65afd0b4cbd2846830ab7972d73235a
---
cmk_base/automations/check_mk.py | 1 +
cmk_base/classic_snmp.py | 2 +-
cmk_base/data_sources/snmp.py | 1 +
cmk_base/snmp.py | 1 +
cmk_base/snmp_utils.py | 1 +
tests/integration/cmk_base/snmp/test_snmp.py | 4 ++++
tests/unit/cmk_base/snmp/test_classic_snmp.py | 15 +++++++--------
7 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index cd8e300..564c63a 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -1237,6 +1237,7 @@ class AutomationDiagHost(Automation):
port=config.snmp_port_of(hostname),
is_bulkwalk_host=is_bulkwalk_host,
is_snmpv2c_host=is_snmpv2c_host,
+ bulk_walk_size_of=config.bulk_walk_size_of(hostname),
)
data = snmp.get_snmp_table(
host_config,
diff --git a/cmk_base/classic_snmp.py b/cmk_base/classic_snmp.py
index f165857..dfb4ef7 100644
--- a/cmk_base/classic_snmp.py
+++ b/cmk_base/classic_snmp.py
@@ -222,7 +222,7 @@ def _snmp_base_command(what, host_config, context_name):
elif host_config.is_bulkwalk_host:
command = ['snmpbulkwalk']
- options.append("-Cr%d" %
config.bulk_walk_size_of(host_config.hostname))
+ options.append("-Cr%d" % host_config.bulk_walk_size_of)
else:
command = ['snmpwalk']
diff --git a/cmk_base/data_sources/snmp.py b/cmk_base/data_sources/snmp.py
index 1b9d0cf..7e1837d 100644
--- a/cmk_base/data_sources/snmp.py
+++ b/cmk_base/data_sources/snmp.py
@@ -85,6 +85,7 @@ class SNMPDataSource(DataSource):
port=self._port,
is_bulkwalk_host=self._is_bulkwalk_host,
is_snmpv2c_host=self._is_snmpv2c_host,
+ bulk_walk_size_of=config.bulk_walk_size_of(self._hostname),
)
def describe(self):
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index 228baed..4b13995 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -150,6 +150,7 @@ def create_snmp_host_config(hostname):
port=config.snmp_port_of(hostname),
is_bulkwalk_host=config.is_bulkwalk_host(hostname),
is_snmpv2c_host=config.is_snmpv2c_host(hostname),
+ bulk_walk_size_of=config.bulk_walk_size_of(hostname),
)
diff --git a/cmk_base/snmp_utils.py b/cmk_base/snmp_utils.py
index 849e64f..884af9a 100644
--- a/cmk_base/snmp_utils.py
+++ b/cmk_base/snmp_utils.py
@@ -78,4 +78,5 @@ SNMPHostConfig = NamedTuple("SNMPHostConfig", [
("port", int),
("is_bulkwalk_host", bool),
("is_snmpv2c_host", bool),
+ ("bulk_walk_size_of", int),
])
diff --git a/tests/integration/cmk_base/snmp/test_snmp.py
b/tests/integration/cmk_base/snmp/test_snmp.py
index a9d000e..3408a0e 100644
--- a/tests/integration/cmk_base/snmp/test_snmp.py
+++ b/tests/integration/cmk_base/snmp/test_snmp.py
@@ -74,6 +74,7 @@ def snmpsim(site, request, tmp_path_factory):
# TODO: Use SNMPv2 over v1 for the moment
is_bulkwalk_host=False,
is_snmpv2c_host=True,
+ bulk_walk_size_of=10,
)
# Ensure that snmpsim is ready for clients before starting with the tests
@@ -143,6 +144,7 @@ def test_get_single_oid_ipv6(snmpsim, backend, monkeypatch):
port=1337,
is_bulkwalk_host=False,
is_snmpv2c_host=True,
+ bulk_walk_size_of=10,
)
monkeypatch.setattr(config, "is_ipv6_primary", lambda h: True)
result = snmp.get_single_oid(host_config, ".1.3.6.1.2.1.1.1.0")
@@ -160,6 +162,7 @@ def test_get_single_oid_snmpv3(snmpsim, backend, monkeypatch):
port=1337,
is_bulkwalk_host=False,
is_snmpv2c_host=True,
+ bulk_walk_size_of=10,
)
result = snmp.get_single_oid(host_config, ".1.3.6.1.2.1.1.1.0")
assert result == "Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016
i686"
@@ -261,6 +264,7 @@ def test_get_single_oid_not_resolvable(snmpsim, backend):
port=1337,
is_bulkwalk_host=True,
is_snmpv2c_host=True,
+ bulk_walk_size_of=10,
)
assert snmp.get_single_oid(host_config, ".1.3.6.1.2.1.1.7.0") is None
diff --git a/tests/unit/cmk_base/snmp/test_classic_snmp.py
b/tests/unit/cmk_base/snmp/test_classic_snmp.py
index 508a7c8..0ccdca9 100644
--- a/tests/unit/cmk_base/snmp/test_classic_snmp.py
+++ b/tests/unit/cmk_base/snmp/test_classic_snmp.py
@@ -14,6 +14,7 @@ def host_config():
port=161,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=10,
)
@@ -29,6 +30,7 @@ def test_snmp_port_spec(port, expected):
port=port,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=10,
)
assert classic_snmp._snmp_port_spec(host_config) == expected
@@ -44,7 +46,6 @@ def test_snmp_proto_spec(monkeypatch, is_ipv6, expected, host_config):
SNMPSettings = collections.namedtuple("SNMPSettings", [
"host_config",
- "bulk_walk_size_of",
"snmp_timing_of",
"context_name",
])
@@ -59,8 +60,8 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
port=161,
is_bulkwalk_host=True,
is_snmpv2c_host=True,
+ bulk_walk_size_of=10,
),
- bulk_walk_size_of=10,
snmp_timing_of={
"timeout": 2,
"retries": 3
@@ -78,8 +79,8 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
port=161,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=5,
),
- bulk_walk_size_of=5,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -97,8 +98,8 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
port=161,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=5,
),
- bulk_walk_size_of=5,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -116,8 +117,8 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
port=161,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=5,
),
- bulk_walk_size_of=5,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -135,8 +136,8 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
port=161,
is_bulkwalk_host=False,
is_snmpv2c_host=False,
+ bulk_walk_size_of=5,
),
- bulk_walk_size_of=5,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -148,7 +149,5 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
]),
])
def test_snmp_walk_command(monkeypatch, settings, expected):
- monkeypatch.setattr(config, "bulk_walk_size_of", lambda h:
settings.bulk_walk_size_of)
- monkeypatch.setattr(config, "snmp_timing_of", lambda h:
settings.snmp_timing_of)
monkeypatch.setattr(config, "snmp_timing_of", lambda h:
settings.snmp_timing_of)
assert classic_snmp._snmp_walk_command(settings.host_config, settings.context_name)
== expected