Module: check_mk
Branch: master
Commit: d6902c4f9d76eb43a45511ab27598c009cdd1a87
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d6902c4f9d76eb…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Fri Feb 28 13:43:45 2014 +0100
Step2: Using regex for only_hosts in flexible notifications
---
modules/notify.py | 21 ++++++++++++++++++++-
web/htdocs/wato.py | 3 ++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/modules/notify.py b/modules/notify.py
index 3467973..3ccd3a0 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -682,7 +682,26 @@ def should_notify(context, entry):
# Check host, if configured
if entry.get("only_hosts"):
hostname = context.get("HOSTNAME")
- if hostname not in entry["only_hosts"]:
+
+ skip = True
+ regex = False
+ negate = False
+ for h in entry["only_hosts"]:
+ if h.startswith("!"): # negate
+ negate = True
+ h = h[1:]
+ elif h.startswith('~'):
+ regex = True
+ h = h[1:]
+
+ if not regex and hostname == h:
+ skip = negate
+ break
+
+ elif regex and re.match(h, hostname):
+ skip = negate
+ break
+ if skip:
notify_log(" - Skipping: host '%s' matches none of %s" %
(hostname, ", ".join(entry["only_hosts"])))
return False
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index caf0daf..3f118d7 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -10235,7 +10235,8 @@ def load_notification_table():
( "only_hosts",
ListOfStrings(
title = _("Limit to the following
hosts"),
- help = _("Configure the hosts for this
notification. Only exact, case sensitive matches"),
+ help = _("Configure the hosts for this
notification. Without prefix, only exact, case sensitive matches,"
+ "! for negation and ~ for regex
matches " ),
orientation = "horizontal",
valuespec = RegExp(size = 20),
),