Module: check_mk
Branch: master
Commit: d920f74a52cfa703d5bf30654a800dcdd56ddc0f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d920f74a52cfa7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 13 11:00:28 2017 +0100
4496 The site ID can now be used as match condition
Setting the site ID as condition is now possible to be configured in
notification rules. This is useful for setups where centralized
notifications are used and you want to configured rules depending
on the origin site.
Change-Id: I3a061c5f5ff70ead97d111c5ab254668f2103725
---
.werks/4496 | 14 ++++++++++++++
modules/events.py | 15 +++++++++++++++
web/htdocs/wato.py | 12 ++++++++++--
3 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/.werks/4496 b/.werks/4496
new file mode 100644
index 0000000..3597b9c
--- /dev/null
+++ b/.werks/4496
@@ -0,0 +1,14 @@
+Title: The site ID can now be used as match condition
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1489399160
+Class: feature
+
+Setting the site ID as condition is now possible to be configured in
+notification rules. This is useful for setups where centralized
+notifications are used and you want to configured rules depending
+on the origin site.
+
diff --git a/modules/events.py b/modules/events.py
index 5c617d8..cfa9b8d 100644
--- a/modules/events.py
+++ b/modules/events.py
@@ -349,6 +349,7 @@ def complete_raw_context(raw_context, with_dump, event_log):
def event_match_rule(rule, context):
return \
+ event_match_site(rule, context) or \
event_match_folder(rule, context) or \
event_match_hosttags(rule, context) or \
event_match_hostgroups(rule, context) or \
@@ -368,6 +369,20 @@ def event_match_rule(rule, context):
event_match_servicelevel(rule, context)
+def event_match_site(rule, context):
+ if "match_site" not in rule:
+ return
+
+ required_site_ids = rule["match_site"]
+
+ # Fallback to local site ID in case there is none in the context
+ site_id = context.get("OMD_SITE", omd_site())
+
+ if site_id not in required_site_ids:
+ return "The site '%s' is not in the required sites list: %s" %
\
+ (site_id, ",".join(required_site_ids))
+
+
def event_match_folder(rule, context):
if "match_folder" in rule:
mustfolder = rule["match_folder"]
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 83bd489..8a1cc43 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7492,7 +7492,7 @@ def vs_notification_rule(userid = None):
),
],
- optional_keys = [ "match_folder", "match_hosttags",
"match_hostgroups", "match_hosts", "match_exclude_hosts",
+ optional_keys = [ "match_site", "match_folder",
"match_hosttags", "match_hostgroups", "match_hosts",
"match_exclude_hosts",
"match_servicegroups",
"match_exclude_servicegroups", "match_servicegroups_regex",
"match_exclude_servicegroups_regex",
"match_services",
"match_exclude_services",
"match_contacts", "match_contactgroups",
@@ -7506,7 +7506,7 @@ def vs_notification_rule(userid = None):
( _("Notification Method"), [ "notify_plugin",
"notify_method", "bulk" ] ),]
+ contact_headers
+ [
- ( _("Conditions"), [ "match_folder",
"match_hosttags", "match_hostgroups",
+ ( _("Conditions"), [ "match_site",
"match_folder", "match_hosttags", "match_hostgroups",
"match_hosts",
"match_exclude_hosts", "match_servicegroups",
"match_exclude_servicegroups",
"match_servicegroups_regex", "match_exclude_servicegroups_regex",
"match_services",
"match_exclude_services",
@@ -7524,6 +7524,14 @@ def vs_notification_rule(userid = None):
def simple_host_rule_match_conditions():
return [
+ ( "match_site",
+ DualListChoice(
+ title = _("Match site"),
+ help = _("This condition makes the rule match only notifications that
have been "
+ "created on the selected sites."),
+ choices = config.site_choices,
+ ),
+ ),
( "match_folder",
FolderChoice(
title = _("Match folder"),