Module: check_mk
Branch: master
Commit: 869d9e28aca8f152c64434d50c5a548e1296d492
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=869d9e28aca8f1…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Nov 25 16:41:45 2016 +0100
3993 Some minor performance improvements during config generation
Rules with host tags as well as explicit set host names now being processed faster.
However, those kinds of rules are quite rare...
---
.werks/3993 | 10 ++++++++++
ChangeLog | 1 +
modules/check_mk.py | 26 ++++++++++++++++++--------
3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/.werks/3993 b/.werks/3993
new file mode 100644
index 0000000..60d0d0d
--- /dev/null
+++ b/.werks/3993
@@ -0,0 +1,10 @@
+Title: Some minor performance improvements during config generation
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i3
+Date: 1480088343
+Class: feature
+
+Rules with host tags as well as explicit set host names now being processed faster.
+However, those kinds of rules are quite rare...
diff --git a/ChangeLog b/ChangeLog
index fe41b15..b93da3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
* 4096 avaya_chassis_card, avaya_chassis_ps, avaya_chassis_temp: New checks for Avaya
devices...
* 4094 apc_rackpdu_power: now detects all phases or banks connected to this pdu
NOTE: Please refer to the migration notes!
+ * 3993 Some minor performance improvements during config generation...
* 3987 FIX: Check_MK Agent Access: Windows agent reported incorrect only from value
* 3952 FIX: diskstat: fixed bug if multipath devices having an alias...
* 3939 FIX: f5_bigip_conns: readded performance data and graphs...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 173df00..d2bc850 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -893,16 +893,26 @@ def all_matching_hosts(tags, hostlist, with_foreign_hosts):
else:
valid_hosts = all_active_hosts()
- # Speed up matching process by filter out single matches
+ # Contains matched hosts
matching = set([])
- if not tags and not [x for x in hostlist if x[0] in ["@", "!",
"~"]]:
- for hostname in hostlist:
- if hostname in valid_hosts:
- matching.add(hostname)
- elif not tags and len(hostlist) == 1 and "@all" in hostlist:
- matching.update(set(valid_hosts))
+
+ # Check if the rule has only specific hosts set
+ only_specific_hosts = not bool([x for x in hostlist if x[0] in ["@",
"!", "~"]])
+
+ # If no tags are specified and there are only specific hosts we already have the
matches
+ if not tags and only_specific_hosts:
+ matching = valid_hosts.intersection(hostlist)
+ # If no tags are specified and the hostlist only include @all (all hosts)
+ elif not tags and hostlist == [ "@all" ]:
+ matching = valid_hosts
else:
- for hostname in valid_hosts:
+ # If the rule has only exact host restrictions, we can thin out the list of hosts
to check
+ if only_specific_hosts:
+ hosts_to_check = valid_hosts.intersection(set(hostlist))
+ else:
+ hosts_to_check = valid_hosts
+
+ for hostname in hosts_to_check:
# When no tag matching is requested, do not filter by tags. Accept all hosts
# and filter only by hostlist
if in_extraconf_hostlist(hostlist, hostname) and \