Module: check_mk
Branch: master
Commit: ec5e9e3cc40db893ffa5f37a16c21f959037381b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec5e9e3cc40db8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Feb 21 19:07:07 2019 +0100
Centralized some standard SNMPHostConfig() construction
Change-Id: I2be22309a606da95237d16b0d0c1495625363246
---
cmk_base/automations/check_mk.py | 6 +-----
cmk_base/snmp.py | 21 +++++++++++----------
2 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index 348ddd1..dd56735 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -1392,11 +1392,7 @@ class AutomationGetAgentOutput(Automation):
success = False
output += "[%s] %s\n" % (source.id(), source_output)
else:
- host_config = snmp_utils.SNMPHostConfig(
- hostname=hostname,
- ipaddress=ip_lookup.lookup_ipv4_address(hostname),
- credentials=config.snmp_credentials_of(hostname),
- )
+ host_config = snmp.create_snmp_host_config(hostname)
lines = []
for walk_oid in snmp.oids_to_walk():
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index e7128b6..f9decdd 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -141,6 +141,15 @@ def _clear_other_hosts_oid_cache(hostname):
# '----------------------------------------------------------------------'
+def create_snmp_host_config(hostname):
+ # type: (str) -> cmk_base.snmp_utils.SNMPHostConfig
+ return cmk_base.snmp_utils.SNMPHostConfig(
+ hostname=hostname,
+ ipaddress=ip_lookup.lookup_ipv4_address(hostname),
+ credentials=config.snmp_credentials_of(hostname),
+ )
+
+
# TODO: OID_END_OCTET_STRING is not used at all. Drop it.
def get_snmp_table(host_config, check_plugin_name, oid_info, use_snmpwalk_cache):
# oid_info is either ( oid, columns ) or
@@ -738,11 +747,7 @@ def do_snmpwalk(options, hostnames):
for hostname in hostnames:
#TODO: What about SNMP management boards?
- host_config = cmk_base.snmp_utils.SNMPHostConfig(
- hostname=hostname,
- ipaddress=ip_lookup.lookup_ipv4_address(hostname),
- credentials=config.snmp_credentials_of(hostname),
- )
+ host_config = create_snmp_host_config(hostname)
try:
_do_snmpwalk_on(host_config, options, cmk.utils.paths.snmpwalks_dir +
"/" + hostname)
@@ -810,11 +815,7 @@ def do_snmpget(*args):
for hostname in hostnames:
#TODO what about SNMP management boards?
- host_config = cmk_base.snmp_utils.SNMPHostConfig(
- hostname=hostname,
- ipaddress=ip_lookup.lookup_ipv4_address(hostname),
- credentials=config.snmp_credentials_of(hostname),
- )
+ host_config = create_snmp_host_config(hostname)
value = get_single_oid(host_config, oid)
console.output("%s (%s): %r\n" % (hostname, host_config.ipaddress,
value))