Module: check_mk
Branch: master
Commit: 5f904fec4bbe7b709d5bde240dd36933ef0d50d6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5f904fec4bbe7b…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Apr 26 15:03:18 2019 +0200
agent_aws: factor out validation by arguments (again)
Change-Id: Iddb5ec7be536396865749d8d09f0853ee62d38f7
---
cmk/special_agents/agent_aws.py | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/cmk/special_agents/agent_aws.py b/cmk/special_agents/agent_aws.py
index 2191e1f..7c5804f 100644
--- a/cmk/special_agents/agent_aws.py
+++ b/cmk/special_agents/agent_aws.py
@@ -624,7 +624,8 @@ class AWSSection(object):
# Cache is only used if the age is lower than section interval AND
# the collected data from colleagues are not newer
self._cache_file_dir.mkdir(parents=True, exist_ok=True)
- if use_cache and self._cache_is_recent_enough(colleague_contents):
+ if (use_cache and self.get_validity_from_args(colleague_contents) and
+ self._cache_is_recent_enough()):
raw_content, cache_timestamp = self._read_from_cache()
else:
raw_content = self._fetch_raw_content(colleague_contents)
@@ -648,20 +649,26 @@ class AWSSection(object):
logging.info("Cannot calculate cache file age: %s", e)
raise
- def _cache_is_recent_enough(self, colleague_contents):
+ def _cache_is_recent_enough(self):
mtime = self.cache_timestamp
if mtime is None:
return False
age = time.time() - mtime
+ if 0 <= age < self.interval:
+ return True
+
if age < 0:
logging.info("Cache file from future considered invalid: %s",
self._cache_file)
- return False
-
- if age >= self.interval:
+ else:
logging.info("Cache file %s is outdated", self._cache_file)
+ return False
+
+ def get_validity_from_args(self, colleague_contents):
+ my_cache_timestamp = self.cache_timestamp
+ if my_cache_timestamp is None:
return False
- if colleague_contents.cache_timestamp > mtime:
+ if colleague_contents.cache_timestamp > my_cache_timestamp:
logging.info("Colleague data is newer than cache file %s",
self._cache_file)
return False
return True