Module: check_mk
Branch: master
Commit: 7104f183a1ed46d5822e9ee781c1959fd08678d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7104f183a1ed46…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 17 10:29:25 2014 +0100
logwatch.ec: Optionally monitor the list of forwarded logfiles
You can now have the check <tt>logwatch.ec</tt> - Event Console forwarding of
logfiles - monitor the list of forwarded logfiles. This is enabled by setting
<tt>"monitoring_logfilelist"</tt> to <tt>True</tt> in
the checks parameter
dictionary. WATO shows this as a new check box <i>Warn if list of forwarded
logfiles changes</i> in the rule set <i>Logwatch Event Console
Forwarding</i>.
During inventory the check remembers the list of currently present logfiles
that should be forwarded to the Event Console. If that list changes at any
time later then the check goes to WARN and displays the missing/exceeding
logfiles. Re-inventorize the check in order to acknowledge the new list.
---
.werks/718 | 17 ++++++++
ChangeLog | 1 +
checkman/logwatch.ec | 3 ++
checks/logwatch | 78 ++++++++++++++++++++++++----------
web/plugins/wato/check_parameters.py | 10 +++++
5 files changed, 87 insertions(+), 22 deletions(-)
diff --git a/.werks/718 b/.werks/718
new file mode 100644
index 0000000..c7027b6
--- /dev/null
+++ b/.werks/718
@@ -0,0 +1,17 @@
+Title: logwatch.ec: Optionally monitor the list of forwarded logfiles
+Level: 1
+Component: checks
+Version: 1.2.5i1
+Date: 1392629160
+Class: feature
+
+You can now have the check <tt>logwatch.ec</tt> - Event Console forwarding
of
+logfiles - monitor the list of forwarded logfiles. This is enabled by setting
+<tt>"monitoring_logfilelist"</tt> to <tt>True</tt> in
the checks parameter
+dictionary. WATO shows this as a new check box <i>Warn if list of forwarded
+logfiles changes</i> in the rule set <i>Logwatch Event Console
Forwarding</i>.
+
+During inventory the check remembers the list of currently present logfiles
+that should be forwarded to the Event Console. If that list changes at any
+time later then the check goes to WARN and displays the missing/exceeding
+logfiles. Re-inventorize the check in order to acknowledge the new list.
diff --git a/ChangeLog b/ChangeLog
index 03b0ba7..b66d930 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -89,6 +89,7 @@
* 0135 apc_inputs: New Check for APC Input Contacts
* 0701 emc_isilon_diskstatus: new check for Status of Disks in EMC Isilon Storage
Systems
* 0581 emc_datadomain_disks emc_datadomain_fs: new checks to monitor disks and
filesystems of EMC Datadomain
+ * 0718 logwatch.ec: Optionally monitor the list of forwarded logfiles...
* 0103 FIX: services: Fixed bug with service inventory defined in main.mk...
* 0299 FIX: borcade_mlx_fan: Prettified output, handling "other" state now
* 0300 FIX: cisco_fru_power: Trying not to inventorize not plugged in FRUs...
diff --git a/checkman/logwatch.ec b/checkman/logwatch.ec
index 7497da2..2e9b120 100644
--- a/checkman/logwatch.ec
+++ b/checkman/logwatch.ec
@@ -22,3 +22,6 @@ parameters (dict): This check works with the following keys:
be configured to use the spooling mechanism of the event console. To configure this,
either
configure {"socket:"} to detect the spooling directory of the local event
console or
{"socket:/path/to/spool/directory"} to configure the path explicit to the
local spool directory.
+
+ {"monitor_logfilelist"}: Set this to {True} if you want to get warned if the
list of logfiles
+ has changed since the last inventory if this check.
diff --git a/checks/logwatch b/checks/logwatch
index 07c8091..d57316e 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -45,9 +45,12 @@ def logwatch_ec_forwarding_enabled(params, item):
return False
-def inventory_logwatch(info, is_logwatch_ec = False):
- inventory = []
- forward_logs = []
+# Splits the number of existing logfiles into
+# forwarded (to ec) and not forwarded. Returns a
+# pair of forwarded and not forwarded logs.
+def logwatch_select_forwarded(info):
+ forwarded_logs = []
+ not_forwarded_logs = []
forward_settings = host_extra_conf(g_hostname,
checkgroup_parameters.get('logwatch_ec', []))
@@ -55,23 +58,24 @@ def inventory_logwatch(info, is_logwatch_ec = False):
line = " ".join(l)
if len(line) > 6 and line[0:3] == "[[[" and line[-3:] ==
"]]]" \
and ':missing' not in line and ':cannotopen' not in line:
- item = line[3:-3]
+ logfile_name = line[3:-3]
- if not forward_settings or forward_settings[0] is None:
- if not is_logwatch_ec:
- inventory.append((item, "", '""'))
- continue
+ # Is forwarding enabled in general?
+ if forward_settings and forward_settings[0] != None:
+ if logwatch_ec_forwarding_enabled(forward_settings[0], logfile_name):
+ forwarded_logs.append(logfile_name)
+ else:
+ not_forwarded_logs.append(logfile_name)
- forward = logwatch_ec_forwarding_enabled(forward_settings[0], item)
- if not is_logwatch_ec and not forward:
- inventory.append((item, "", '""'))
- elif is_logwatch_ec and forward:
- forward_logs.append(item)
+ # No forwarding rule configured
+ else:
+ not_forwarded_logs.append(logfile_name)
- if forward_logs:
- return [(None, '{}')]
+ return forwarded_logs, not_forwarded_logs
- return inventory
+def inventory_logwatch(info):
+ forwarded_logs, not_forwarded_logs = logwatch_select_forwarded(info)
+ return [ (n, None) for n in not_forwarded_logs ]
#logwatch_patterns = {
# 'System': [
@@ -393,9 +397,8 @@ def check_logwatch(item, params, info):
check_info['logwatch'] = {
'check_function': check_logwatch,
+ 'inventory_function': inventory_logwatch,
'service_description': "LOG %s",
- 'has_perfdata': 0,
- 'inventory_function': lambda info: inventory_logwatch(info, False),
'group': 'logwatch',
}
@@ -434,6 +437,11 @@ def syslog_time():
value = time.strftime("%b %%d %H:%M:%S", localtime)
return value % day
+def inventory_logwatch_ec(info):
+ forwarded_logs, not_forwarded_logs = logwatch_select_forwarded(info)
+ if forwarded_logs:
+ return [ (None, { "expected_logfiles": forwarded_logs } ) ]
+
def check_logwatch_ec(item, params, info):
if len(info) == 1:
line = " ".join(info[0])
@@ -461,6 +469,31 @@ def check_logwatch_ec(item, params, info):
if not logwatch_ec_forwarding_enabled(params, logfile):
del logs[logfile]
+ # Check if the number of expected files matches the actual one
+ status = 0
+ infotexts = []
+ if params.get('monitor_logfilelist'):
+ if 'expected_logfiles' not in params:
+ infotexts.append("You enabled monitoring the list of forwarded logfiles.
You need to re-inventorize the check once.")
+ status = 1
+ else:
+ expected = params['expected_logfiles']
+ missing = []
+ for f in expected:
+ if f not in logs:
+ missing.append(f)
+ if missing:
+ infotexts.append("Missing logfiles: %s" % (",
".join(missing)))
+ status = 1
+
+ exceeding = []
+ for f in logs:
+ if f not in expected:
+ exceeding.append(f)
+ if exceeding:
+ infotexts.append("Newly appeared logfiles: %s" % (",
".join(exceeding)))
+ status = 1
+
# 3. create syslog message of each line
# <128> Oct 24 10:44:27 Klappspaten /var/log/syslog: Oct 24 10:44:27
Klappspaten logger: asdasdad as
# <facility+priority> timestamp hostname logfile: message
@@ -526,16 +559,17 @@ def check_logwatch_ec(item, params, info):
logfile_info = " from " +
",".join(list(forwarded_logfiles))
else:
logfile_info = ""
- return (0, 'Forwarded %d messages%s to event console' % (
- num_messages, logfile_info ), [('messages', num_messages)])
+
+ infotexts.append('Forwarded %d messages%s to event console' %
(num_messages, logfile_info))
+ return (status, ", ".join(infotexts), [('messages',
num_messages)])
+
except Exception, e:
return (2, 'Unable to forward messages to event console (%s). Lost %d
messages.' %
(e, num_messages))
check_info['logwatch.ec'] = {
'check_function': check_logwatch_ec,
+ 'inventory_function': inventory_logwatch_ec,
'service_description': "Log Forwarding",
- 'has_perfdata': 0,
- 'inventory_function': lambda info: inventory_logwatch(info, True),
'group': 'logwatch_ec',
}
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index a58bcb1..01f766a 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -4445,6 +4445,16 @@ register_check_parameters(subgroup_applications,
choices = syslog_facilities,
default_value = 17, # local1
)),
+ ('monitor_logfilelist',
+ Checkbox(
+ title = _("Monitoring of forwarded logfiles"),
+ label = _("Warn if list of forwarded logfiles
changes"),
+ help = _("If this option is enabled then the check
monitors the list of forwarded "
+ "logfiles and will warn you if at any time a
logfile is missing or exceeding "
+ "when compared to the initial list that was
snapshotted during service detection. "
+ "Reinventorize this check in order to make it OK
again."),
+ )
+ ),
],
optional_keys = ['restrict_logfiles'],
),