Module: check_mk
Branch: master
Commit: 4499a766c8f772470eae290c459ad39245c44896
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4499a766c8f772…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Feb 25 17:51:06 2014 +0100
RBN: all conditions are now implemented
---
check_mk_templates.cfg | 2 ++
modules/notify.py | 65 +++++++++++++++++++++++++++++++++++++++-----
web/htdocs/wato.py | 70 ++++++++++++++++++++++++++----------------------
3 files changed, 98 insertions(+), 39 deletions(-)
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index a6f04d7..1f295b1 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -365,6 +365,7 @@ define command {
NOTIFY_HOSTALIAS='$HOSTALIAS$' \
NOTIFY_HOSTADDRESS='$HOSTADDRESS$' \
NOTIFY_LASTHOSTSTATE='$LASTHOSTSTATE$' \
+ NOTIFY_LASTHOSTSTATEID='$LASTHOSTSTATEID$' \
NOTIFY_LASTHOSTSTATECHANGE='$LASTHOSTSTATECHANGE$' \
NOTIFY_LASTHOSTUP='$LASTHOSTUP$' \
NOTIFY_HOSTSTATE='$HOSTSTATE$' \
@@ -375,6 +376,7 @@ define command {
NOTIFY_LONGHOSTOUTPUT='$LONGHOSTOUTPUT$' \
NOTIFY_SERVICEDESC='$SERVICEDESC$' \
NOTIFY_LASTSERVICESTATE='$LASTSERVICESTATE$' \
+ NOTIFY_LASTSERVICESTATEID='$LASTSERVICESTATEID$' \
NOTIFY_LASTSERVICESTATECHANGE='$LASTSERVICESTATECHANGE$' \
NOTIFY_LASTSERVICEOK='$LASTSERVICEOK$' \
NOTIFY_SERVICESTATE='$SERVICESTATE$' \
diff --git a/modules/notify.py b/modules/notify.py
index 8f39b79..f02c51a 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -896,7 +896,9 @@ def rbn_match_rule(rule, context):
rbn_match_checktype(rule, context) or \
rbn_match_timeperiod(rule) or \
rbn_match_escalation(rule, context) or \
- rbn_match_servicelevel(rule, context)
+ rbn_match_servicelevel(rule, context) or \
+ rbn_match_host_event(rule, context) or \
+ rbn_match_service_event(rule, context)
def rbn_match_hosttags(rule, context):
@@ -930,6 +932,8 @@ def rbn_match_services(rule, context):
"allowed services (%s)" % (service, ",
".join(servicelist))
def rbn_match_exclude_services(rule, context):
+ if context["WHAT"] != "SERVICE":
+ return
excludelist = rule.get("match_exclude_services", [])
service = context["SERVICEDESC"]
if in_extraconf_servicelist(excludelist, service):
@@ -968,14 +972,61 @@ def rbn_match_escalation(rule, context):
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'))
+ if "match_sl" in rule:
+ 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_match_host_event(rule, context):
+ if "match_host_event" in rule:
+ if context["WHAT"] != "HOST":
+ if "match_host_event" not in rule:
+ return "This is a service notification, but the rule just matches
host events"
+ else:
+ return # Let this be handled by match_service_event
+ allowed_events = rule["match_host_event"]
+ state = context["HOSTSTATE"]
+ last_state = context["LASTHOSTSTATE"]
+ events = { "UP" : 'r', "DOWN" : 'd',
"UNREACHABLE" : 'u' }
+ return rbn_match_event(context, state, last_state, events, allowed_events)
+
+
+def rbn_match_service_event(rule, context):
+ if "match_service_event" in rule:
+ if context["WHAT"] != "SERVICE":
+ if "match_host_event" not in rule:
+ return "This is a host notification, but the rule just matches
service events"
+ else:
+ return # Let this be handled by match_host_event
+ allowed_events = rule["match_service_event"]
+ state = context["SERVICESTATE"]
+ last_state = context["LASTSERVICESTATE"]
+ events = { "OK" : 'r', "WARNING" :
'w', "CRITICAL" : 'c', "UNKNOWN" : 'u' }
+ return rbn_match_event(context, state, last_state, events, allowed_events)
+
+def rbn_match_event(context, state, last_state, events, allowed_events):
+ notification_type = context["NOTIFICATIONTYPE"]
+
+ if notification_type == "RECOVERY":
+ event = events.get(last_state, '?') + 'r'
+ elif notification_type in [ "FLAPPINGSTART", "FLAPPINGSTOP",
"FLAPPINGDISABLED" ]:
+ event = 'f'
+ elif notification_type in [ "DOWNTIMESTART", "DOWNTIMEEND",
"DOWNTIMECANCELLED"]:
+ event = 's'
+ elif notification_type == "ACKNOWLEDGEMENT":
+ event = 'x'
else:
- sl = saveint(context.get('HOST_SL'))
+ event = events.get(last_state, '?') + events.get(state, '?')
+
+ if event not in allowed_events:
+ return "Event type '%s' not handled by this rule. Allowed are:
%s" % (
+ event, ", ".join(allowed_events))
- 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):
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 1ff23b7..6670e3b 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7485,45 +7485,51 @@ def vs_notification_rule():
( "match_host_event",
ListChoice(
title = _("Match Host Event Type"),
+ help = _("Select the host event types and transitions this rule
should handle. Note: "
+ "If you activate this option and do
<b>not</b> also specify service event "
+ "types then this rule will never hold for service
notifications!"),
choices = [
- ( 'rd', _("UP") + " ➤ " +
_("DOWN")),
- ( 'dr', _("DOWN") + " ➤ " +
_("UP")),
- ( 'ru', _("UP") + " ➤ " +
_("UNREACHABLE")),
- ( 'du', _("DOWN") + " ➤ " +
_("UNREACHABLE")),
- ( 'ud', _("UNREACHABLE") + " ➤ " +
_("DOWN")),
- ( 'ur', _("UNREACHABLE") + " ➤ " +
_("UP")),
- ( 'f', _("Start or end of flapping state")),
- ( 's', _("Start or end of a scheduled downtime
")),
- ( 'x', _("Acknowledgement of host problem")),
- ],
- default_value = [ 'rd', 'dr', 'f', 's',
'x' ],
+ ( 'rd', _("UP") + " ➤ " +
_("DOWN")),
+ ( 'dr', _("DOWN") + " ➤ " +
_("UP")),
+ ( 'ru', _("UP") + " ➤ " +
_("UNREACHABLE")),
+ ( 'du', _("DOWN") + " ➤ " +
_("UNREACHABLE")),
+ ( 'ud', _("UNREACHABLE") + " ➤ " +
_("DOWN")),
+ ( 'ur', _("UNREACHABLE") + " ➤ " +
_("UP")),
+ ( 'f', _("Start or end of flapping state")),
+ ( 's', _("Start or end of a scheduled downtime
")),
+ ( 'x', _("Acknowledgement of host problem")),
+ ],
+ default_value = [ 'rd', 'dr', 'f',
's', 'x' ],
)
),
( "match_service_event",
ListChoice(
title = _("Match Service Event Type"),
+ help = _("Select the service event types and transitions this
rule should handle. Note: "
+ "If you activate this option and do
<b>not</b> also specify host event "
+ "types then this rule will never hold for host
notifications!"),
choices = [
- ( 'rw', _("OK") + " ➤ " +
_("WARN")),
- ( 'rc', _("OK") + " ➤ " +
_("CRIT")),
- ( 'ru', _("OK") + " ➤ " +
_("UNKNOWN")),
-
- ( 'wr', _("WARN") + " ➤ " +
_("OK")),
- ( 'wc', _("WARN") + " ➤ " +
_("CRIT")),
- ( 'wu', _("WARN") + " ➤ " +
_("UNKNOWN")),
-
- ( 'cr', _("CRIT") + " ➤ " +
_("OK")),
- ( 'cw', _("CRIT") + " ➤ " +
_("WARN")),
- ( 'cu', _("CRIT") + " ➤ " +
_("UNKNOWN")),
-
- ( 'ur', _("UNKNOWN") + " ➤ " +
_("OK")),
- ( 'uw', _("UNKNOWN") + " ➤ " +
_("WARN")),
- ( 'uc', _("UNKNOWN") + " ➤ " +
_("CRIT")),
-
- ( 'f', _("Start or end of flapping state")),
- ( 's', _("Start or end of a scheduled downtime")),
- ( 'x', _("Acknowledgement of service problem")),
- ],
- default_value = [ 'rw', 'rc', 'ru', 'wc',
'wu', 'uc', 'f', 's', 'x' ],
+ ( 'rw', _("OK") + " ➤ " +
_("WARN")),
+ ( 'rc', _("OK") + " ➤ " +
_("CRIT")),
+ ( 'ru', _("OK") + " ➤ " +
_("UNKNOWN")),
+
+ ( 'wr', _("WARN") + " ➤ " +
_("OK")),
+ ( 'wc', _("WARN") + " ➤ " +
_("CRIT")),
+ ( 'wu', _("WARN") + " ➤ " +
_("UNKNOWN")),
+
+ ( 'cr', _("CRIT") + " ➤ " +
_("OK")),
+ ( 'cw', _("CRIT") + " ➤ " +
_("WARN")),
+ ( 'cu', _("CRIT") + " ➤ " +
_("UNKNOWN")),
+
+ ( 'ur', _("UNKNOWN") + " ➤ " +
_("OK")),
+ ( 'uw', _("UNKNOWN") + " ➤ " +
_("WARN")),
+ ( 'uc', _("UNKNOWN") + " ➤ " +
_("CRIT")),
+
+ ( 'f', _("Start or end of flapping state")),
+ ( 's', _("Start or end of a scheduled
downtime")),
+ ( 'x', _("Acknowledgement of service
problem")),
+ ],
+ default_value = [ 'rw', 'rc', 'ru',
'wc', 'wu', 'uc', 'f', 's', 'x' ],
)
),