Module: check_mk
Branch: master
Commit: 29279017fd348a1dec89af7fa47521bccb2b4ac3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=29279017fd348a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 13 12:30:39 2015 +0200
icons and actions now use own config variable
---
modules/check_mk.py | 20 +++++++++--
modules/config.py | 2 ++
web/htdocs/valuespec.py | 19 ++++++++--
web/plugins/wato/check_mk_configuration.py | 52 +++++++++++++---------------
4 files changed, 60 insertions(+), 33 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index e7c3a6f..137b7d0 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1522,6 +1522,14 @@ def host_check_command(hostname, ip, is_clust):
value, hostname))
+def icons_and_actions_of(what, hostname, svcdesc = None):
+ if what == 'host':
+ return list(set(host_extra_conf(hostname, host_icons_and_actions)))
+ else:
+ actions = set(service_extra_conf(hostname, svcdesc, service_icons_and_actions))
+
+ return list(actions)
+
def check_icmp_arguments_of(hostname):
values = host_extra_conf(hostname, ping_levels)
@@ -2094,6 +2102,10 @@ def create_nagios_hostdefs(outfile, hostname):
else:
alias = make_utf8(alias)
+ # Add custom user icons and actions
+ actions = icons_and_actions_of('host', hostname)
+ if actions:
+ outfile.write(" _ACTIONS\t\t\t%s\n" % ','.join(actions))
# Custom configuration last -> user may override all other values
outfile.write(make_utf8(extra_host_conf_of(hostname)))
@@ -2234,16 +2246,20 @@ define servicedependency {
if value is not None:
check_interval = value
+ # Add custom user icons and actions
+ actions = icons_and_actions_of('service', hostname, description)
+ action_cfg = actions and ' _ACTIONS\t\t\t%s\n' %
','.join(actions) or ''
+
outfile.write("""define service {
use\t\t\t\t%s
host_name\t\t\t%s
service_description\t\t%s
check_interval\t\t%d
-%s%s check_command\t\t\tcheck_mk-%s
+%s%s%s check_command\t\t\tcheck_mk-%s
}
""" % ( template, hostname, description, check_interval, logwatch,
- extra_service_conf_of(hostname, description), checkname ))
+ extra_service_conf_of(hostname, description), action_cfg, checkname ))
checknames_to_define.add(checkname)
have_at_least_one_service = True
diff --git a/modules/config.py b/modules/config.py
index 7332004..1aad61d 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -165,6 +165,8 @@ snmp_check_interval = []
inv_exports = {} # Rulesets for inventory export hooks
notification_parameters = {} # Rulesets for parameters of notification
scripts
use_new_descriptions_for = []
+host_icons_and_actions = [] # Custom user icons / actions to be configured
+service_icons_and_actions = [] # Custom user icons / actions to be configured
# Rulesets for agent bakery
agent_config = {}
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 916248f..6945703 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -24,6 +24,13 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+# FIXME: Cleanups
+# - Consolidate ListChoice and DualListChoice to use the same class
+# and rename to better name
+# - Consolidate RadioChoice and DropdownChoice to use same class
+# and rename to better name
+# - Checkbox -> rename to Boolean
+
import math, os, time, re, sre_constants, urlparse, forms
from lib import *
@@ -1175,6 +1182,7 @@ class DropdownChoice(ValueSpec):
self._label = kwargs.get("label")
self._prefix_values = kwargs.get("prefix_values", False)
self._sorted = kwargs.get("sorted", False)
+ self._empty_text = kwargs.get("empty_text", _("There are not
defined any elements for this selection yet."))
self._no_preselect = kwargs.get("no_preselect", False)
self._no_preselect_value = kwargs.get("no_preselect_value", None)
@@ -1213,7 +1221,7 @@ class DropdownChoice(ValueSpec):
if entry[0] == value:
defval = str(n)
if len(options) == 0:
- html.write(_("There are no options to select from"))
+ html.write(self._empty_text)
elif len(options[0]) == 3:
html.icon_select(varprefix, options, defval)
else:
@@ -1247,11 +1255,16 @@ class DropdownChoice(ValueSpec):
ValueSpec.custom_validate(self, value, varprefix)
def validate_datatype(self, value, varprefix):
- for val, title in self.choices():
+ choices = self.choices()
+ if not choices and value == None:
+ return
+
+ for val, title in choices:
if val == value:
return
+
raise MKUserError(varprefix, _("Invalid value %s, must be in %s") %
- (value, ", ".join([v for (v,t) in self.choices()])))
+ (value, ", ".join([v for (v,t) in choices])))
# Special conveniance variant for monitoring states
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 68238d4..5e7b432 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -2232,41 +2232,37 @@ def list_user_icons_and_actions():
choices.append((key, label))
return sorted(choices, key = lambda x: x[1])
+icon_upload_link_txt = \
+ _("In order to be able to choose actions here, you need to "
+ "<a href=\"%s\">define your own actions</a>.") % \
+ "wato.py?mode=edit_configvar&varname=user_icons_and_actions"
register_rule(group,
- "extra_host_conf:_ACTIONS",
- Transform(
- ListChoice(
- title = _("Custom icons or actions for hosts in status GUI"),
- help = _("You can assign icons or actions to hosts for the status GUI.
"
- "In order to be able to choose actions here, you need to
"
- "<a href=\"%s\">define your own
actions</a>.") % \
-
"wato.py?mode=edit_configvar&varname=user_icons_and_actions",
- choices = list_user_icons_and_actions,
- allow_empty = False,
- ),
- forth = lambda x: x.split(','),
- back = lambda x: ','.join(x),
- )
+ "host_icons_and_actions",
+ DropdownChoice(
+ title = _("Custom icons or actions for hosts in status GUI"),
+ help = _("You can assign icons or actions to hosts for the status
GUI.") \
+ + " " + icon_upload_link_txt,
+ choices = list_user_icons_and_actions,
+ allow_empty = False,
+ empty_text = icon_upload_link_txt,
+ ),
+ match = "all",
)
register_rule(group,
- "extra_service_conf:_ACTIONS",
- Transform(
- ListChoice(
- title = _("Custom icons or actions for services in status GUI"),
- help = _("You can assign icons or actions to services for the status
GUI. "
- "In order to be able to choose actions here, you need to
"
- "<a href=\"%s\">define your own
actions</a>.") % \
-
"wato.py?mode=edit_configvar&varname=user_icons_and_actions",
- choices = list_user_icons_and_actions,
- allow_empty = False,
- ),
- forth = lambda x: x.split(','),
- back = lambda x: x.join(','),
+ "service_icons_and_actions",
+ DropdownChoice(
+ title = _("Custom icons or actions for services in status GUI"),
+ help = _("You can assign icons or actions to services for the status
GUI.") \
+ + " " + icon_upload_link_txt,
+ choices = list_user_icons_and_actions,
+ allow_empty = False,
+ empty_text = icon_upload_link_txt,
),
- itemtype = "service"
+ match = "all",
+ itemtype = "service",
)