Module: check_mk
Branch: master
Commit: f1ad452b0166e42d6db4d438fdaf011c2eb7dd3e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f1ad452b0166e4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 19 07:30:23 2019 +0200
Move SNMPHostConfig instanciation to HostConfig.snmp_config()
Change-Id: Ie4e05d08cd3e3993ca71bc54b50668616241acae
---
cmk_base/config.py | 16 ++++++++++++++++
cmk_base/data_sources/snmp.py | 36 ++++++++----------------------------
cmk_base/snmp.py | 14 +-------------
3 files changed, 25 insertions(+), 41 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 5e4d5b3..167f487 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -56,6 +56,7 @@ import cmk_base.utils
import cmk_base.check_api_utils as check_api_utils
import cmk_base.cleanup
import cmk_base.piggyback as piggyback
+import cmk_base.snmp_utils
from cmk_base.discovered_labels import DiscoveredHostLabelsStore
# TODO: Prefix helper functions with "_".
@@ -2688,6 +2689,21 @@ class HostConfig(object):
# type: () -> Dict
return DiscoveredHostLabelsStore(self.hostname).load()
+ def snmp_config(self, ipaddress):
+ # type: (str) -> cmk_base.snmp_utils.SNMPHostConfig
+ return cmk_base.snmp_utils.SNMPHostConfig(
+ is_ipv6_primary=self.is_ipv6_primary,
+ hostname=self.hostname,
+ ipaddress=ipaddress,
+ credentials=snmp_credentials_of(self.hostname),
+ port=snmp_port_of(self.hostname),
+ is_bulkwalk_host=is_bulkwalk_host(self.hostname),
+
is_snmpv2or3_without_bulkwalk_host=is_snmpv2or3_without_bulkwalk_host(self.hostname),
+ bulk_walk_size_of=bulk_walk_size_of(self.hostname),
+ timing=snmp_timing_of(self.hostname),
+ oid_range_limits=oid_range_limits_of(self.hostname),
+ )
+
#.
# .--Configuration Cache-------------------------------------------------.
diff --git a/cmk_base/data_sources/snmp.py b/cmk_base/data_sources/snmp.py
index 97c13b5..b360abc 100644
--- a/cmk_base/data_sources/snmp.py
+++ b/cmk_base/data_sources/snmp.py
@@ -61,11 +61,6 @@ class SNMPDataSource(DataSource):
self._use_snmpwalk_cache = True
self._ignore_check_interval = False
self._fetched_check_plugin_names = []
- 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_snmpv2or3_without_bulkwalk_host =
config.is_snmpv2or3_without_bulkwalk_host(
- self._hostname)
def id(self):
return "snmp"
@@ -76,23 +71,8 @@ class SNMPDataSource(DataSource):
def _cpu_tracking_id(self):
return "snmp"
- # TODO: Replace SNMPHostConfig with HostConfig
- def _get_host_config(self):
- # type: () -> snmp_utils.SNMPHostConfig
- return snmp_utils.SNMPHostConfig(
- is_ipv6_primary=self._host_config.is_ipv6_primary,
- hostname=self._hostname,
- ipaddress=self._ipaddress,
- credentials=self._credentials,
- port=self._port,
- is_bulkwalk_host=self._is_bulkwalk_host,
- is_snmpv2or3_without_bulkwalk_host=self._is_snmpv2or3_without_bulkwalk_host,
- bulk_walk_size_of=config.bulk_walk_size_of(self._hostname),
- timing=config.snmp_timing_of(self._hostname),
- oid_range_limits=config.oid_range_limits_of(self._hostname),
- )
-
def describe(self):
+ snmp_config = self._host_config.snmp_config(self._ipaddress)
if config.is_usewalk_host(self._hostname):
return "SNMP (use stored walk)"
@@ -101,18 +81,18 @@ class SNMPDataSource(DataSource):
else:
inline = "no"
- if snmp_utils.is_snmpv3_host(self._get_host_config()):
- credentials_text = "Credentials: '%s'" % ",
".join(self._credentials)
+ if snmp_utils.is_snmpv3_host(snmp_config):
+ credentials_text = "Credentials: '%s'" % ",
".join(snmp_config.credentials)
else:
- credentials_text = "Community: %r" % self._credentials
+ credentials_text = "Community: %r" % snmp_config.credentials
- if snmp_utils.is_snmpv3_host(self._get_host_config()) or self._is_bulkwalk_host:
+ if snmp_utils.is_snmpv3_host(snmp_config) or snmp_config.is_bulkwalk_host:
bulk = "yes"
else:
bulk = "no"
return "%s (%s, Bulk walk: %s, Port: %d, Inline: %s)" % \
- (self.title(), credentials_text, bulk, self._port, inline)
+ (self.title(), credentials_text, bulk, snmp_config.port, inline)
def _from_cache_file(self, raw_data):
return ast.literal_eval(raw_data)
@@ -164,7 +144,7 @@ class SNMPDataSource(DataSource):
return self._check_plugin_names[(self._hostname, self._ipaddress)]
except KeyError:
check_plugin_names = self._check_plugin_name_filter_func(
- self._get_host_config(),
+ self._host_config.snmp_config(self._ipaddress),
on_error=self._on_error,
do_snmp_scan=self._do_snmp_scan,
for_mgmt_board=self._for_mgmt_board)
@@ -178,7 +158,7 @@ class SNMPDataSource(DataSource):
check_plugin_names = self.get_check_plugin_names()
- host_config = self._get_host_config()
+ host_config = self._host_config.snmp_config(self._ipaddress)
info = {}
for check_plugin_name in self._sort_check_plugin_names(check_plugin_names):
# Is this an SNMP table check? Then snmp_info specifies the OID to fetch
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index e15644f..78158fc 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -142,7 +142,6 @@ def _clear_other_hosts_oid_cache(hostname):
# '----------------------------------------------------------------------'
-# TODO: Replace SNMPHostConfig with HostConfig
def create_snmp_host_config(hostname):
# type: (str) -> cmk_base.snmp_utils.SNMPHostConfig
host_config = config.get_config_cache().get_host_config(hostname)
@@ -153,18 +152,7 @@ def create_snmp_host_config(hostname):
if address is None:
raise MKGeneralException("Failed to gather IP address of %s" %
hostname)
- return cmk_base.snmp_utils.SNMPHostConfig( # type: ignore
- is_ipv6_primary=host_config.is_ipv6_primary,
- hostname=hostname,
- ipaddress=address,
- credentials=config.snmp_credentials_of(hostname),
- port=config.snmp_port_of(hostname),
- is_bulkwalk_host=config.is_bulkwalk_host(hostname),
-
is_snmpv2or3_without_bulkwalk_host=config.is_snmpv2or3_without_bulkwalk_host(hostname),
- bulk_walk_size_of=config.bulk_walk_size_of(hostname),
- timing=config.snmp_timing_of(hostname),
- oid_range_limits=config.oid_range_limits_of(hostname),
- )
+ return host_config.snmp_config(address)
# TODO: OID_END_OCTET_STRING is not used at all. Drop it.