Module: check_mk
Branch: master
Commit: 44ed2bce5b7b75af40eda367a23160b12045131f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=44ed2bce5b7b75…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Sep 12 09:39:43 2017 +0200
5122 FIX Service discovery: Find SNMP checks of not yet monitored type when using cached
data
Change-Id: I84246b81a3c193f868ebd0607d0e5952b5593098
---
.werks/5122 | 11 +++++++++++
cmk_base/checks.py | 8 +++++++-
cmk_base/discovery.py | 33 ++++++++++++++++++++-------------
3 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/.werks/5122 b/.werks/5122
new file mode 100644
index 0000000..8214338
--- /dev/null
+++ b/.werks/5122
@@ -0,0 +1,11 @@
+Title: Service discovery: Find SNMP checks of not yet monitored type when using cached
data
+Level: 2
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1505140261
+
+
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index c23cbb6..094219a 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -499,11 +499,17 @@ def is_tcp_check(check_name):
def discoverable_tcp_checks():
types = []
-
for check_type, check in check_info.items():
if is_tcp_check(check_type) and check["inventory_function"]:
types.append(check_type)
+ return sorted(types)
+
+def discoverable_snmp_checks():
+ types = []
+ for check_type, check in check_info.items():
+ if is_snmp_check(check_type) and check["inventory_function"]:
+ types.append(check_type)
return sorted(types)
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index 9d6364d..f969b47 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -207,7 +207,7 @@ def discover_on_host(mode, hostname, do_snmp_scan, use_caches,
on_error="ignore"
# Compute current state of new and existing checks
services = _get_host_services(hostname, use_caches=use_caches,
- do_snmp_scan=do_snmp_scan, on_error=on_error)
+ do_snmp_scan=do_snmp_scan, on_error=on_error)
# Create new list of checks
new_items = {}
@@ -672,29 +672,37 @@ def _in_keepalive_mode():
# '----------------------------------------------------------------------'
# gather auto_discovered check_types for this host
-def _gather_check_types_native(hostname, ipaddress, on_error, do_snmp_scan):
- check_types = []
+def _gather_check_types_native(hostname, ipaddress, on_error, do_snmp_scan, use_caches):
+ check_types = set()
if config.is_snmp_host(hostname):
# May we do an SNMP scan?
if do_snmp_scan:
try:
- check_types = snmp_scan(hostname, ipaddress, on_error)
+ check_types.update(snmp_scan(hostname, ipaddress, on_error))
except Exception, e:
if on_error == "raise":
raise
elif on_error == "warn":
console.error("SNMP scan failed: %s" % e)
+ # Otherwise we gather all check types from autochecks and cached files.
else:
- # Otherwise use all check types that we already have discovered
- # previously
+ snmp_check_types = set(checks.discoverable_snmp_checks())
for check_type, _unused_item, _unused_params in
read_autochecks_of(hostname):
- if check_type not in check_types and checks.is_snmp_check(check_type):
- check_types.append(check_type)
+ if check_type in snmp_check_types:
+ check_types.add(check_type)
+
+ if use_caches and os.path.isdir(cmk.paths.tcp_cache_dir):
+ for cachefile in os.listdir(cmk.paths.tcp_cache_dir):
+ if not cachefile.startswith("%s." % hostname):
+ continue
+ check_type = cachefile.split("%s." % hostname)[-1]
+ if check_type in snmp_check_types:
+ check_types.add(check_type)
if config.is_tcp_host(hostname) or piggyback.has_piggyback_info(hostname):
- check_types += checks.discoverable_tcp_checks()
- return check_types
+ check_types.update(checks.discoverable_tcp_checks())
+ return list(check_types)
# Create a table of autodiscovered services of a host. Do not save
@@ -747,7 +755,7 @@ def _discover_services(hostname, check_types, use_caches,
do_snmp_scan, on_error
# Check types not specified (via --checks=)? Determine automatically
if not check_types:
- check_types = _gather_check_types_native(hostname, ipaddress, on_error,
do_snmp_scan)
+ check_types = _gather_check_types_native(hostname, ipaddress, on_error,
do_snmp_scan, use_caches)
return services + _discover_services_impl(hostname, check_types, use_caches,
on_error, ipaddress)
@@ -1085,8 +1093,7 @@ def _merge_manual_services(services, hostname, on_error):
continue # ignore
if config.service_ignored(hostname, check_type, descr):
- new_source = "ignored"
- services[(check_type, item)] = (new_source, paramstring)
+ services[(check_type, item)] = ("ignored", paramstring)
return services