Module: check_mk
Branch: master
Commit: bc40e7d393cbadaeb01c46e396b49039a9aba5c2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bc40e7d393cbad…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Aug 23 11:51:10 2017 +0200
5116 FIX if.include: Fixed wrong handling of duplicate interfaces if "use alias" or "use desccription" is configured
Within the rule {{Network Interface and Switch Port Discovery}}
you are able to configure the service description to use the
interface alias or description. Per default the index is used.
If there are duplicate interfaces with same name, the interface
index should be added.
Unfortunately, the afore-mentioned mechanism was broken. This
has been fixed.
Change-Id: I44221ac4b1323e551ce9758041fae192baa38405
---
.werks/5116 | 19 +++++++++++++++++++
checks/if.include | 35 ++++++++++++++---------------------
2 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/.werks/5116 b/.werks/5116
new file mode 100644
index 0000000..8f03058
--- /dev/null
+++ b/.werks/5116
@@ -0,0 +1,19 @@
+Title: if.include: Fixed wrong handling of duplicate interfaces if "use alias" or "use desccription" is configured
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1503481848
+
+Within the rule {{Network Interface and Switch Port Discovery}}
+you are able to configure the service description to use the
+interface alias or description. Per default the index is used.
+If there are duplicate interfaces with same name, the interface
+index should be added.
+
+
+Unfortunately, the afore-mentioned mechanism was broken. This
+has been fixed.
diff --git a/checks/if.include b/checks/if.include
index 3d0a3ed..5b76a66 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -321,8 +321,6 @@ def inventory_if_common(info, has_nodeinfo = False):
group_patterns = _prepare_if_group_patterns_from_conf()
local_seen = set()
- seen_items = set()
- duplicate = set()
have_groups = {}
# Determine whether single, grouped or both
@@ -416,24 +414,17 @@ def inventory_if_common(info, has_nodeinfo = False):
is_only_in_group = True
# Prepare single interfaces
- if not is_only_in_group:
- if ifIndex in global_seen:
- continue
-
- if item in seen_items: # duplicate
- duplicate.add(item)
- seen_items.add(item)
-
- if ifType in porttypes and ifOperStatus in portstates and \
- port_match(ifAlias, match_alias) and port_match(ifDescr, match_desc):
- params = {}
- if if_inventory_monitor_state:
- params["state"] = [ ifOperStatus ]
-
- if ifSpeed != "" and if_inventory_monitor_speed:
- params["speed"] = int(ifSpeed)
- local_seen.add(ifIndex)
- pre_inventory.append( (item, "%r" % params, int(ifIndex)) )
+ if not is_only_in_group and ifIndex not in global_seen and \
+ ifType in porttypes and ifOperStatus in portstates and \
+ port_match(ifAlias, match_alias) and port_match(ifDescr, match_desc):
+ params = {}
+ if if_inventory_monitor_state:
+ params["state"] = [ ifOperStatus ]
+
+ if ifSpeed != "" and if_inventory_monitor_speed:
+ params["speed"] = int(ifSpeed)
+ local_seen.add(ifIndex)
+ pre_inventory.append((item, "%r" % params, int(ifIndex)))
global_seen = global_seen.union(local_seen)
@@ -476,9 +467,11 @@ def inventory_if_common(info, has_nodeinfo = False):
pre_inventory.append((group_name, "%r" % params, 1))
inventory = []
+ s = set()
+ duplicates = set(x[0] for x in pre_inventory if x[0] in s or s.add(x[0]))
# Check for duplicate items (e.g. when using Alias as item and the alias is not unique)
for item, params, index in pre_inventory:
- if item in duplicate:
+ if item in duplicates:
new_item = "%s %d" % (item, index)
else:
new_item = item