Module: check_mk
Branch: master
Commit: 163493ec54158eb168ea9f1be22e4d1f782fc37e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=163493ec54158e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 13 11:45:36 2018 +0200
6564 FIX Fixed incorrect rate computation affecting various checks in some cases
All previous 1.5 releases used a partially broken counter / rate computation in
various checks in specific situations, e.g. inotify checks. Not all check
results were computed wrong, only the ones based on counter / rate
computations.
When a single check monitors several services on a host, only the first of
these services was affected by this issue.
Change-Id: Ib7883c2684b14871a13151b2be11b6a35643dd8a
---
.werks/6564 | 17 +++++++++++++++++
cmk_base/checking.py | 6 ------
cmk_base/data_sources/host_sections.py | 5 +++++
cmk_base/item_state.py | 22 +++++++++++++++-------
4 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/.werks/6564 b/.werks/6564
new file mode 100644
index 0000000..6c270dd
--- /dev/null
+++ b/.werks/6564
@@ -0,0 +1,17 @@
+Title: Fixed incorrect rate computation affecting various checks in some cases
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1536829823
+
+All previous 1.5 releases used a partially broken counter / rate computation in
+various checks in specific situations, e.g. inotify checks. Not all check
+results were computed wrong, only the ones based on counter / rate
+computations.
+
+When a single check monitors several services on a host, only the first of
+these services was affected by this issue.
diff --git a/cmk_base/checking.py b/cmk_base/checking.py
index 97a9919..22178b0 100644
--- a/cmk_base/checking.py
+++ b/cmk_base/checking.py
@@ -265,12 +265,6 @@ def execute_check(multi_host_sections, hostname, ipaddress,
check_plugin_name, i
section_name = cmk_base.check_utils.section_name_of(check_plugin_name)
- # We need to set this again, because get_section_content has the side effect of
setting this with
- # item None if there is a parse function. This would break the entire
set_item/get_rate logic
- # for checks with items that rely on this being handled by the API.
- # TODO: Write a regression test for this.
- item_state.set_item_state_prefix(check_plugin_name, item)
-
dont_submit = False
section_content = None
try:
diff --git a/cmk_base/data_sources/host_sections.py
b/cmk_base/data_sources/host_sections.py
index 82942e2..d3db705 100644
--- a/cmk_base/data_sources/host_sections.py
+++ b/cmk_base/data_sources/host_sections.py
@@ -252,6 +252,9 @@ class MultiHostSections(object):
if not parse_function:
return section_content
+ # TODO: Item state needs to be handled in local objects instead of the
+ # item_state._cached_item_states object
+ orig_item_state_prefix = item_state.get_item_state_prefix()
try:
item_state.set_item_state_prefix(section_name, None)
return parse_function(section_content)
@@ -259,6 +262,8 @@ class MultiHostSections(object):
if cmk.debug.enabled():
raise
raise MKParseFunctionError(*sys.exc_info())
+ finally:
+ item_state.set_item_state_prefix(*orig_item_state_prefix)
return section_content
diff --git a/cmk_base/item_state.py b/cmk_base/item_state.py
index 38975e8..590f22f 100644
--- a/cmk_base/item_state.py
+++ b/cmk_base/item_state.py
@@ -155,23 +155,27 @@ class CachedItemStates(object):
pass
+ def get_item_state(self, user_key, default=None):
+ key = self.get_unique_item_state_key(user_key)
+ return self._item_states.get(key, default)
+
+
def set_item_state(self, user_key, state):
key = self.get_unique_item_state_key(user_key)
self._item_states[key] = state
self._updated_item_states[key] = state
- def set_item_state_prefix(self, args):
- self._item_state_prefix = args
+ def get_all_item_states(self):
+ return self._item_states
- def get_item_state(self, user_key, default=None):
- key = self.get_unique_item_state_key(user_key)
- return self._item_states.get(key, default)
+ def get_item_state_prefix(self):
+ return self._item_state_prefix
- def get_all_item_states(self):
- return self._item_states
+ def set_item_state_prefix(self, args):
+ self._item_state_prefix = args
def get_unique_item_state_key(self, user_key):
@@ -237,6 +241,10 @@ def set_item_state_prefix(*args):
_cached_item_states.set_item_state_prefix(args)
+def get_item_state_prefix():
+ return _cached_item_states.get_item_state_prefix()
+
+
def _unique_item_state_key(user_key):
_cached_item_states.get_unique_item_state_key(user_key)