Module: check_mk
Branch: master
Commit: 88c69fddadc2a5eb87e03c8be4c30ee3e1dcbade
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=88c69fddadc2a5…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Mar 7 15:40:54 2019 +0100
if.include: rigorously make if-scans mutually exclusive
7214 Interface checks: Introduce scan function API
In the past conflicting check plugins with services called "Interface
<ITEM>"
could lead to a "duplicate services" warning on the discovery page.
To avoid this issue in the future, all scan functions for those plugins
are now located in the file "if.include".
If you add a new "Interface <ITEM>"- service, please add the
corresponding
scan function to the file "if.include", and list in the dictionary
<tt>_SPECIFIC_IF_SCANS</tt>. You can then access the scan function by
specifying
<tt> 'snmp_scan_function':
get_snmp_if_scan_function('my_if_check')</tt>
in your check plugin.
The matching devices will then be automatically excluded from the generic if
and if64 check plugin.
7215 FIX Avoid duplicate services for if_fortigate check
This fixes the duplicate services warning displayed on the
discovery page for if/if_fortigate checks.
Services of the if checkplugin are no longer discovered if
the if_fortigate plugin already found interfaces.
Change-Id: Id6736a24fcce8f235354213bd3708527ea5b8779
---
.werks/7214 | 21 +++++++++++++++++++++
.werks/7215 | 14 ++++++++++++++
checks/if.include | 40 ++++++++++++++++++++--------------------
3 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/.werks/7214 b/.werks/7214
new file mode 100644
index 0000000..640242e
--- /dev/null
+++ b/.werks/7214
@@ -0,0 +1,21 @@
+Title: Interface checks: Introduce scan function API
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.6.0i1
+Date: 1552033415
+Class: feature
+
+In the past conflicting check plugins with services called "Interface
<ITEM>"
+could lead to a "duplicate services" warning on the discovery page.
+
+To avoid this issue in the future, all scan functions for those plugins
+are now located in the file "if.include".
+If you add a new "Interface <ITEM>"- service, please add the
corresponding
+scan function to the file "if.include", and list in the dictionary
+<tt>_SPECIFIC_IF_SCANS</tt>. You can then access the scan function by
specifying
+<tt> 'snmp_scan_function':
get_snmp_if_scan_function('my_if_check')</tt>
+in your check plugin.
+The matching devices will then be automatically excluded from the generic if
+and if64 check plugin.
diff --git a/.werks/7215 b/.werks/7215
new file mode 100644
index 0000000..38dc992
--- /dev/null
+++ b/.werks/7215
@@ -0,0 +1,14 @@
+Title: Avoid duplicate services for if_fortigate check
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1552034080
+Class: fix
+
+This fixes the duplicate services warning displayed on the
+discovery page for if/if_fortigate checks.
+
+Services of the if checkplugin are no longer discovered if
+the if_fortigate plugin already found interfaces.
diff --git a/checks/if.include b/checks/if.include
index 2bba1fc..1bebb26 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -126,24 +126,6 @@ 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):
- return if64_disabled(host_name()) or not has_ifHCInOctets(oid)
-
-
-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),
- need_if64adm() != use_if64adm,
- )):
- return 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,
@@ -156,17 +138,35 @@ _SPECIFIC_IF_SCANS = collections.OrderedDict({
})
+def is_specific(oid):
+ return any(scan(oid) for scan in _SPECIFIC_IF_SCANS.values())
+
+
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
+
+ def wrapped_scan_function(oid):
+ if is_specific(oid):
+ return False
+ return if64_disabled(host_name()) or not has_ifHCInOctets(oid)
+
elif plugin_name == 'if64':
- return _if64_scan_function
+
+ def wrapped_scan_function(oid):
+ if if64_disabled(host_name()) or is_specific(oid):
+ return False
+ if need_if64adm():
+ return False
+ return has_ifHCInOctets(oid)
+
else:
raise NotImplementedError("unknown if plugin: %r" % plugin_name)
+ return wrapped_scan_function
+
def fix_if_64_highspeed(info):
for line in info: