Module: check_mk
Branch: master
Commit: 357170a1dde7ffff7371729e61af84482b80e731
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=357170a1dde7ff…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jan 14 13:10:25 2019 +0100
Update persisted sections with existing (filtered) persisted sections before saving
Change-Id: I5dba7b5f4921d4acd0f49f01b3067e6ee08cab3c
---
cmk_base/data_sources/abstract.py | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/cmk_base/data_sources/abstract.py b/cmk_base/data_sources/abstract.py
index ca783c1..4de01d5 100644
--- a/cmk_base/data_sources/abstract.py
+++ b/cmk_base/data_sources/abstract.py
@@ -122,7 +122,6 @@ class DataSource(object):
try:
cpu_tracking.push_phase(self._cpu_tracking_id())
- self._persisted_sections = self._load_persisted_sections()
raw_data, is_cached_data = self._get_raw_data()
self._host_sections = host_sections = self._convert_to_sections(raw_data)
@@ -131,11 +130,9 @@ 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)
+ host_sections = self._update_info_with_persisted_sections(host_sections,
is_cached_data)
+ self._persisted_sections = host_sections.persisted_sections
return host_sections
@@ -428,24 +425,31 @@ 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):
- if not self._persisted_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(host_sections.persisted_sections)
+
+ if not persisted_sections:
return host_sections
- for section_name, entry in self._persisted_sections.items():
+ for section_name, entry in persisted_sections.items():
if len(entry) == 2:
continue # Skip entries of "old" format
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):