Module: check_mk
Branch: master
Commit: 011d76cade7cc08e276523478fc68332dbe61d94
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=011d76cade7cc0…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Apr 26 14:59:16 2019 +0200
agent_aws: factor out determination of timestamp (again)
Change-Id: Ie7edf4e50ef5d381372068093d44433d192e9ff8
---
cmk/special_agents/agent_aws.py | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/cmk/special_agents/agent_aws.py b/cmk/special_agents/agent_aws.py
index 63a050a..2191e1f 100644
--- a/cmk/special_agents/agent_aws.py
+++ b/cmk/special_agents/agent_aws.py
@@ -634,27 +634,33 @@ class AWSSection(object):
cache_timestamp = time.time()
return AWSRawContent(raw_content, cache_timestamp)
- def _cache_is_recent_enough(self, colleague_contents):
+ @property
+ def cache_timestamp(self):
if not self._cache_file.exists():
- logging.info("New cache file %s", self._cache_file)
- return False
+ return None
- now = time.time()
try:
- mtime = self._cache_file.stat().st_mtime
+ return self._cache_file.stat().st_mtime
except OSError as e:
if e.errno == 2:
logging.info("No such file or directory %s (calculate age)",
self._cache_file)
- return False
- else:
- logging.info("Cannot calculate cache file age: %s", e)
- raise
+ return None
+ logging.info("Cannot calculate cache file age: %s", e)
+ raise
+
+ def _cache_is_recent_enough(self, colleague_contents):
+ mtime = self.cache_timestamp
+ if mtime is None:
+ return False
+
+ age = time.time() - mtime
+ if age < 0:
+ logging.info("Cache file from future considered invalid: %s",
self._cache_file)
+ return False
- age = now - mtime
if age >= self.interval:
logging.info("Cache file %s is outdated", self._cache_file)
return False
-
if colleague_contents.cache_timestamp > mtime:
logging.info("Colleague data is newer than cache file %s",
self._cache_file)
return False