Module: check_mk
Branch: master
Commit: e9f48ff981651646be844c4bb036f49932f81d04
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e9f48ff9816516…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 21 20:07:23 2019 +0100
Moved SNMP is_snmpv2c_host attribute to SNMPHostConfig
Change-Id: I883a3051ceb855b1a2fd896a7bf0b156b2c0acb3
---
cmk_base/automations/check_mk.py | 6 ++++--
cmk_base/classic_snmp.py | 2 +-
cmk_base/data_sources/snmp.py | 2 ++
cmk_base/snmp.py | 1 +
cmk_base/snmp_utils.py | 1 +
tests/integration/cmk_base/snmp/test_snmp.py | 12 +++++++-----
tests/unit/cmk_base/snmp/test_classic_snmp.py | 14 +++++++-------
7 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index 02ebed6..cd8e300 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -1218,12 +1218,13 @@ class AutomationDiagHost(Automation):
# SNMP versions
if test in ['snmpv2', 'snmpv3']:
is_bulkwalk_host = True
+ is_snmpv2c_host = False
elif test == 'snmpv2_nobulk':
is_bulkwalk_host = False
- config.snmpv2c_hosts = [hostname]
+ is_snmpv2c_host = True
elif test == 'snmpv1':
is_bulkwalk_host = False
- config.snmpv2c_hosts = []
+ is_snmpv2c_host = False
else:
return 1, "SNMP command not implemented"
@@ -1235,6 +1236,7 @@ class AutomationDiagHost(Automation):
credentials=config.snmp_credentials_of(hostname),
port=config.snmp_port_of(hostname),
is_bulkwalk_host=is_bulkwalk_host,
+ is_snmpv2c_host=is_snmpv2c_host,
)
data = snmp.get_snmp_table(
host_config,
diff --git a/cmk_base/classic_snmp.py b/cmk_base/classic_snmp.py
index c885d3e..f165857 100644
--- a/cmk_base/classic_snmp.py
+++ b/cmk_base/classic_snmp.py
@@ -233,7 +233,7 @@ def _snmp_base_command(what, host_config, context_name):
else:
if what == 'walk':
command = ['snmpwalk']
- if config.is_snmpv2c_host(host_config.hostname):
+ if host_config.is_snmpv2c_host:
options.append('-v2c')
else:
options.append('-v1')
diff --git a/cmk_base/data_sources/snmp.py b/cmk_base/data_sources/snmp.py
index b2447c0..1b9d0cf 100644
--- a/cmk_base/data_sources/snmp.py
+++ b/cmk_base/data_sources/snmp.py
@@ -66,6 +66,7 @@ class SNMPDataSource(DataSource):
self._credentials = config.snmp_credentials_of(self._hostname)
self._port = config.snmp_port_of(self._hostname)
self._is_bulkwalk_host = config.is_bulkwalk_host(self._hostname)
+ self._is_snmpv2c_host = config.is_snmpv2c_host(self._hostname)
def id(self):
return "snmp"
@@ -83,6 +84,7 @@ class SNMPDataSource(DataSource):
credentials=self._credentials,
port=self._port,
is_bulkwalk_host=self._is_bulkwalk_host,
+ is_snmpv2c_host=self._is_snmpv2c_host,
)
def describe(self):
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index 83df9e8..228baed 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -149,6 +149,7 @@ def create_snmp_host_config(hostname):
credentials=config.snmp_credentials_of(hostname),
port=config.snmp_port_of(hostname),
is_bulkwalk_host=config.is_bulkwalk_host(hostname),
+ is_snmpv2c_host=config.is_snmpv2c_host(hostname),
)
diff --git a/cmk_base/snmp_utils.py b/cmk_base/snmp_utils.py
index 572e66c..849e64f 100644
--- a/cmk_base/snmp_utils.py
+++ b/cmk_base/snmp_utils.py
@@ -77,4 +77,5 @@ SNMPHostConfig = NamedTuple("SNMPHostConfig", [
("credentials", SNMPCredentials),
("port", int),
("is_bulkwalk_host", bool),
+ ("is_snmpv2c_host", bool),
])
diff --git a/tests/integration/cmk_base/snmp/test_snmp.py
b/tests/integration/cmk_base/snmp/test_snmp.py
index 5c24932..a9d000e 100644
--- a/tests/integration/cmk_base/snmp/test_snmp.py
+++ b/tests/integration/cmk_base/snmp/test_snmp.py
@@ -35,7 +35,7 @@ def monkeymodule(request):
@pytest.fixture(scope="module")
-def snmpsim(site, request, tmp_path_factory, monkeymodule):
+def snmpsim(site, request, tmp_path_factory):
tmp_path = tmp_path_factory.getbasetemp()
cmd = "%s/.venv/bin/snmpsimd.py" % cmk_path()
@@ -44,9 +44,6 @@ def snmpsim(site, request, tmp_path_factory, monkeymodule):
log.set_verbosity(2)
debug.enable()
- # TODO: Use SNMPv2 over v1 for the moment
- monkeymodule.setattr(config, "is_snmpv2c_host", lambda h: True)
-
p = subprocess.Popen(
[
cmd,
@@ -74,7 +71,9 @@ def snmpsim(site, request, tmp_path_factory, monkeymodule):
hostname="localhost",
credentials="public",
port=1337,
+ # TODO: Use SNMPv2 over v1 for the moment
is_bulkwalk_host=False,
+ is_snmpv2c_host=True,
)
# Ensure that snmpsim is ready for clients before starting with the tests
@@ -143,6 +142,7 @@ def test_get_single_oid_ipv6(snmpsim, backend, monkeypatch):
credentials="public",
port=1337,
is_bulkwalk_host=False,
+ is_snmpv2c_host=True,
)
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")
@@ -159,6 +159,7 @@ def test_get_single_oid_snmpv3(snmpsim, backend, monkeypatch):
credentials=('authNoPriv', 'md5', 'authOnlyUser',
'authOnlyUser'),
port=1337,
is_bulkwalk_host=False,
+ is_snmpv2c_host=True,
)
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"
@@ -258,7 +259,8 @@ def test_get_single_oid_not_resolvable(snmpsim, backend):
hostname="localhost",
credentials="public",
port=1337,
- is_bulkwalk_host=False,
+ is_bulkwalk_host=True,
+ is_snmpv2c_host=True,
)
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 0aa95c2..508a7c8 100644
--- a/tests/unit/cmk_base/snmp/test_classic_snmp.py
+++ b/tests/unit/cmk_base/snmp/test_classic_snmp.py
@@ -13,6 +13,7 @@ def host_config():
credentials="public",
port=161,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
)
@@ -27,6 +28,7 @@ def test_snmp_port_spec(port, expected):
credentials="public",
port=port,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
)
assert classic_snmp._snmp_port_spec(host_config) == expected
@@ -43,7 +45,6 @@ def test_snmp_proto_spec(monkeypatch, is_ipv6, expected, host_config):
SNMPSettings = collections.namedtuple("SNMPSettings", [
"host_config",
"bulk_walk_size_of",
- "is_snmpv2c_host",
"snmp_timing_of",
"context_name",
])
@@ -57,9 +58,9 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
credentials="public",
port=161,
is_bulkwalk_host=True,
+ is_snmpv2c_host=True,
),
bulk_walk_size_of=10,
- is_snmpv2c_host=True,
snmp_timing_of={
"timeout": 2,
"retries": 3
@@ -76,9 +77,9 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
credentials="public",
port=161,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
),
bulk_walk_size_of=5,
- is_snmpv2c_host=False,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -95,9 +96,9 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
credentials=("authNoPriv", "abc", "md5",
"abc"),
port=161,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
),
bulk_walk_size_of=5,
- is_snmpv2c_host=False,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -114,9 +115,9 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
credentials=('noAuthNoPriv', 'secname'),
port=161,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
),
bulk_walk_size_of=5,
- is_snmpv2c_host=False,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -133,9 +134,9 @@ SNMPSettings = collections.namedtuple("SNMPSettings", [
credentials=('authPriv', 'md5', 'secname',
'auhtpassword', 'DES', 'privacybla'),
port=161,
is_bulkwalk_host=False,
+ is_snmpv2c_host=False,
),
bulk_walk_size_of=5,
- is_snmpv2c_host=False,
snmp_timing_of={
"timeout": 5,
"retries": 1
@@ -148,7 +149,6 @@ 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, "is_snmpv2c_host", lambda h:
settings.is_snmpv2c_host)
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