Module: check_mk
Branch: master
Commit: c5f8831e3598178e37e0590f1e603e205ca01e95
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c5f8831e359817…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Feb 27 21:09:53 2019 +0100
Move SNMPBackend instantiation to factory
CMK-1736
Change-Id: I3f4f493528200cb9883e9519a1ac0d211feb448c
---
cmk_base/snmp.py | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/cmk_base/snmp.py b/cmk_base/snmp.py
index 33b7ddb..61ba291 100644
--- a/cmk_base/snmp.py
+++ b/cmk_base/snmp.py
@@ -290,15 +290,9 @@ def get_single_oid(host_config, oid, check_plugin_name=None,
do_snmp_scan=True):
console.vverbose(" Getting OID %s: " % oid)
for context_name in snmp_contexts:
try:
- if _enforce_stored_walks or config.is_usewalk_host(host_config.hostname):
- value = StoredWalkSNMPBackend().get(host_config, oid, context_name)
-
- elif config.is_inline_snmp_host(host_config.hostname):
- value = inline_snmp.InlineSNMPBackend().get(
- host_config, oid, context_name=context_name)
- else:
- value = classic_snmp.ClassicSNMPBackend().get(
- host_config, oid, context_name=context_name)
+ snmp_backend = SNMPBackendFactory().factory(
+ host_config, enforce_stored_walks=_enforce_stored_walks)
+ value = snmp_backend.get(host_config, oid, context_name)
if value is not None:
break # Use first received answer in case of multiple contextes
@@ -316,6 +310,18 @@ def get_single_oid(host_config, oid, check_plugin_name=None,
do_snmp_scan=True):
return value
+class SNMPBackendFactory(object):
+ @staticmethod
+ def factory(host_config, enforce_stored_walks):
+ if enforce_stored_walks or config.is_usewalk_host(host_config.hostname):
+ return StoredWalkSNMPBackend()
+
+ if config.is_inline_snmp_host(host_config.hostname):
+ return inline_snmp.InlineSNMPBackend()
+
+ return classic_snmp.ClassicSNMPBackend()
+
+
class StoredWalkSNMPBackend(cmk_base.snmp_utils.ABCSNMPBackend):
def get(self, host_config, oid, context_name=None):
walk = _get_stored_snmpwalk(host_config.hostname, oid)