Module: check_mk
Branch: master
Commit: 93f333f961fdcd60e297e8b6b0643192702d45e8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=93f333f961fdcd…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Mar 7 15:17:36 2019 +0100
if.include: refactor: make scan functions private
Change-Id: I60763ecc4cccb08134cb03989b693d7162506108
---
checks/adva_fsp_if | 2 +-
checks/emc_vplex_if | 2 +-
checks/huawei_osn_if | 2 +-
checks/if | 2 +-
checks/if.include | 52 ++++++++++++++++++++++++++++++++++++++--------------
checks/if64 | 2 +-
checks/if64_tplink | 2 +-
checks/if64adm | 2 +-
checks/if_brocade | 2 +-
checks/if_fortigate | 2 +-
checks/if_lancom | 2 +-
11 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/checks/adva_fsp_if b/checks/adva_fsp_if
index 2792b99..0f84e7d 100644
--- a/checks/adva_fsp_if
+++ b/checks/adva_fsp_if
@@ -134,6 +134,6 @@ check_info['adva_fsp_if'] = {
"4.1.2544.1.11.2.4.3.5.1.3", # opticalIfDiagInputPower
],
),
- "snmp_scan_function": snmp_scan_function_adva_fsp_if,
"includes": ["if.include"],
+ "snmp_scan_function": get_snmp_if_scan_function('adva_fsp_if'),
}
diff --git a/checks/emc_vplex_if b/checks/emc_vplex_if
index aff53d2..a86eac3 100644
--- a/checks/emc_vplex_if
+++ b/checks/emc_vplex_if
@@ -76,7 +76,7 @@ check_info["emc_vplex_if"] = {
"check_function": check_emc_vplex_if,
"inventory_function": inventory_emc_vplex_if,
"service_description": 'Interface %s',
- 'snmp_scan_function': snmp_scan_function_emc_vplex_if,
+ 'snmp_scan_function': get_snmp_if_scan_function('emc_vplex_if'),
"snmp_info": [
(
".1.3.6.1.4.1.1139.21.2.2",
diff --git a/checks/huawei_osn_if b/checks/huawei_osn_if
index 2acc44a..17e966f 100644
--- a/checks/huawei_osn_if
+++ b/checks/huawei_osn_if
@@ -86,7 +86,7 @@ check_info['huawei_osn_if'] = {
"4.944", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmRXPBAD
13
"4.945", # OPTIX-GLOBAL-NGWDM-MIB::sdh_pathDataPmMonValue.pmTXPBAD
14
]),
- 'snmp_scan_function': snmp_scan_function_huawei_osn_if,
+ 'snmp_scan_function': get_snmp_if_scan_function('huawei_osn_if'),
'has_perfdata': True,
'includes': ['huawei_osn.include', 'if.include'],
'group': 'if',
diff --git a/checks/if b/checks/if
index 5e0b3f2..0d9bc47 100644
--- a/checks/if
+++ b/checks/if
@@ -71,7 +71,7 @@ check_info["if"] = {
]),
# check if number of network interfaces (IF-MIB::ifNumber.0) is at least 2
# use if64 if possible and not disabled
- 'snmp_scan_function': snmp_scan_function_if,
+ 'snmp_scan_function': get_snmp_if_scan_function('if'),
'group': 'if',
'default_levels_variable': 'if_default_levels',
}
diff --git a/checks/if.include b/checks/if.include
index 323c57c..2bba1fc 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -82,26 +82,26 @@ def need_if64adm():
return "portstates" in settings and '9' in
settings["portstates"]
-def snmp_scan_function_if_brocade(oid):
+def _snmp_scan_function_if_brocade(oid):
return "Brocade VDX Switch" in oid(".1.3.6.1.2.1.1.1.0") and (not
if64_disabled(
host_name())) and has_ifHCInOctets(oid)
-def snmp_scan_function_if64adm(oid):
+def _snmp_scan_function_if64adm(oid):
if if64_disabled(host_name()) or not need_if64adm():
return False
return has_ifHCInOctets(oid)
-def snmp_scan_function_adva_fsp_if(oid):
+def _snmp_scan_function_adva_fsp_if(oid):
return oid(".1.3.6.1.2.1.1.1.0") == "Fiber Service Platform F7"
-def snmp_scan_function_if64_tplink(oid):
+def _snmp_scan_function_if64_tplink(oid):
return ".4.1.11863." in oid(".1.3.6.1.2.1.1.2.0") and
has_ifHCInOctets(oid)
-def snmp_scan_function_if_lancom(oid):
+def _snmp_scan_function_if_lancom(oid):
sys_description = oid(".1.3.6.1.2.1.1.1.0")
for name in ("LANCOM", "ELSA", "T-Systems"):
if name in sys_description:
@@ -113,30 +113,30 @@ def snmp_scan_function_if_lancom(oid):
return has_ifHCInOctets(oid)
-def snmp_scan_function_emc_vplex_if(oid):
+def _snmp_scan_function_emc_vplex_if(oid):
return oid(".1.3.6.1.2.1.1.1.0") == "" and
oid(".1.3.6.1.4.1.1139.21.2.2.8.1.*")
-def snmp_scan_function_huawei_osn_if(oid):
+def _snmp_scan_function_huawei_osn_if(oid):
# duplicate code from huawei_osn.include
return ".1.3.6.1.4.1.2011.2.25.1" in oid(".1.3.6.1.2.1.1.2.0")
-def snmp_scan_function_if_fortigate(oid):
+def _snmp_scan_function_if_fortigate(oid):
return
oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.12356")
-def snmp_scan_function_if(oid):
+def _snmp_scan_function_if(oid):
return if64_disabled(host_name()) or not has_ifHCInOctets(oid)
-def if64_scan_function(oid, use_if64adm=False):
+def _if64_scan_function(oid, use_if64adm=False):
if any((
if64_disabled(host_name()),
- snmp_scan_function_if_lancom(oid),
- snmp_scan_function_if_brocade(oid),
- snmp_scan_function_if_fortigate(oid),
- snmp_scan_function_if64_tplink(oid),
+ _snmp_scan_function_if_lancom(oid),
+ _snmp_scan_function_if_brocade(oid),
+ _snmp_scan_function_if_fortigate(oid),
+ _snmp_scan_function_if64_tplink(oid),
need_if64adm() != use_if64adm,
)):
return False
@@ -144,6 +144,30 @@ def if64_scan_function(oid, use_if64adm=False):
return has_ifHCInOctets(oid)
+_SPECIFIC_IF_SCANS = collections.OrderedDict({
+ 'if_brocade': _snmp_scan_function_if_brocade,
+ 'adva_fsp_if': _snmp_scan_function_adva_fsp_if,
+ 'if64_tplink': _snmp_scan_function_if64_tplink,
+ 'if_lancom': _snmp_scan_function_if_lancom,
+ 'emc_vplex_if': _snmp_scan_function_emc_vplex_if,
+ 'huawei_osn_if': _snmp_scan_function_huawei_osn_if,
+ 'if_fortigate': _snmp_scan_function_if_fortigate,
+ 'if64adm': _snmp_scan_function_if64adm,
+})
+
+
+def get_snmp_if_scan_function(plugin_name):
+ if plugin_name in _SPECIFIC_IF_SCANS:
+ return _SPECIFIC_IF_SCANS[plugin_name]
+
+ if plugin_name == 'if':
+ return _snmp_scan_function_if
+ elif plugin_name == 'if64':
+ return _if64_scan_function
+ else:
+ raise NotImplementedError("unknown if plugin: %r" % plugin_name)
+
+
def fix_if_64_highspeed(info):
for line in info:
# TODO: Use six.string_types when this is a module.
diff --git a/checks/if64 b/checks/if64
index 3a849fd..a67e2f6 100644
--- a/checks/if64
+++ b/checks/if64
@@ -41,7 +41,7 @@ check_info["if64"] = {
'has_perfdata': True,
'includes': ['if.include'],
'snmp_info': (".1.3.6.1.2.1", if64_snmp_end_oids),
- 'snmp_scan_function': if64_scan_function,
+ 'snmp_scan_function': get_snmp_if_scan_function('if64'),
'group': 'if',
'node_info': True,
'default_levels_variable': 'if_default_levels',
diff --git a/checks/if64_tplink b/checks/if64_tplink
index d94c149..3fcb348 100644
--- a/checks/if64_tplink
+++ b/checks/if64_tplink
@@ -67,7 +67,7 @@ check_info["if64_tplink"] = {
"4.1.11863.1.1.3.2.1.1.1.1.2", # special for TP Link
BINARY("2.1.2.2.1.6"), # ifPhysAddress 19
]),
- 'snmp_scan_function': snmp_scan_function_if64_tplink,
+ 'snmp_scan_function': get_snmp_if_scan_function('if64_tplink'),
'group': 'if',
'default_levels_variable': 'if_default_levels',
}
diff --git a/checks/if64adm b/checks/if64adm
index da6d8ed..8f18e0a 100644
--- a/checks/if64adm
+++ b/checks/if64adm
@@ -57,7 +57,7 @@ check_info["if64adm"] = {
if64_snmp_end_oids + [
"2.2.1.7", # ifAdminStatus
]),
- 'snmp_scan_function': snmp_scan_function_if64adm,
+ 'snmp_scan_function': get_snmp_if_scan_function('if64adm'),
'group': 'if',
'node_info': True,
'default_levels_variable': 'if_default_levels',
diff --git a/checks/if_brocade b/checks/if_brocade
index df4e778..0ca3801 100644
--- a/checks/if_brocade
+++ b/checks/if_brocade
@@ -94,7 +94,7 @@ check_info["if_brocade"] = {
(".1.3.6.1.4.1.2356.11.1.3.56.1", [1, 3]) # brocade: SSID
21
],
# check if number of network interfaces (IF-MIB::ifNumber.0) is at least 2
- 'snmp_scan_function': snmp_scan_function_if_brocade,
+ 'snmp_scan_function': get_snmp_if_scan_function('if_brocade'),
'group': 'if',
'default_levels_variable': 'if_default_levels',
}
diff --git a/checks/if_fortigate b/checks/if_fortigate
index cb17108..5e2ed98 100644
--- a/checks/if_fortigate
+++ b/checks/if_fortigate
@@ -63,7 +63,7 @@ check_info["if_fortigate"] = {
BINARY("2.2.1.6"), # ifPhysAddress 19
"31.1.1.1.15", # ifHighSpeed -1 (parse_if64 assumes
this is the last element)
]),
- 'snmp_scan_function': snmp_scan_function_if_fortigate,
+ 'snmp_scan_function': get_snmp_if_scan_function('if_fortigate'),
'has_perfdata': True,
'includes': ["if.include"],
'group': 'if',
diff --git a/checks/if_lancom b/checks/if_lancom
index 9116312..d676d0d 100644
--- a/checks/if_lancom
+++ b/checks/if_lancom
@@ -94,7 +94,7 @@ check_info["if_lancom"] = {
(".1.3.6.1.4.1.2356.11.1.3.56.1", [1, 3]) # LANCOM: SSID
21
],
# check if number of network interfaces (IF-MIB::ifNumber.0) is at least 2
- 'snmp_scan_function': snmp_scan_function_if_lancom,
+ 'snmp_scan_function': get_snmp_if_scan_function('if_lancom'),
'group': 'if',
'default_levels_variable': 'if_default_levels',
}