Module: check_mk
Branch: master
Commit: 755595451c05e075eb046903671ae10c88d60c1f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=755595451c05e0…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Feb 25 16:52:37 2014 +0100
RBN: Implement further conditions
---
modules/notify.py | 31 ++++++++++++++++++++++++-------
web/htdocs/wato.py | 8 +++++---
2 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/modules/notify.py b/modules/notify.py
index 97acb51..8f39b79 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -339,10 +339,6 @@ def notify_keepalive():
global g_inactive_timerperiods
g_inactive_timerperiods = None
- # Invalidate timeperiod cache
- global g_inactive_timerperiods
- g_inactive_timerperiods = None
-
# If the configuration has changed, we do a restart. But we do
# this check just before the next notification arrives. We must
# *not* read data from stdin, just peek! There is still one
@@ -840,8 +836,6 @@ def format_exception():
# '----------------------------------------------------------------------'
def notify_rulebased(context):
- notify_log("RBN2!")
-
# First step: go through all rules and construct our table of
# notification plugins to call. This is a dict from (user, plugin) to
# a pair if (locked, parameters). If locked is True, then a user
@@ -900,7 +894,9 @@ def rbn_match_rule(rule, context):
rbn_match_services(rule, context) or \
rbn_match_exclude_services(rule, context) or \
rbn_match_checktype(rule, context) or \
- rbn_match_timeperiod(rule)
+ rbn_match_timeperiod(rule) or \
+ rbn_match_escalation(rule, context) or \
+ rbn_match_servicelevel(rule, context)
def rbn_match_hosttags(rule, context):
@@ -960,6 +956,27 @@ def rbn_match_timeperiod(rule):
return "The timeperiod '%s' is currently not active." %
timeperiod
+def rbn_match_escalation(rule, context):
+ if "match_escalation" in rule:
+ from_number, to_number = rule["match_escalation"]
+ if context["WHAT"] == "HOST":
+ notification_number = int(context.get("HOSTNOTIFICATIONNUMBER",
1))
+ else:
+ notification_number = int(context.get("SERVICENOTIFICATIONNUMBER",
1))
+ if notification_number < from_number or notification_number > to_number:
+ return "The notification number %d does not lie in range %d ... %d"
% (
+ notification_number, from_number, to_number)
+
+def rbn_match_servicelevel(rule, context):
+ from_sl, to_sl = rule["match_sl"]
+ if context['WHAT'] == "SERVICE" and
context.get('SVC_SL','').isdigit():
+ sl = saveint(context.get('SVC_SL'))
+ else:
+ sl = saveint(context.get('HOST_SL'))
+
+ if sl < from_sl or sl > to_sl:
+ return "The service level %d is not between %d and %d." % (sl, from_sl,
to_sl)
+
def rbn_rule_contacts(rule, context):
contacts = set([])
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index da4f276..1ff23b7 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7453,9 +7453,11 @@ def vs_notification_rule():
elements = [
Integer(
label = _("from"),
- help = _("Let through notifications counting from this
number"),
- default_value = 1,
- minvalue = 1,
+ help = _("Let through notifications counting from this
number. "
+ "For normal alerts The first notification has the
number 1. "
+ "For custom notifications the number is
0."),
+ default_value = 0,
+ minvalue = 0,
maxvalue = 999999,
),
Integer(