Module: check_mk
Branch: master
Commit: a4443cd72ef6bff7af26ba3126ae327cb73e4d7b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a4443cd72ef6bf…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Jul 3 11:02:27 2014 +0200
Rule based notifications: allow matching on host groups
In the rule based notifications you can now use host group membership
for matching. It is allowed to select severel groups at once, one of
which the host must be member of.
---
.werks/1042 | 10 ++++++++++
ChangeLog | 3 +++
check_mk_templates.cfg | 1 +
modules/notify.py | 22 ++++++++++++++++++++++
web/htdocs/valuespec.py | 4 ++++
web/htdocs/wato.py | 25 ++++++++++++++++++++-----
6 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/.werks/1042 b/.werks/1042
new file mode 100644
index 0000000..1ab41e6
--- /dev/null
+++ b/.werks/1042
@@ -0,0 +1,10 @@
+Title: Rule based notifications: allow matching on host groups
+Level: 2
+Component: notifications
+Version: 1.2.5i5
+Date: 1404378080
+Class: feature
+
+In the rule based notifications you can now use host group membership
+for matching. It is allowed to select severel groups at once, one of
+which the host must be member of.
diff --git a/ChangeLog b/ChangeLog
index 0d6e465..0f2e3e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -42,6 +42,9 @@
* 0947 FIX: WATO snapshots: fixed missing files on restoring nagvis backup domains
* 0826 FIX: Fixed problem where user access times were not updated correctly
+ Notifications:
+ * 1042 Rule based notifications: allow matching on host groups...
+
Reporting & Availability:
* 0991 FIX: Availability: optionally show time stamps as UNIX epoch time...
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index 406fc57..117cd50 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -395,6 +395,7 @@ define command {
NOTIFY_NOTIFICATIONAUTHOR='$NOTIFICATIONAUTHOR$' \
NOTIFY_NOTIFICATIONAUTHORNAME='$NOTIFICATIONAUTHORNAME$' \
NOTIFY_NOTIFICATIONAUTHORALIAS='$NOTIFICATIONAUTHORALIAS$' \
+ NOTIFY_HOSTGROUPNAMES='$HOSTGROUPNAMES$' \
NOTIFY_HOSTTAGS='$_HOSTTAGS$' \
NOTIFY_HOST_SL='$_HOSTEC_SL$' \
NOTIFY_SVC_SL='$_SERVICEEC_SL$' \
diff --git a/modules/notify.py b/modules/notify.py
index b39c8da..d9db00e 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -617,6 +617,7 @@ def rbn_match_rule(rule, context):
return \
rbn_match_folder(rule, context) or \
rbn_match_hosttags(rule, context) or \
+ rbn_match_hostgroups(rule, context) or \
rbn_match_hosts(rule, context) or \
rbn_match_exclude_hosts(rule, context) or \
rbn_match_services(rule, context) or \
@@ -662,6 +663,27 @@ def rbn_match_hosttags(rule, context):
"|".join(tags), "|".join(required))
+def rbn_match_hostgroups(rule, context):
+ required_groups = rule.get("match_hostgroups")
+ if required_groups != None:
+ hgn = context.get("HOSTGROUPNAMES")
+ if hgn == None:
+ return "No information about host groups is in the context, but host
" \
+ "must be in group %s" % ( " or
".join(required_groups))
+ if hgn:
+ hostgroups = hgn.split(",")
+ else:
+ return "The host is in no group, but %s is required" % (
+ " or ".join(required_groups))
+
+ for group in required_groups:
+ if group in hostgroups:
+ return
+
+ return "The host only is the groups %s, but %s is required" % (
+ hgn, " or ".join(required_groups))
+
+
def rbn_match_hosts(rule, context):
if "match_hosts" in rule:
hostlist = rule["match_hosts"]
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index c3997b5..cbd72f5 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1372,6 +1372,10 @@ class DualListChoice(ListChoice):
def render_input(self, varprefix, value):
self.load_elements()
+ if not self._elements:
+ html.write(_("There are no elements for selection."))
+ return
+
selected = []
unselected = []
if self._custom_order:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index d8ac8ca..4fb4a60 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8057,6 +8057,17 @@ def FolderChoice(**kwargs):
return DropdownChoice(**kwargs)
+class HostgroupChoice(DualListChoice):
+ def __init__(self, **kwargs):
+ DualListChoice.__init__(self, **kwargs)
+ self._choices = lambda: self.load_groups()
+
+ def load_groups(self):
+ all_groups = userdb.load_group_information()
+ this_group = all_groups.get("host", {})
+ return [ (k, t and t or k) for (k, t) in this_group.items() ]
+
+
def vs_notification_bulkby():
return ListChoice(
title = _("Create separate notification bulks based on"),
@@ -8193,6 +8204,13 @@ def vs_notification_rule(userid = None):
HostTagCondition(
title = _("Match Host Tags"))
),
+ ( "match_hostgroups",
+ HostgroupChoice(
+ title = _("Match Host Groups"),
+ help = _("The host must be in one of the selected host
groups"),
+ allow_empty = False,
+ )
+ ),
( "match_hosts",
ListOfStrings(
title = _("Match only the following hosts"),
@@ -8423,7 +8441,7 @@ def vs_notification_rule(userid = None):
),
],
- optional_keys = [ "match_folder", "match_hosttags",
"match_hosts", "match_exclude_hosts",
+ optional_keys = [ "match_folder", "match_hosttags",
"match_hostgroups", "match_hosts", "match_exclude_hosts",
"match_services", "match_exclude_services",
"match_plugin_output",
"match_timeperiod", "match_escalation",
"match_escalation_throttle",
"match_sl", "match_host_event",
"match_service_event",
@@ -8433,7 +8451,7 @@ def vs_notification_rule(userid = None):
( _("Notification Method"), [ "notify_plugin",
"notify_method", "bulk" ] ),]
+ contact_headers
+ [
- ( _("Conditions"), [ "match_folder",
"match_hosttags", "match_hosts", "match_exclude_hosts",
+ ( _("Conditions"), [ "match_folder",
"match_hosttags", "match_hostgroups", "match_hosts",
"match_exclude_hosts",
"match_services",
"match_exclude_services", "match_plugin_output",
"match_checktype",
"match_timeperiod",
"match_escalation",
"match_escalation_throttle",
@@ -15791,8 +15809,6 @@ class HostTagCondition(ValueSpec):
raise MKUserError(varprefix, _("The list of host tags must only
contain strings "
"but also contains %r") % x)
-
-
def validate_value(self, value, varprefix):
pass
@@ -15800,7 +15816,6 @@ class HostTagCondition(ValueSpec):
-
# We need to replace the BI constants internally with something
# that we can replace back after writing the BI-Rules out
# with pprint.pformat