Module: check_mk
Branch: master
Commit: 2e8c736e2687e3080e951f83271da0f467b3361b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2e8c736e2687e3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 20 08:56:12 2015 +0100
#1869 FIX Deleting outdated persisted agent sections now
---
.werks/1869 | 9 +++++++++
ChangeLog | 1 +
modules/check_mk_base.py | 41 ++++++++++++++++++++---------------------
3 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/.werks/1869 b/.werks/1869
new file mode 100644
index 0000000..3ad9b76
--- /dev/null
+++ b/.werks/1869
@@ -0,0 +1,9 @@
+Title: Deleting outdated persisted agent sections now
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.7i1
+Date: 1421740547
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 9c673cd..60489fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
* 1832 FIX: Fix "global name 'splitted' is not defined" in bulk
inventory...
* 1808 FIX: Fixed broken nagios config when using RBN without a host defined...
* 1842 FIX: Rewrote implementation of service discovery (formerly inventory)...
+ * 1869 FIX: Deleting outdated persisted agent sections now
Checks & Agents:
* 1665 agent_netapp: New special agent for NetApp monitoring via Web-API...
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index bf1dbe7..a530599 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -503,27 +503,32 @@ def store_persisted_info(hostname, persisted):
if not os.path.exists(dir):
os.makedirs(dir)
file(dir + hostname, "w").write("%r\n" % persisted)
- if opt_verbose:
- sys.stdout.write("Persisted sections %s.\n" % ",
".join(persisted.keys()))
+ verbose("Persisted sections %s.\n" % ",
".join(persisted.keys()))
def add_persisted_info(hostname, info):
+ file_path = var_dir + "/persisted/" + hostname
try:
- path = var_dir + "/persisted/" + hostname
- persisted = eval(file(path).read())
+ persisted = eval(file(file_path).read())
except:
return
now = time.time()
+ modified = False
for section, (persisted_until, persisted_section) in persisted.items():
if now < persisted_until or opt_force:
if section not in info:
info[section] = persisted_section
- if opt_verbose:
- sys.stdout.write("Added persisted section %s.\n" %
section)
+ verbose("Added persisted section %s.\n" % section)
else:
- if opt_verbose:
- sys.stdout.write("Persisted section %s is outdated by %d
seconds.\n" % (
- section, persisted_until - now))
+ verbose("Persisted section %s is outdated by %d seconds. Deleting
it.\n" % (
+ section, now - persisted_until))
+ del persisted[section]
+ modified = True
+
+ if not persisted:
+ os.remove(file_path)
+ elif modified:
+ store_persisted_info(hostname, persisted)
def get_piggyback_info(hostname):
@@ -538,15 +543,12 @@ def get_piggyback_info(hostname):
file_path = dir + "/" + sourcehost
if cachefile_age(file_path) > piggyback_max_cachefile_age:
- if opt_debug:
- sys.stderr.write("Piggyback file %s is outdated by %d
seconds. Deleting it.\n" %
- (file_path, cachefile_age(file_path) -
piggyback_max_cachefile_age))
+ verbose("Piggyback file %s is outdated by %d seconds. Deleting
it.\n" %
+ (file_path, cachefile_age(file_path) -
piggyback_max_cachefile_age))
os.remove(file_path)
continue
- if opt_debug:
- sys.stderr.write("Using piggyback information from host
%s.\n" %
- sourcehost)
+ verbose("Using piggyback information from host %s.\n" %
sourcehost)
output += file(file_path).read()
return output
@@ -555,8 +557,7 @@ def get_piggyback_info(hostname):
def store_piggyback_info(sourcehost, piggybacked):
piggyback_path = tmp_dir + "/piggyback/"
for backedhost, lines in piggybacked.items():
- if opt_debug:
- sys.stderr.write("Storing piggyback data for %s.\n" % backedhost)
+ verbose("Storing piggyback data for %s.\n" % backedhost)
dir = piggyback_path + backedhost
if not os.path.exists(dir):
os.makedirs(dir)
@@ -580,8 +581,7 @@ def remove_piggyback_info_from(sourcehost, keep=[]):
if backedhost not in ['.', '..'] and backedhost not in keep:
path = piggyback_path + backedhost + "/" + sourcehost
if os.path.exists(path):
- if opt_debug:
- sys.stderr.write("Removing stale piggyback file %s\n" %
path)
+ verbose("Removing stale piggyback file %s\n" % path)
os.remove(path)
removed += 1
@@ -639,8 +639,7 @@ def read_cache_file(relpath, max_cache_age):
result = f.read(10000000)
f.close()
if len(result) > 0:
- if opt_debug:
- sys.stderr.write("Using data from cachefile %s.\n" %
cachefile)
+ verbose("Using data from cachefile %s.\n" % cachefile)
return result
elif opt_debug:
sys.stderr.write("Skipping cache file %s: Too old "