Module: check_mk
Branch: master
Commit: f7f576c7f1e3c3e0ba53e358ef96263b91d97628
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f7f576c7f1e3c3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 2 11:33:22 2017 +0100
5429 FIX Fixed broken event history expiration (when using default settings)
The Event Console was not deleting outdated entries from the event history.
With the default settings it is intended to delete entries older than 365
days from the EC archive. This did not work.
A message like this can be found each "Housekeeping interval", normaly 1
minute:
[1509618281.352829] Error expiring log files: year out of range
This time window can be configured with the setting "Event history lifetime".
As a workaround you can simply open this setting and save it with the default
value. This will make the event deletion work as expected.
When you are affected, this may result in a way too huge Event Console archive
directory (<tt>~/var/mkeventd/history</tt>) which may result in slow
"Event Console History" views (depends on your filtering). You could clean up
the archive directory by hand to improve the situation.
After applying the update, the next housekeeping run will clean up all your old
archived events.
Change-Id: Ie00346286eee239377b2c38c2e2c05b757084e7a
---
.werks/5429 | 29 +++++++++++++++++++++++++++++
bin/mkeventd | 23 +++++++++++++++++------
lib/event_console.py | 2 +-
3 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/.werks/5429 b/.werks/5429
new file mode 100644
index 0000000..abf304a
--- /dev/null
+++ b/.werks/5429
@@ -0,0 +1,29 @@
+Title: Fixed broken event history expiration (when using default settings)
+Level: 2
+Component: ec
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1509618033
+
+The Event Console was not deleting outdated entries from the event history.
+With the default settings it is intended to delete entries older than 365
+days from the EC archive. This did not work.
+
+A message like this can be found each "Housekeeping interval", normaly 1
minute:
+
+[1509618281.352829] Error expiring log files: year out of range
+
+This time window can be configured with the setting "Event history lifetime".
+As a workaround you can simply open this setting and save it with the default
+value. This will make the event deletion work as expected.
+
+When you are affected, this may result in a way too huge Event Console archive
+directory (<tt>~/var/mkeventd/history</tt>) which may result in slow
+"Event Console History" views (depends on your filtering). You could clean up
+the archive directory by hand to improve the situation.
+
+After applying the update, the next housekeeping run will clean up all your old
+archived events.
diff --git a/bin/mkeventd b/bin/mkeventd
index 4071499..c384398 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -55,6 +55,7 @@ import cmk.paths
import cmk.defines as defines
import cmk.daemon
import cmk.event_console
+import cmk.render
import cmk.profile
from cmk.regex import regex, is_regex
@@ -744,7 +745,7 @@ def update_mongodb_history_lifetime():
if not g_mongo_conn:
connect_mongodb()
- if get_mongodb_max_history_age() == g_config['history_lifetime']:
+ if get_mongodb_max_history_age() == g_config['history_lifetime'] * 86400:
return # do not update already correct index
try:
@@ -754,7 +755,7 @@ def update_mongodb_history_lifetime():
# Delete messages after x days
g_mongo_db.ec_archive.ensure_index([('dt', DESCENDING)],
- expireAfterSeconds = g_config['history_lifetime'],
+ expireAfterSeconds = g_config['history_lifetime'] * 86400,
unique = False
)
@@ -970,16 +971,26 @@ def expire_logfiles(flush = False):
try:
now = time.time()
min_mtime = now - g_config["history_lifetime"] * 86400
+
+ logger.verbose("Expiring logfiles (Horizon: %d days -> %s)" %
+ (g_config["history_lifetime"],
cmk.render.date_and_time(min_mtime)))
+
for fn in os.listdir(log_dir):
if fn.endswith(".log"):
path = log_dir + "/" + fn
+
if flush:
logger.info("Flushed log file %s" % path)
os.remove(path)
- elif os.stat(path).st_mtime < min_mtime:
- logger.info("Deleting log file %s (lifetime expired after %d
days)" %
- (path, g_config["history_lifetime"]))
- os.remove(path)
+
+ else:
+ file_mtime = os.stat(path).st_mtime
+
+ if file_mtime < min_mtime:
+ logger.info("Deleting log file %s (age %s)" %
+ (path, cmk.render.date_and_time(file_mtime)))
+ os.remove(path)
+
except Exception as e:
if opt_debug:
raise
diff --git a/lib/event_console.py b/lib/event_console.py
index d8fd006..eefe2a7 100644
--- a/lib/event_console.py
+++ b/lib/event_console.py
@@ -48,7 +48,7 @@ def default_config():
"retention_interval": 60,
"housekeeping_interval": 60,
"statistics_interval": 5,
- "history_lifetime": 365 * 24 * 3600,
+ "history_lifetime": 365, # days
"history_rotation": "daily",
"replication": None,
"remote_status": None,