Module: check_mk
Branch: master
Commit: 8ab1c0413c1af037379832d0842f2d24e96306d5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8ab1c0413c1af0…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Apr 14 15:36:41 2014 +0200
New option for writing all messages into a syslog-like logfile
The new Event Console global option <i>Syslog-like message logging</i> will
enable
logging of <b>all</b> incoming events into logfiles that have syslog format.
These files will be stored below <tt>var/check_mk/mkeventd/messages</tt> and
will
be named with the same scheme as the history logfiles. They will adopt the same
rotation principle as the history files.
If you are using Check_MK in a non-OMD environment and enable this option then
please make sure that you have some logrotate configuration or similar for
deleting outdated files.
If you are using OMD then consider enabling the global <i>Diskspace
Cleanup</i>.
---
.werks/885 | 18 ++++++++++++++++++
ChangeLog | 3 +++
mkeventd/bin/mkeventd | 27 ++++++++++++++++++++++++---
mkeventd/web/plugins/wato/mkeventd.py | 13 +++++++++++++
web/plugins/wato/backup_domains.py | 2 ++
5 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/.werks/885 b/.werks/885
new file mode 100644
index 0000000..3cbae30
--- /dev/null
+++ b/.werks/885
@@ -0,0 +1,18 @@
+Title: New option for writing all messages into a syslog-like logfile
+Level: 1
+Component: ec
+Version: 1.2.5i3
+Date: 1397482457
+Class: feature
+
+The new Event Console global option <i>Syslog-like message logging</i> will
enable
+logging of <b>all</b> incoming events into logfiles that have syslog format.
+These files will be stored below <tt>var/check_mk/mkeventd/messages</tt> and
will
+be named with the same scheme as the history logfiles. They will adopt the same
+rotation principle as the history files.
+
+If you are using Check_MK in a non-OMD environment and enable this option then
+please make sure that you have some logrotate configuration or similar for
+deleting outdated files.
+
+If you are using OMD then consider enabling the global <i>Diskspace
Cleanup</i>.
diff --git a/ChangeLog b/ChangeLog
index 7510b61..afeded1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -57,6 +57,9 @@
Reporting & Availability:
* 0756 Allow availability of multisite BI aggregates at once...
+ Event Console:
+ * 0885 New option for writing all messages into a syslog-like logfile...
+
Livestatus:
* 0747 FIX: livestatus table hostsbygroup: fixed bug with group_authorization
strict...
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 66ced83..463c7ef 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -407,7 +407,7 @@ def log_event_history(event, what, who="",
addinfo=""):
columns += [ quote_tab(event.get(colname[6:], defval)) # drop "event_"
for colname, defval in event_columns ]
- get_logfile().write("\t".join(map(to_utf8, columns)) + "\n")
+ get_logfile("history").write("\t".join(map(to_utf8, columns))
+ "\n")
def to_utf8(x):
if type(x) == unicode:
@@ -429,9 +429,9 @@ active_history_period = None
# Get file object to current log file, handle also
# history and lifetime limit.
-def get_logfile():
+def get_logfile(basename):
global active_history_period
- log_dir = g_state_dir + "/history"
+ log_dir = g_state_dir + "/" + basename
make_parentdirs(log_dir + "/foo")
# Log into file starting at current history period,
@@ -732,6 +732,7 @@ class EventServer:
self.open_syslog()
self.open_syslog_tcp()
self.open_snmptrap()
+
self._rules = []
self._hash_stats = []
for facility in range(32):
@@ -1483,6 +1484,10 @@ class EventServer:
self.process_event(self.parse_event(line, address))
def process_event(self, event):
+ # Log all incoming messages into a syslog-like text file if that is enabled
+ if g_config["log_messages"]:
+ self.log_message(event)
+
# Rule optimizer
if g_config["rule_optimizer"]:
self._hash_stats[event["facility"]][event["priority"]] +=
1
@@ -1900,6 +1905,21 @@ class EventServer:
return event
+ def log_message(self, event):
+ try:
+ get_logfile("messages").write("%s %s %s%s: %s\n" % (
+ time.strftime("%b %d %H:%M:%S",
time.localtime(event["time"])),
+ event["host"],
+ event["application"],
+ event["pid"] and ("[%s]" % event["pid"]) or
"",
+ event["text"]))
+ except Exception, e:
+ if opt_debug:
+ raise
+ # Better silently ignore errors. We could have run out of
+ # diskspace and make things worse by logging that we could
+ # not log.
+
#.
@@ -2993,6 +3013,7 @@ def load_configuration():
"debug_rules" : False,
"rule_optimizer" : True,
"log_rulehits" : False,
+ "log_messages" : False,
"retention_interval" : 60,
"housekeeping_interval" : 60,
"statistics_interval" : 5,
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 65cf707..0366a9e 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -1649,6 +1649,19 @@ if mkeventd_enabled:
)
register_configvar(group,
+ "log_messages",
+ Checkbox(title = _("Syslog-like message logging"),
+ label = _("Log all messages into syslog-like logfiles"),
+ help = _("When this option is enabled, then
<b>every</b> incoming message is being "
+ "logged into the directory <tt>messages</tt>
in the Event Consoles state "
+ "directory. The logfile rotation is analog to that of the
history logfiles. "
+ "Please note that if you have lots of incoming messages
then these "
+ "files can get very large."),
+ default_value = False),
+ domain = "mkeventd",
+ )
+
+ register_configvar(group,
"rule_optimizer",
Checkbox(title = _("Optimize rule execution"),
label = _("enable optimized rule execution"),
diff --git a/web/plugins/wato/backup_domains.py b/web/plugins/wato/backup_domains.py
index e036a6f..14d7c6c 100644
--- a/web/plugins/wato/backup_domains.py
+++ b/web/plugins/wato/backup_domains.py
@@ -180,6 +180,8 @@ else:
"paths" : [
("dir", "var/mkeventd/history"),
("file", "var/mkeventd/status"),
+ ("file", "var/mkeventd/messages"),
+ ("dir",
"var/mkeventd/messages-history"),
],
},
"dokuwiki": {