Module: check_mk
Branch: master
Commit: 34819035a76e123045f1d59d6e4b3e30433b18c6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=34819035a76e12…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 28 13:15:37 2016 +0200
3893 FIX Predictive levels: Improved handling of broken prediction files (empty files)
In previous versions it could happen that the predictive levels feature created empty
(zero byte sized) files below var/check_mk/prediction which made the predictive levels
not work anymore for the affected service. This situation is now being repaired
automatically.
---
.werks/3893 | 12 ++++++++++++
ChangeLog | 1 +
modules/prediction.py | 7 +++++++
web/htdocs/prediction.py | 22 ++++++++++++++--------
4 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/.werks/3893 b/.werks/3893
new file mode 100644
index 0000000..57219f0
--- /dev/null
+++ b/.werks/3893
@@ -0,0 +1,12 @@
+Title: Predictive levels: Improved handling of broken prediction files (empty files)
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.4.0i1
+Date: 1475061250
+Class: fix
+
+In previous versions it could happen that the predictive levels feature created empty
+(zero byte sized) files below var/check_mk/prediction which made the predictive levels
+not work anymore for the affected service. This situation is now being repaired
+automatically.
diff --git a/ChangeLog b/ChangeLog
index f9f68e0..b1ac70e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,7 @@
* 3846 FIX: Nagios: define_contactgroups = False is handled correctly again
* 3852 FIX: Host related files are now deleted during host deletion...
* 3737 FIX: Fixed slow activation of changes due to loss of IP address cache...
+ * 3893 FIX: Predictive levels: Improved handling of broken prediction files (empty
files)...
Checks & Agents:
* 3183 aruba_wlc_aps: new check which monitors the provisioned accesspoints of an
Aruba Network WLAN Controller
diff --git a/modules/prediction.py b/modules/prediction.py
index 1a31b33..f1c3387 100644
--- a/modules/prediction.py
+++ b/modules/prediction.py
@@ -213,6 +213,13 @@ def get_predictive_levels(dsname, params, cf, levels_factor=1.0):
pred_file = "%s/%s" % (dir, timegroup)
info_file = pred_file + ".info"
+ # In previous versions it could happen that the files were created with 0 bytes of
size
+ # which was never handled correctly so that the prediction could never be used again
until
+ # manual removal of the files. Clean this up.
+ for file_path in [ pred_file, info_file ]:
+ if os.stat(file_path).st_size == 0:
+ os.unlink(file_path)
+
# Check, if we need to (re-)compute the prediction file. This is
# the case if:
# - no prediction has been done yet for this time group
diff --git a/web/htdocs/prediction.py b/web/htdocs/prediction.py
index fb6aa6c..f0e9914 100644
--- a/web/htdocs/prediction.py
+++ b/web/htdocs/prediction.py
@@ -67,14 +67,20 @@ def page_graph():
timegroups = []
now = time.time()
for f in os.listdir(dir):
- if f.endswith(".info"):
- tg_info = eval(file(dir + "/" + f).read())
- tg_info["name"] = f[:-5]
- timegroups.append(tg_info)
- if tg_info["name"] == tg_name or \
- (tg_name == None and now >= tg_info["range"][0] and now
<= tg_info["range"][1]):
- timegroup = tg_info
- tg_name = tg_info["name"]
+ file_path = dir + "/" + f
+ if not f.endswith(".info"):
+ continue
+
+ if os.stat(file_path).st_size == 0:
+ continue
+
+ tg_info = eval(file(dir + "/" + f).read())
+ tg_info["name"] = f[:-5]
+ timegroups.append(tg_info)
+ if tg_info["name"] == tg_name or \
+ (tg_name == None and now >= tg_info["range"][0] and now <=
tg_info["range"][1]):
+ timegroup = tg_info
+ tg_name = tg_info["name"]
timegroups.sort(cmp = lambda a,b: cmp(a["range"][0],
b["range"][0]))