Module: check_mk
Branch: master
Commit: 82929028509bd3d75f19cc4cf343df79f8e1a96e
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=82929028509bd3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 14 08:06:48 2017 +0100
Fixed different issues in recent changes
* Added several explaining comments
* Implemented some TODOs
* Storing of piggyback information is now done after
processing all data sources for all sources at once
* Small cleanups for persisting of agent sections
Change-Id: I58d147c6489cc905ad3300892ef544fd7662ecca
---
cmk_base/data_sources/__init__.py | 71 +++++++++++++++++++++++---------------
cmk_base/data_sources/abstract.py | 47 +++++++++++++++----------
cmk_base/data_sources/host_info.py | 6 +++-
cmk_base/data_sources/piggyback.py | 10 ++++++
cmk_base/data_sources/snmp.py | 16 +++++++--
cmk_base/discovery.py | 8 +++--
cmk_base/snmp.py | 1 -
7 files changed, 106 insertions(+), 53 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=8292902850…
Module: check_mk
Branch: master
Commit: 53d0d35e2b042bb9c517a04fd22a234553d3e8fd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=53d0d35e2b042b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Nov 17 10:24:48 2017 +0100
5436 FIX Fixed logical problem with SNMP check interval rule
The rule was previously configured for each individual check. This was not really
correct, because the SNMP data is fetched for main checks and their sub checks
together. This means that you can not define inidividual SNMP checks intervals for
these checks.
The ruleset "Check intervals for SNMP checks" has now been changed to work with the
"section names" instead of inidividual checks.
Change-Id: I56f00bd5e49f4bf791801da94740b0329eb83671
---
.werks/5436 | 16 ++++++++++++++
cmk_base/checks.py | 8 +++++--
cmk_base/config.py | 9 +++++---
cmk_base/core_nagios.py | 2 +-
cmk_base/data_sources/snmp.py | 2 --
web/plugins/wato/check_mk_configuration.py | 35 +++++++++++++++++++++++-------
6 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/.werks/5436 b/.werks/5436
new file mode 100644
index 0000000..ea2a38b
--- /dev/null
+++ b/.werks/5436
@@ -0,0 +1,16 @@
+Title: Fixed logical problem with SNMP check interval rule
+Level: 1
+Component: core
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1510910528
+Class: fix
+
+The rule was previously configured for each individual check. This was not really
+correct, because the SNMP data is fetched for main checks and their sub checks
+together. This means that you can not define inidividual SNMP checks intervals for
+these checks.
+
+The ruleset "Check intervals for SNMP checks" has now been changed to work with the
+"section names" instead of inidividual checks.
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index abe34b0..1c249c6 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -449,6 +449,10 @@ def initialize_check_type_caches():
# | Misc check related helper functions |
# '----------------------------------------------------------------------'
+def section_name_of(check_name):
+ return check_name.split(".")[0]
+
+
def set_hostname(hostname):
check_api._hostname = hostname
@@ -466,7 +470,7 @@ def is_snmp_check(check_name):
except KeyError:
snmp_checks = cmk_base.runtime_cache.get_set("check_type_snmp")
- result = check_name.split(".")[0] in snmp_checks
+ result = section_name_of(check_name) in snmp_checks
cache[check_name] = result
return result
@@ -479,7 +483,7 @@ def is_tcp_check(check_name):
except KeyError:
tcp_checks = cmk_base.runtime_cache.get_set("check_type_tcp")
- result = check_name.split(".")[0] in tcp_checks
+ result = section_name_of(check_name) in tcp_checks
cache[check_name] = result
return result
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 73fce5d..5a52167 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -852,13 +852,16 @@ def check_period_of(hostname, service):
return None
-def check_interval_of(hostname, checkname):
+def check_interval_of(hostname, section_name):
import cmk_base.checks
- if not cmk_base.checks.is_snmp_check(checkname):
+ if not cmk_base.checks.is_snmp_check(section_name):
return # no values at all for non snmp checks
+ # Previous to 1.5 "match" could be a check name (including subchecks) instead of
+ # only main check names -> section names. This has been cleaned up, but we still
+ # need to be compatible. Strip of the sub check part of "match".
for match, minutes in rulesets.host_extra_conf(hostname, snmp_check_interval):
- if match is None or match == checkname:
+ if match is None or match.split(".")[0] == section_name:
return minutes # use first match
#.
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 9493c91..6507699 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -308,7 +308,7 @@ define servicedependency {
check_interval = int(values[0])
except:
check_interval = float(values[0])
- value = config.check_interval_of(hostname, checkname)
+ value = config.check_interval_of(hostname, checks.section_name_of(checkname))
if value is not None:
check_interval = value
diff --git a/cmk_base/data_sources/snmp.py b/cmk_base/data_sources/snmp.py
index 2ade572..d55da51 100644
--- a/cmk_base/data_sources/snmp.py
+++ b/cmk_base/data_sources/snmp.py
@@ -213,8 +213,6 @@ class SNMPDataSource(DataSource):
persisted_info = {}
for section_name, section_info in raw_data.items():
- # TODO: check_type/section_name? Previously check_type was used
- # for this kind of call. Possibly we need to redefine this!
check_interval = config.check_interval_of(hostname, section_name)
if check_interval is None:
continue
diff --git a/web/plugins/wato/check_mk_configuration.py b/web/plugins/wato/check_mk_configuration.py
index dda8be7..169c209 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -2585,12 +2585,20 @@ register_rule(group,
),
match_type="all")
+
def get_snmp_checktypes():
- checks = watolib.check_mk_local_automation("get-check-information")
- types = [ (cn, (c['title'] != cn and '%s: ' % cn or '') + c['title'])
- for (cn, c) in checks.items() if c['snmp'] ]
- types.sort()
- return [ (None, _('All SNMP Checks')) ] + types
+ checks = watolib.check_mk_local_automation("get-check-information")
+ types = [ (cn, (c['title'] != cn and '%s: ' % cn or '') + c['title'])
+ for (cn, c) in checks.items() if c['snmp'] ]
+ types.sort()
+ return [ (None, _('All SNMP Checks')) ] + types
+
+
+def get_snmp_section_names():
+ checks = watolib.check_mk_local_automation("get-check-information")
+ return [ (None, _('All SNMP Checks')) ] \
+ + sorted([ (cn, cn) for (cn, c) in checks.items() if c['snmp'] ])
+
register_rule(group,
"snmp_check_interval",
@@ -2600,9 +2608,20 @@ register_rule(group,
'With this option it is possible to configure a longer check interval for specific '
'checks, than then normal check interval.'),
elements = [
- DropdownChoice(
- title = _("Checktype"),
- choices = get_snmp_checktypes,
+ Transform(
+ DropdownChoice(
+ title = _("Check"),
+ help = _("You can only configure \"section names\" here and not choose all "
+ "individual SNMP based checks here. It is only possible to define "
+ "SNMP check intervals for main checks and all the related sub "
+ "checks together. The reason for this is that the data of the "
+ "main check and it's sub checks is defined for the whole group "
+ "of checks in the main check and also fetched for all these "
+ "checks together."),
+ choices = get_snmp_section_names,
+ ),
+ # Transform check types to section names
+ forth = lambda e: e.split(".")[0] if e is not None else None,
),
Integer(
title = _("Do check every"),