Skip to content
Permalink
Browse files

icons and actions now use own config variable

  • Loading branch information
LarsMichelsen committed Apr 13, 2015
1 parent 32584a8 commit 29279017fd348a1dec89af7fa47521bccb2b4ac3
Showing with 60 additions and 33 deletions.
  1. +18 −2 modules/check_mk.py
  2. +2 −0 modules/config.py
  3. +16 −3 web/htdocs/valuespec.py
  4. +24 −28 web/plugins/wato/check_mk_configuration.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 @@ def get_dependencies(hostname,servicedesc):
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
@@ -165,6 +165,8 @@
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 = {}
@@ -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 @@ def __init__(self, **kwargs):
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 @@ def render_input(self, varprefix, value):
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 @@ def validate_value(self, value, varprefix):
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
@@ -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",
)


0 comments on commit 2927901

Please sign in to comment.
You can’t perform that action at this time.