Module: check_mk
Branch: master
Commit: 65f91ab899f606fdc8234f93faca0b12a6036da3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=65f91ab899f606…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Jun 3 13:10:14 2013 +0200
no longer output cached data if its older than twice the max cache age
---
ChangeLog | 2 ++
agents/check_mk_agent.linux | 11 ++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 8052cde..a56c28d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,8 @@
* windows_agent: Now available as 64 bit version
* agent_vsphere: fix problem where sensors were missing when
you queried multiple host systems via vCenter
+ * cached checks: no longer output cached data if the age of the
+ cache file is twice the maximum cache age
Notifications:
* Flexible Notification can now filter service levels
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 335ba79..2ef7e6e 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -63,9 +63,18 @@ function run_cached () {
if [ ! -d $MK_CONFDIR/cache ]; then mkdir -p $MK_CONFDIR/cache ; fi
CACHEFILE="$MK_CONFDIR/cache/$NAME.cache"
+ # Check if the creation of the cache takes suspiciously long and return
+ # nothing if the age (access time) of $CACHEFILE.new is twice the MAXAGE
+ local NOW=$(date +%s)
+ if [ -e "$CACHEFILE.new" ] ; then
+ local CF_ATIME=$(stat -c %X "$CACHEFILE.new")
+ if [ $((NOW - CF_ATIME)) -ge $((MAXAGE * 2)) ] ; then
+ return
+ fi
+ fi
+
# Check if cache file exists and is recent enough
if [ -s "$CACHEFILE" ] ; then
- local NOW=$(date +%s)
local MTIME=$(stat -c %Y "$CACHEFILE")
if [ $((NOW - MTIME)) -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
# Output the file in any case, even if it is