Module: check_mk
Branch: master
Commit: fe968afbff3a50939c5882cefc2a4979ad9da3fb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe968afbff3a50…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 15 02:56:24 2013 +0200
Automatically remove duplicate checks on SNMP+TCP
This was very annoying. Now if a host as a TCP based and SNMP based variant
of the same check then the SNMP based one is silently dropped. It is still
handled during inventory and visible in WATO. But when the actual monitoring
configuration is being created, it is omitted.
In the rare case where the user wants to prefer the SNMP based check, he
can still use disabled_checks and disable the TCP based one for the host
in question.
---
.bugs/955 | 7 +++++--
ChangeLog | 4 +++-
modules/check_mk.py | 49 ++++++++++++++++++++++++++++++++++++++--------
modules/check_mk_base.py | 2 +-
4 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/.bugs/955 b/.bugs/955
index 0595fb7..f5e5992 100644
--- a/.bugs/955
+++ b/.bugs/955
@@ -1,9 +1,9 @@
Title: Automatically remove duplicate checks
Component: core
-State: open
+Class: nastiness
+State: done
Date: 2013-09-26 09:23:02
Targetversion: 1.2.3i3
-Class: nastiness
When you check a host with TCP and SNMP, you most times have
duplicate checks. This is nasty because you manually have
@@ -11,3 +11,6 @@ to ignore the duplicate.
We simply could silently disable the SNMP based variants
if a TCP based variant already exist.
+
+2013-10-15 02:53:21: changed state open -> done
+Done.
diff --git a/ChangeLog b/ChangeLog
index 36d1b3c..c7572bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,7 +6,9 @@
* FIX: fix configuration of explicit SNMP community, allow unicode
* FIX: avoid invalid cache of 2nd and up hosts in bulk inventory
* FIX: fixed error handling in SNMP scan, inventory check fails now
- if SNMP agent is not responding
+ if SNMP agent is not responding
+ * Automatically remove duplicate checks when monitoring with Agent+SNMP
+ at the same time. TCP based ones have precedence.
* inventory check of SNMP devices now does scan per default (configurable)
Multisite:
diff --git a/modules/check_mk.py b/modules/check_mk.py
index d29e890..5b59f92 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -593,6 +593,9 @@ def is_tcp_host(hostname):
def is_ping_host(hostname):
return not is_snmp_host(hostname) and not is_tcp_host(hostname)
+def is_dual_host(hostname):
+ return is_tcp_host(hostname) and is_snmp_host(hostname)
+
def check_period_of(hostname, service):
periods = service_extra_conf(hostname, service, check_periods)
if periods:
@@ -951,13 +954,16 @@ g_check_table_cache = {}
# are used in the autochecks and assumed be make up the vast majority.
g_singlehost_checks = None
g_multihost_checks = None
-def get_check_table(hostname):
+def get_check_table(hostname, remove_duplicates=False):
global g_singlehost_checks
global g_multihost_checks
# speed up multiple lookup of same host
if hostname in g_check_table_cache:
- return g_check_table_cache[hostname]
+ if remove_duplicates and is_dual_host(hostname):
+ return remove_duplicate_checks(g_check_table_cache[hostname])
+ else:
+ return g_check_table_cache[hostname]
check_table = {}
@@ -1039,15 +1045,42 @@ def get_check_table(hostname):
deps.append(d)
g_check_table_cache[hostname] = check_table
- return check_table
+ if remove_duplicates and is_dual_host(hostname):
+ return remove_duplicate_checks(check_table)
+ else:
+ return check_table
+
+def remove_duplicate_checks(check_table):
+ have_with_tcp = {}
+ have_with_snmp = {}
+ without_duplicates = {}
+ for key, value in check_table.iteritems():
+ checkname = key[0]
+ descr = value[1]
+ if check_uses_snmp(checkname):
+ if descr in have_with_tcp:
+ continue
+ have_with_snmp[descr] = key
+ else:
+ if descr in have_with_snmp:
+ snmp_key = have_with_snmp[descr]
+ del without_duplicates[snmp_key]
+ del have_with_snmp[descr]
+ have_with_tcp[descr] = key
+ without_duplicates[key] = value
+ return without_duplicates
+
-def get_sorted_check_table(hostname):
+# remove_duplicates: Automatically remove SNMP based checks
+# if there already is a TCP based one with the same
+# description. E.g: df vs hr_fs.
+def get_sorted_check_table(hostname, remove_duplicates=False):
# Convert from dictionary into simple tuple list. Then sort
# it according to the service dependencies.
unsorted = [ (checkname, item, params, descr, deps)
for ((checkname, item), (params, descr, deps))
- in get_check_table(hostname).items() ]
+ in get_check_table(hostname,
remove_duplicates=remove_duplicates).items() ]
def cmp(a, b):
if a[3] < b[3]:
return -1
@@ -1920,7 +1953,7 @@ define servicedependency {
return result
- host_checks = get_check_table(hostname).items()
+ host_checks = get_check_table(hostname, remove_duplicates=True).items()
host_checks.sort() # Create deterministic order
aggregated_services_conf = set([])
do_aggregation = host_is_aggregated(hostname)
@@ -2900,7 +2933,7 @@ def find_check_plugins(checktype):
return paths
def get_precompiled_check_table(hostname):
- host_checks = get_sorted_check_table(hostname)
+ host_checks = get_sorted_check_table(hostname, remove_duplicates=True)
precomp_table = []
for checktype, item, params, description, deps in host_checks:
aggr_name = aggregated_service_name(hostname, description)
@@ -3006,7 +3039,7 @@ no_inventory_possible = None
output.write("%s = %r\n" % (var, globals()[var]))
output.write("\n# Checks for %s\n\n" % hostname)
- output.write("def get_sorted_check_table(hostname):\n return %r\n\n" %
check_table)
+ output.write("def get_sorted_check_table(hostname, remove_duplicates=False):\n
return %r\n\n" % check_table)
# Do we need to load the SNMP module? This is the case, if the host
# has at least one SNMP based check. Also collect the needed check
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 1b37a71..a47207e 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1032,7 +1032,7 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
g_hostname = hostname
num_success = 0
error_sections = set([])
- check_table = get_sorted_check_table(hostname)
+ check_table = get_sorted_check_table(hostname, remove_duplicates=True)
problems = []
for checkname, item, params, description, info in check_table: