Module: check_mk
Branch: master
Commit: 62673227ec2bdbd5d61eecb5a5e9d431f62b9daf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62673227ec2bdb…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jan 11 09:39:35 2019 +0100
Update persisted sections with existing (filtered) persisted sections before saving
Change-Id: Ifc93a6f18cdc2b352b15cb9bd102c1923ea677cf
---
cmk_base/data_sources/abstract.py | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/cmk_base/data_sources/abstract.py b/cmk_base/data_sources/abstract.py
index 56e562d..4b8d1e3 100644
--- a/cmk_base/data_sources/abstract.py
+++ b/cmk_base/data_sources/abstract.py
@@ -128,13 +128,8 @@ class DataSource(object):
if get_raw_data:
return raw_data
- if host_sections.persisted_sections and not is_cached_data:
- self._store_persisted_sections(host_sections.persisted_sections)
-
# Add information from previous persisted infos
- host_sections = self._update_info_with_persisted_sections(host_sections)
-
- return host_sections
+ return self._update_info_with_persisted_sections(host_sections,
is_cached_data)
except MKTerminate:
raise
@@ -413,7 +408,6 @@ class DataSource(object):
return
file_path = self._persisted_sections_file_path()
-
try:
os.makedirs(os.path.dirname(file_path))
except OSError as e:
@@ -425,8 +419,14 @@ class DataSource(object):
store.save_data_to_file(file_path, persisted_sections, pretty=False)
self._logger.debug("Stored persisted sections: %s" % (",
".join(persisted_sections.keys())))
- def _update_info_with_persisted_sections(self, host_sections):
+ def _update_info_with_persisted_sections(self, host_sections, is_cached_data):
+ persisted_sections_from_raw = host_sections.persisted_sections
persisted_sections = self._load_persisted_sections()
+
+ if persisted_sections_from_raw and not is_cached_data:
+ persisted_sections.update(persisted_sections_from_raw)
+ self._store_persisted_sections(persisted_sections)
+
if not persisted_sections:
return host_sections
@@ -437,13 +437,13 @@ class DataSource(object):
persisted_from, persisted_until, section_info = entry
# Don't overwrite sections that have been received from the source with
this call
- if section_name not in host_sections.sections:
+ if section_name in host_sections.sections:
+ self._logger.debug(
+ "Skipping persisted section %r, live data available" %
(section_name))
+ else:
self._logger.debug("Using persisted section %r" %
(section_name))
host_sections.add_cached_section(section_name, section_info,
persisted_from,
persisted_until)
- else:
- self._logger.debug("Skipping persisted section %r" %
(section_name))
-
return host_sections
def _load_persisted_sections(self):