Module: check_mk
Branch: master
Commit: cdc0a13ee70358e6c0b36620d2b2ebb56f274871
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cdc0a13ee70358…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Oct 7 14:03:32 2014 +0200
#1123 Rule based notifications: New condition "Match Service Groups"
---
.werks/1123 | 9 +++++++++
ChangeLog | 1 +
check_mk_templates.cfg | 1 +
modules/notify.py | 26 +++++++++++++++++++++++++-
web/htdocs/wato.py | 21 ++++++++++++++-------
5 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/.werks/1123 b/.werks/1123
new file mode 100644
index 0000000..c856d9d
--- /dev/null
+++ b/.werks/1123
@@ -0,0 +1,9 @@
+Title: Rule based notifications: New condition "Match Service Groups"
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.5i6
+Date: 1412683344
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 6ef12ef..554de9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -141,6 +141,7 @@
* 1151 Add variables (HOST/SERVICE)ACK(AUTHOR/COMMENT) to notification context...
* 1394 HTML notifications have a new content field for debugging variables...
* 1400 Added example notification script for Pushover to doc/treasures/notifications...
+ * 1123 Rule based notifications: New condition "Match Service Groups"
* 1156 FIX: Graphs in HTML mails are now sent again where they where missing...
* 1157 FIX: Fixed SMS plugin on at least debian (distrs which have no sendsms/smssend)...
* 1407 FIX: Fix exception in rule based notification on non-Ascii characters in log message
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index 7cef53f..47bc763 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -397,6 +397,7 @@ define command {
NOTIFY_NOTIFICATIONAUTHORALIAS='$NOTIFICATIONAUTHORALIAS$' \
NOTIFY_SERVICEACKAUTHOR='$SERVICEACKAUTHOR$' \
NOTIFY_SERVICEACKCOMMENT='$SERVICEACKCOMMENT$' \
+ NOTIFY_SERVICEGROUPNAMES='$SERVICEGROUPNAMES$' \
NOTIFY_HOSTACKAUTHOR='$HOSTACKAUTHOR$' \
NOTIFY_HOSTACKCOMMENT='$HOSTACKCOMMENT$' \
NOTIFY_HOSTGROUPNAMES='$HOSTGROUPNAMES$' \
diff --git a/modules/notify.py b/modules/notify.py
index 57b90d9..276b11a 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -626,6 +626,7 @@ def rbn_match_rule(rule, context):
rbn_match_folder(rule, context) or \
rbn_match_hosttags(rule, context) or \
rbn_match_hostgroups(rule, context) or \
+ rbn_match_servicegroups(rule, context) or \
rbn_match_hosts(rule, context) or \
rbn_match_exclude_hosts(rule, context) or \
rbn_match_services(rule, context) or \
@@ -672,6 +673,29 @@ def rbn_match_hosttags(rule, context):
"|".join(tags), "|".join(required))
+def rbn_match_servicegroups(rule, context):
+ if context["WHAT"] != "SERVICE":
+ return
+ required_groups = rule.get("match_servicegroups")
+ if required_groups != None:
+ sgn = context.get("SERVICEGROUPNAMES")
+ if sgn == None:
+ return "No information about service groups is in the context, but service " \
+ "must be in group %s" % ( " or ".join(required_groups))
+ if sgn:
+ servicegroups = sgn.split(",")
+ else:
+ return "The service is in no group, but %s is required" % (
+ " or ".join(required_groups))
+
+ for group in required_groups:
+ if group in servicegroups:
+ return
+
+ return "The service is only in the groups %s, but %s is required" % (
+ sgn, " or ".join(required_groups))
+
+
def rbn_match_hostgroups(rule, context):
required_groups = rule.get("match_hostgroups")
if required_groups != None:
@@ -689,7 +713,7 @@ def rbn_match_hostgroups(rule, context):
if group in hostgroups:
return
- return "The host only is the groups %s, but %s is required" % (
+ return "The host is only in the groups %s, but %s is required" % (
hgn, " or ".join(required_groups))
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ad72b8d..a4cf757 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8114,17 +8114,17 @@ def FolderChoice(**kwargs):
return DropdownChoice(**kwargs)
-class HostgroupChoice(DualListChoice):
- def __init__(self, **kwargs):
+class GroupChoice(DualListChoice):
+ def __init__(self, what, **kwargs):
DualListChoice.__init__(self, **kwargs)
+ self.what = what
self._choices = lambda: self.load_groups()
def load_groups(self):
all_groups = userdb.load_group_information()
- this_group = all_groups.get("host", {})
+ this_group = all_groups.get(self.what, {})
return [ (k, t['alias'] and t['alias'] or k) for (k, t) in this_group.items() ]
-
def vs_notification_bulkby():
return ListChoice(
title = _("Create separate notification bulks based on"),
@@ -8262,7 +8262,7 @@ def vs_notification_rule(userid = None):
title = _("Match Host Tags"))
),
( "match_hostgroups",
- HostgroupChoice(
+ GroupChoice("host",
title = _("Match Host Groups"),
help = _("The host must be in one of the selected host groups"),
allow_empty = False,
@@ -8296,6 +8296,13 @@ def vs_notification_rule(userid = None):
empty_text = _("Please specify at least one service regex. Disable the option if you want to allow all services."),
)
),
+ ( "match_servicegroups",
+ GroupChoice("service",
+ title = _("Match Service Groups"),
+ help = _("The host must be in one of the selected service groups"),
+ allow_empty = False,
+ )
+ ),
( "match_exclude_services",
ListOfStrings(
title = _("Do <b>not</b> match the following services"),
@@ -8546,7 +8553,7 @@ def vs_notification_rule(userid = None):
],
optional_keys = [ "match_folder", "match_hosttags", "match_hostgroups", "match_hosts", "match_exclude_hosts",
- "match_services", "match_exclude_services", "match_plugin_output",
+ "match_services", "match_servicegroups", "match_exclude_services", "match_plugin_output",
"match_timeperiod", "match_escalation", "match_escalation_throttle",
"match_sl", "match_host_event", "match_service_event", "match_ec",
"match_checktype", "bulk", "contact_users", "contact_groups", "contact_emails" ],
@@ -8556,7 +8563,7 @@ def vs_notification_rule(userid = None):
+ contact_headers
+ [
( _("Conditions"), [ "match_folder", "match_hosttags", "match_hostgroups", "match_hosts", "match_exclude_hosts",
- "match_services", "match_exclude_services", "match_plugin_output",
+ "match_services", "match_servicegroups", "match_exclude_services", "match_plugin_output",
"match_checktype", "match_timeperiod",
"match_escalation", "match_escalation_throttle",
"match_sl", "match_host_event", "match_service_event", "match_ec" ] ),
Module: check_mk
Branch: master
Commit: 087b2fd828447ef24d9f3c64b3a9d1b576eb52d1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=087b2fd828447e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 7 10:44:22 2014 +0200
Fix some bugs with edit_dictionary
---
web/htdocs/forms.py | 56 ++++++++++++++++++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 19 deletions(-)
diff --git a/web/htdocs/forms.py b/web/htdocs/forms.py
index b305f42..1c0ae42 100644
--- a/web/htdocs/forms.py
+++ b/web/htdocs/forms.py
@@ -25,7 +25,6 @@
# Boston, MA 02110-1301 USA.
from lib import *
-from valuespec import *
# A input function with the same call syntax as htmllib.textinput()
def input(valuespec, varprefix, defvalue):
@@ -42,33 +41,47 @@ def get_input(valuespec, varprefix):
def edit_dictionary(entries, value, **args):
- return edit_dictionaries(
- [ ("value", Dictionary(title=title, elements=entries)) ],
- { "value" : value },
- **args)
+ result = edit_dictionaries([("value", entries)], value, **args)
+ if result:
+ return result["value"]
+ else:
+ return result
-# Edit a dictionary with several sub-dictionaries
+# Edit a list of several dictionaries. Those can either be dictionary
+# valuespec or just a list of elements. Each entry in dictionaries is
+# a pair of key and either a list of elements or a Dictionary.
def edit_dictionaries(dictionaries, value, focus=None, hover_help=True,
validate=None, buttontext=None, title=None,
buttons = None, method="GET", preview=False,
varprefix="", formname="form", consume_transid = True):
+ # Convert list of entries/dictionaries
+ sections = []
+ for keyname, d in dictionaries:
+ if type(d) == list:
+ sections.append((keyname, title or _("Properties"), d))
+ else:
+ sections.append((keyname, d.title() or title, d._elements)) # valuespec Dictionary
+
new_value = value.copy()
if html.var("filled_in") == formname and html.transaction_valid():
if not preview and consume_transid:
html.check_transaction()
messages = []
- for keyname, dictionary in dictionaries:
+ for keyname, section_title, entries in sections:
new_value[keyname] = {}
- entries = dictionary._elements
for name, vs in entries:
+ if len(sections) == 1:
+ vp = varprefix
+ else:
+ vp = keyname + "_" + varprefix
try:
- v = vs.from_html_vars(keyname + "_" + varprefix + name)
+ v = vs.from_html_vars(vp + name)
vs.validate_value(v, keyname + "_" + varprefix + name)
new_value[keyname][name] = v
except MKUserError, e:
- messages.append("%s: %s" % (vs.title(), e.message))
+ messages.append("%s: %s" % (title, e.message))
html.add_user_error(e.varname, e.message)
if validate and not html.has_user_errors():
@@ -88,25 +101,30 @@ def edit_dictionaries(dictionaries, value, focus=None, hover_help=True,
html.begin_form(formname, method=method)
- for keyname, dictionary in dictionaries:
- header(dictionary.title())
+ for keyname, title, entries in sections:
+ subvalue = value.get(keyname, {})
+ header(title)
first = True
- for name, vs in dictionary._elements:
+ for name, vs in entries:
section(vs.title())
html.help(vs.help())
- if name in value:
- v = value[name]
+ if name in subvalue:
+ v = subvalue[name]
else:
v = vs.default_value()
- vs.render_input(keyname + "_" + varprefix + name, v)
+ if len(sections) == 1:
+ vp = varprefix
+ else:
+ vp = keyname + "_" + varprefix
+ vs.render_input(vp + name, v)
if (not focus and first) or (name == focus):
- vs.set_focus(keyname + "_" + varprefix + name)
+ vs.set_focus(vp + name)
first = False
end()
if buttons:
- for name, title, icon in buttons:
- html.button(name, title)
+ for name, button_title, icon in buttons:
+ html.button(name, button_title)
else:
if buttontext == None:
buttontext = _("Save")