Module: check_mk
Branch: master
Commit: 885c2ba5211dfe9bc65e81d1cddce865741c9f5f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=885c2ba5211dfe…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 6 16:49:57 2014 +0100
RBN: Fix rule anaysis, allow disable bulking by later rule
---
doc/treasures/mknotifyd | 5 -----
modules/notify.py | 13 +++++++------
web/htdocs/wato.py | 31 +++++++++++++++++++++++--------
3 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/doc/treasures/mknotifyd b/doc/treasures/mknotifyd
index b60f791..215c8cb 100755
--- a/doc/treasures/mknotifyd
+++ b/doc/treasures/mknotifyd
@@ -573,8 +573,3 @@ try:
except Exception, e:
bail_out(e)
-
-
-
-
-
diff --git a/modules/notify.py b/modules/notify.py
index f57e5be..058b278 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -216,7 +216,7 @@ def notify_notify(raw_context, analyse=False):
if not also_local:
return
- locally_deliver_raw_context(raw_context, analyse=analyse)
+ return locally_deliver_raw_context(raw_context, analyse=analyse)
# Here we decide which notification implementation we are using.
@@ -239,8 +239,7 @@ def locally_deliver_raw_context(raw_context, analyse=False):
if not contactname or contactname == "check-mk-notify":
# 1. RULE BASE NOTIFICATIONS
notify_log("Preparing rule based notifications")
- notify_rulebased(raw_context, analyse=analyse)
- return
+ return notify_rulebased(raw_context, analyse=analyse)
if analyse:
return # Analysis only possible when rule based notifications are enabled
@@ -283,7 +282,7 @@ def notification_analyse_backlog(nr):
global notify_mode
notify_mode = "replay"
raw_context = raw_context_from_backlog(nr)
- notify_notify(raw_context, analyse=True)
+ return notify_notify(raw_context, analyse=True)
#.
@@ -432,7 +431,7 @@ def notify_rulebased(raw_context, analyse=False):
key = contact, plugin
plugintxt = plugin or "plain email"
if key in notifications:
- locked, method, bulk = notifications[key]
+ locked, method, old_bulk = notifications[key]
if locked and "contact" in rule:
notify_log(" - cannot modify notification of %s via
%s: it is locked" % (contact, plugintxt))
continue
@@ -466,7 +465,9 @@ def notify_rulebased(raw_context, analyse=False):
verb = "would notify"
else:
verb = "notifying"
- notify_log(" * %s %s via %s, parameters: %s" % (verb, contact,
(plugin or "plain email"), ", ".join(params)))
+ notify_log(" * %s %s via %s, parameters: %s, bulk: %s" % (
+ verb, contact, (plugin or "plain email"), params and ",
".join(params) or "(no parameters)",
+ bulk and "yes" or "no"))
plugin_info.append((contact, plugin, params, bulk)) # for analysis
try:
rbn_add_contact_information(raw_context, contact)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index da05672..8c04161 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7735,7 +7735,8 @@ def validate_notification_rule(rule, varprefix):
_("The plain emails currently do not support bulking."))
-def render_notification_rules(rules, userid="", show_title=False,
show_buttons=True, analyse=False, start_nr=0, profilemode=False):
+def render_notification_rules(rules, userid="", show_title=False,
show_buttons=True,
+ analyse=False, start_nr=0, profilemode=False):
if not rules:
html.message(_("You have not created any rules yet."))
@@ -7779,12 +7780,12 @@ def render_notification_rules(rules, userid="",
show_title=False, show_buttons=T
listmode = "notifications"
if show_buttons:
- analyse = html.var("analyse", "")
+ anavar = html.var("analyse", "")
delete_url = make_action_link([("mode", listmode),
("user", userid), ("_delete", nr)])
- top_url = make_action_link([("mode", listmode),
("analyse", analyse), ("user", userid), ("_move", nr),
("_where", 0)])
- bottom_url = make_action_link([("mode", listmode),
("analyse", analyse), ("user", userid), ("_move", nr),
("_where", len(rules)-1)])
- up_url = make_action_link([("mode", listmode),
("analyse", analyse), ("user", userid), ("_move", nr),
("_where", nr-1)])
- down_url = make_action_link([("mode", listmode),
("analyse", analyse), ("user", userid), ("_move", nr),
("_where", nr+1)])
+ top_url = make_action_link([("mode", listmode),
("analyse", anavar), ("user", userid), ("_move", nr),
("_where", 0)])
+ bottom_url = make_action_link([("mode", listmode),
("analyse", anavar), ("user", userid), ("_move", nr),
("_where", len(rules)-1)])
+ up_url = make_action_link([("mode", listmode),
("analyse", anavar), ("user", userid), ("_move", nr),
("_where", nr-1)])
+ down_url = make_action_link([("mode", listmode),
("analyse", anavar), ("user", userid), ("_move", nr),
("_where", nr+1)])
suffix = profilemode and "_p" or ""
edit_url = make_link([("mode", "notification_rule"
+ suffix), ("edit", nr), ("user", userid)])
clone_url = make_link([("mode", "notification_rule"
+ suffix), ("clone", nr), ("user", userid)])
@@ -8027,7 +8028,7 @@ def mode_notifications(phase):
table.end()
# Do analysis
- if html.has_var("analyse"):
+ if html.var("analyse"):
nr = int(html.var("analyse"))
analyse = check_mk_local_automation("notification-analyse", [str(nr)],
None)
else:
@@ -14432,7 +14433,8 @@ def page_user_profile():
def create_sample_config():
if os.path.exists(multisite_dir + "hosttags.mk") \
or os.path.exists(root_dir + "rules.mk") \
- or os.path.exists(root_dir + "groups.mk"):
+ or os.path.exists(root_dir + "groups.mk") \
+ or os.path.exists(root_dir + "notifications.mk"):
return
# A contact group where everyone is member of
@@ -14500,6 +14502,19 @@ def create_sample_config():
save_rulesets(g_root_folder, rulesets)
+ notification_rules = [{
+ 'allow_disable' : True,
+ 'contact_all' : False,
+ 'contact_all_with_email' : False,
+ 'contact_object' : True,
+ 'description' : 'Notify all contacts of a host/service via
HTML email',
+ 'disabled' : False,
+ 'notify_method' : [],
+ 'notify_plugin' : 'mail'
+ }]
+ save_notification_rules(notification_rules)
+
+
# Make sure the host tag attributes are immediately declared!
config.wato_host_tags = wato_host_tags
config.wato_aux_tags = wato_aux_tags