to URL prefix option
Message-ID: <59774145.jJ8imXmrg4WBOz98%si(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: d4ed3b1c45f38a346e6b53680b90b9bbb3795ec9
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d4ed3b1c45f38a…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jul 7 09:26:49 2017 +0200
4886 HTML mail notification: Added choices 'Automatic HTTP/s' to URL prefix option
Change-Id: I21886f118289a8ad390495b232a10626c9adf959
---
.werks/4886 | 15 ++++++++++
notifications/mail | 7 +++++
web/plugins/wato/notifications.py | 62 ++++++++++++++++++++++++++++++---------
3 files changed, 70 insertions(+), 14 deletions(-)
diff --git a/.werks/4886 b/.werks/4886
new file mode 100644
index 0000000..a44f42d
--- /dev/null
+++ b/.werks/4886
@@ -0,0 +1,15 @@
+Title: HTML mail notification: Added choices 'Automatic HTTP/s' to URL prefix option
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1499412075
+Class: feature
+
+URL prefixes are used for hyperlinks to Check_MK GUI so that
+the recipient of the email can directly visit the host or
+service in question in Check_MK.
+These two new choices specify the URL prefix automatically.
+If you're using more than one site this may be helpful in
+order to avoid configuration of separate rules for each site.
diff --git a/notifications/mail b/notifications/mail
index d2b62ae..6844fc2 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -779,6 +779,12 @@ def construct_content(context):
url_prefix = context["PARAMETER_2"]
elif context.get("PARAMETER_URL_PREFIX"):
url_prefix = context["PARAMETER_URL_PREFIX"]
+ elif context.get("PARAMETER_URL_PREFIX_MANUAL"):
+ url_prefix = context["PARAMETER_URL_PREFIX_MANUAL"]
+ elif context.get("PARAMETER_URL_PREFIX_AUTOMATIC") == "http":
+ url_prefix = "http://%s/%s" % (context["MONITORING_HOST"], context["OMD_SITE"])
+ elif context.get("PARAMETER_URL_PREFIX_AUTOMATIC") == "https":
+ url_prefix = "https://%s/%s" % (context["MONITORING_HOST"], context["OMD_SITE"])
else:
url_prefix = None
@@ -795,6 +801,7 @@ def construct_content(context):
service_url = base_url + context['SERVICEURL']
context['LINKEDSERVICEDESC'] = '<a href="%s">%s</a>' % (service_url, context['SERVICEDESC'])
context['SERVICELINK'] = '\nLink: %s' % service_url
+
else:
context['LINKEDHOSTNAME'] = context['HOSTNAME']
context['LINKEDSERVICEDESC'] = context.get('SERVICEDESC', '')
diff --git a/web/plugins/wato/notifications.py b/web/plugins/wato/notifications.py
index 213ac10..6f54ced 100644
--- a/web/plugins/wato/notifications.py
+++ b/web/plugins/wato/notifications.py
@@ -24,6 +24,28 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+# We have to transform because 'add_to_event_context'
+# in modules/events.py can't handle complex data structures
+def transform_back_html_mail_url_prefix(p):
+ if type(p) == tuple:
+ return {p[0]: p[1]}
+ elif p == "automatic_http":
+ return {"automatic": "http"}
+ elif p == "automatic_https":
+ return {"automatic": "https"}
+ else:
+ return {"manual": p}
+
+def transform_forth_html_mail_url_prefix(p):
+ if type(p) == dict:
+ k, v = p.items()[0]
+ if k == "automatic":
+ return "%s_%s" % (k, v)
+ else:
+ return ("manual", p)
+ else:
+ return ("manual", p)
+
def html_email_parameter_elements():
elements = [
( "from",
@@ -87,20 +109,32 @@ def html_email_parameter_elements():
),
),
( "url_prefix",
- TextAscii(
- title = _("URL prefix for links to Check_MK"),
- help = _("If you specify an URL prefix here, then several parts of the "
- "email body are armed with hyperlinks to your Check_MK GUI, so "
- "that the recipient of the email can directly visit the host or "
- "service in question in Check_MK. Specify an absolute URL including "
- "the <tt>.../check_mk/</tt>"),
- regex = "^(http|https)://.*/check_mk/$",
- regex_error = _("The URL must begin with <tt>http</tt> or "
- "<tt>https</tt> and end with <tt>/check_mk/</tt>."),
- size = 64,
- default_value = "http://" + socket.gethostname() + "/" + (
- config.omd_site() and config.omd_site() + "/" or "") + "check_mk/",
- )
+ Transform(CascadingDropdown(
+ style="dropdown",
+ title=_("URL prefix for links to Check_MK"),
+ help=_("If you use <b>Automatic HTTP/s</b> the URL prefix for "
+ "host and service links within the notification mail "
+ "is filled automatically. "
+ "If you specify an URL prefix here, then several parts of the "
+ "email body are armed with hyperlinks to your Check_MK GUI. In both cases "
+ "the recipient of the email can directly visit the host or "
+ "service in question in Check_MK. Specify an absolute URL including "
+ "the <tt>.../check_mk/</tt>"),
+ choices=[
+ ("automatic_http", _("Automatic HTTP")),
+ ("automatic_https", _("Automatic HTTPs")),
+ ("manual", _("Specify URL prefix"), TextAscii(
+ regex = "^(http|https)://.*/check_mk/$",
+ regex_error = _("The URL must begin with <tt>http</tt> or "
+ "<tt>https</tt> and end with <tt>/check_mk/</tt>."),
+ size = 64,
+ default_value = "http://" + socket.gethostname() + "/" + (
+ config.omd_site() and config.omd_site() + "/" or "") + "check_mk/",
+ )),
+ ],
+ default_value=html.is_ssl_request() and "automatic_https" or "automatic_http",
+ ), forth=transform_forth_html_mail_url_prefix,
+ back=transform_back_html_mail_url_prefix)
),
( "no_floating_graphs",
FixedValue(