Module: check_mk
Branch: master
Commit: 0ba5421c358245ea8dde7f3d8649dc0528fc2bd1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0ba5421c358245…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Nov 8 16:56:46 2016 +0100
Sync SMTP delivery: better config validation, only enable if mknotifyd is present
---
web/htdocs/valuespec.py | 6 ++
web/plugins/wato/notifications.py | 135 ++++++++++++++++++++------------------
2 files changed, 78 insertions(+), 63 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 45f2fb7..9313257 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1059,6 +1059,7 @@ class ListOfStrings(ValueSpec):
self._vertical = kwargs.get("orientation", "vertical") ==
"vertical"
self._allow_empty = kwargs.get("allow_empty", True)
self._empty_text = kwargs.get("empty_text", "")
+ self._max_entries = kwargs.get("max_entries")
def help(self):
@@ -1136,6 +1137,11 @@ class ListOfStrings(ValueSpec):
else:
msg = _("Please specify at least one value")
raise MKUserError(vp + "_0", msg)
+
+ if self._max_entries != None and len(value) > self._max_entries:
+ raise MKUserError(vp + "_%d" % self._max_entries,
+ _("You can specify at most %d entries") % self._max_entries)
+
if self._valuespec:
for nr, s in enumerate(value):
self._valuespec.validate_value(s, vp + "_%d" % nr)
diff --git a/web/plugins/wato/notifications.py b/web/plugins/wato/notifications.py
index e6abd28..d8e4043 100644
--- a/web/plugins/wato/notifications.py
+++ b/web/plugins/wato/notifications.py
@@ -24,6 +24,68 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+if config.mknotifyd_enabled:
+ smtp_sync_option = [(
+ 'smtp',
+ Dictionary(
+ title = _("Enable synchronous delivery via SMTP"),
+ help = _("Configuring this to have the notification plugin connect
directly to "
+ "the smtp server. This has the advantage of providing better
error "
+ "messages in case of an error but it does require more
configuration "
+ "and is strictly synchronous so we advice use only on
enterprise "
+ "installations using the notification spooler."),
+ elements = [
+ ("smarthosts",
+ ListOfStrings(
+ title = _("Smarthosts"),
+ orientation = "horizontal",
+ max_entries = 2,
+ allow_empty = False,
+ )),
+ ("port",
+ Integer(
+ title = _("Port"),
+ default_value = 25
+ )),
+ ("auth",
+ Dictionary(
+ title = _("Authentication"),
+ elements = [
+ ("method",
+ DropdownChoice(
+ title = _("Authmethod"),
+ choices = [
+ ("plaintext", _("Plaintext"))
+ ]
+ )),
+ ("user",
+ TextAscii(
+ title = _("User")
+ )),
+ ("password",
+ Password(
+ title = _("Password")
+ ))
+ ],
+ optional_keys = []
+ )),
+ ("encryption",
+ DropdownChoice(
+ title = ("Encryption"),
+ choices = [
+ ("ssl_tls", _("SSL/TLS")),
+ ("starttls", _("STARTTLS"))
+ ]
+ )),
+ ],
+ optional_keys = ["auth", "encryption"]
+ )
+ )]
+
+else:
+ smtp_sync_option = []
+
+
register_notification_parameters(
"mail",
Dictionary(
@@ -78,6 +140,14 @@ register_notification_parameters(
default_value = [ "perfdata", "graph",
"abstime", "address", "longoutput" ],
)
),
+ ( "insert_html_section",
+ TextAreaUnicode(
+ title = _("Insert HTML section between body and table"),
+ default_value = "<HTMLTAG>CONTENT</HTMLTAG>",
+ cols = 40,
+ rows = "auto",
+ ),
+ ),
( "url_prefix",
TextAscii(
title = _("URL prefix for links to Check_MK"),
@@ -115,69 +185,8 @@ register_notification_parameters(
title = _("Notification sort order for bulk
notifications"),
default = "oldest_first"
)
- ),
- ('smtp',
- Dictionary(
- title = _("Enable synchronous delivery via SMTP"),
- help = _("Configuring this to have the notification plugin connect
directly to "
- "the smtp server. This has the advantage of providing
better error "
- "messages in case of an error but it does require more
configuration "
- "and is strictly synchronous so we advice use only on
enterprise "
- "installations using the notification spooler."),
- elements = [
- ("smarthosts",
- ListOfStrings(
- title = _("Smarthosts"),
- orientation = "horizontal"
- )),
- ("port",
- Integer(
- title = _("Port"),
- default_value = 25
- )),
- ("auth",
- Dictionary(
- title = _("Authentication"),
- elements = [
- ("method",
- DropdownChoice(
- title = _("Authmethod"),
- choices = [
- ("plaintext", _("Plaintext"))
- ]
- )),
- ("user",
- TextAscii(
- title = _("User")
- )),
- ("password",
- Password(
- title = _("Password")
- ))
- ],
- optional_keys = []
- )),
- ("encryption",
- DropdownChoice(
- title = ("Encryption"),
- choices = [
- ("ssl_tls", _("SSL/TLS")),
- ("starttls", _("STARTTLS"))
- ]
- )),
- ],
- optional_keys = ["auth", "encryption"]
- )
- ),
- ("insert_html_section",
- TextAreaUnicode(
- title = _("Insert HTML section between body and table"),
- default_value = "<HTMLTAG>CONTENT</HTMLTAG>",
- cols = 40,
- rows = "auto",
- ),
- ),
- ]
+ )
+ ] + smtp_sync_option
)
)