Module: check_mk
Branch: master
Commit: 5850073038dc3ded43c6a81c5e3aa9fb96516afe
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5850073038dc3d…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Feb 8 14:31:28 2019 +0100
7059 Add an option to reduce the logging in the notify.log
By default two lines are added for every notification rule in the
notify.log. They contain a short description of the rule and
information why the rule does or does not match. In setups with
a large number of notification rules this may result in up to
hundreds of lines in the notify.log for every incoming raw
notification. To optionally reduce the amount of logging this
werk introduces a new log level that only adds lines for matching
rules. The new option can be selected in the Global Settings under
"Notification log level". Be aware that with this option the
notify.log does not conain information about rules which do not
match which makes it much harder to analyze why a certain rule
did not match retrospectively.
Change-Id: Id8c93e9aadb35c0f7e3c481de1209c344755a0b6
---
.werks/7059 | 21 +++++++++++++++++++++
cmk/gui/plugins/wato/globals_notification.py | 3 ++-
cmk_base/default_config/notify.py | 5 +++--
cmk_base/notify.py | 13 ++++++++++---
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/.werks/7059 b/.werks/7059
new file mode 100644
index 0000000..6f287d8
--- /dev/null
+++ b/.werks/7059
@@ -0,0 +1,21 @@
+Title: Add an option to reduce the logging in the notify.log
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1550494196
+Class: feature
+
+By default two lines are added for every notification rule in the
+notify.log. They contain a short description of the rule and
+information why the rule does or does not match. In setups with
+a large number of notification rules this may result in up to
+hundreds of lines in the notify.log for every incoming raw
+notification. To optionally reduce the amount of logging this
+werk introduces a new log level that only adds lines for matching
+rules. The new option can be selected in the Global Settings under
+"Notification log level". Be aware that with this option the
+notify.log does not conain information about rules which do not
+match which makes it much harder to analyze why a certain rule
+did not match retrospectively.
diff --git a/cmk/gui/plugins/wato/globals_notification.py
b/cmk/gui/plugins/wato/globals_notification.py
index 568e931..1b53317 100644
--- a/cmk/gui/plugins/wato/globals_notification.py
+++ b/cmk/gui/plugins/wato/globals_notification.py
@@ -199,7 +199,8 @@ class ConfigVariableNotificationLogging(ConfigVariable):
return Transform(
DropdownChoice(
choices=[
- (20, _("Normal logging")),
+ (20, _("Minimal logging")),
+ (15, _("Normal logging")),
(10, _("Full dump of all variables and command")),
],),
forth=self._transform_log_level,
diff --git a/cmk_base/default_config/notify.py b/cmk_base/default_config/notify.py
index 8f75cb2..5bc3161 100644
--- a/cmk_base/default_config/notify.py
+++ b/cmk_base/default_config/notify.py
@@ -28,9 +28,10 @@ import cmk as _cmk
# Log level of notifications
# 0, 1, 2 -> deprecated (transformed to 20, 20, and 10)
-# 20 -> normal logging
+# 20 -> minimal logging
+# 15 -> normal logging
# 10 -> full dump of all variables and command
-notification_logging = 20
+notification_logging = 15
notification_backlog = 10 # keep the last 10 notification contexts for reference
# Settings for new rule based notifications
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index 866fba7..f669089 100755
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -428,15 +428,17 @@ def notify_rulebased(raw_context, analyse=False):
for rule in config.notification_rules + user_notification_rules():
if "contact" in rule:
- notify_log("User %s's rule '%s'..." %
(rule["contact"], rule["description"]))
+ contact_info = "User %s's rule '%s'..." %
(rule["contact"], rule["description"])
else:
- notify_log("Global rule '%s'..." %
rule["description"])
+ contact_info = "Global rule '%s'..." %
rule["description"]
why_not = rbn_match_rule(rule, raw_context) # also checks disabling
if why_not:
- notify_log(" -> does not match: %s" % why_not)
+ notify_log_verbose(contact_info)
+ notify_log_verbose(" -> does not match: %s" % why_not)
rule_info.append(("miss", rule, why_not))
else:
+ notify_log(contact_info)
notify_log(" -> matches!")
num_rule_matches += 1
contacts = rbn_rule_contacts(rule, raw_context)
@@ -1915,6 +1917,11 @@ def notify_log(message):
events.event_log(notification_log, message)
+def notify_log_verbose(message):
+ if config.notification_logging <= 15:
+ events.event_log(notification_log, message)
+
+
def notify_log_debug(message):
if config.notification_logging <= 10:
events.event_log(notification_log, message)