Module: check_mk
Branch: master
Commit: 09f7eaca27e98f0ba509612906044e30125f1da0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09f7eaca27e98f…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Jun 25 17:38:38 2013 +0200
multsite views: rule editor icon for services
---
ChangeLog | 2 ++
web/htdocs/wato.py | 44 +++++++++++++++++++++-------
web/plugins/icons/builtin.py | 21 +++++++++++++
web/plugins/wato/check_mk_configuration.py | 10 +++++++
4 files changed, 67 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 25abe3d..72e62e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -56,6 +56,8 @@
* Rules: Renamed "Ignored services" to "Disabled services"
Renamed "Ignored checks" to "Disabled checks"
* Sorter Host IP address: fixed sorting, no longer uses str compare on ip
+ * Views: New: Draw rule editor icon in multisite views (default off)
+ Can be activated in global settings
WATO:
* Allow to configure check-/retry_interval in second precision
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 2220a87..380508c 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -10052,7 +10052,7 @@ def mode_rulesets(phase):
html.write('</div>')
-def create_new_rule_form(rulespec, hostname = None, item = None):
+def create_new_rule_form(rulespec, hostname = None, item = None, varname = None):
html.begin_form("new_rule", add_transid = False)
html.write('<table>')
@@ -10077,13 +10077,24 @@ def create_new_rule_form(rulespec, hostname = None, item =
None):
html.select("rule_folder", folder_selection(g_root_folder))
html.write('</td></tr></table>\n')
- html.hidden_field("varname", html.var("varname"))
+ html.hidden_field("varname", varname)
html.hidden_field("mode", "new_rule")
html.end_form()
def mode_edit_ruleset(phase):
varname = html.var("varname")
- rulespec = g_rulespecs[varname]
+
+ if html.var("check_command"):
+ check_command = html.var("check_command")
+ checks = check_mk_local_automation("get-check-information")
+ if check_command.startswith("check_mk-"):
+ check_command = check_command[9:]
+ varname = "checkgroup_parameters:" +
checks[check_command].get("group","")
+ elif check_command.startswith("check_mk_active-"):
+ check_command = check_command[16:].split(" ")[0][:-1]
+ varname = "active_checks:" + check_command
+
+ rulespec = g_rulespecs.get(varname)
hostname = html.var("host", "")
if html.has_var("item"):
item = mk_eval(html.var("item"))
@@ -10097,6 +10108,9 @@ def mode_edit_ruleset(phase):
hostname = None # host not found. Should not happen
if phase == "title":
+ if not rulespec:
+ text = html.var("service_description") or varname
+ return _("No available rule for service %s at host %s") % (text,
hostname)
title = rulespec["title"]
if hostname:
title += _(" for host %s") % hostname
@@ -10106,18 +10120,23 @@ def mode_edit_ruleset(phase):
elif phase == "buttons":
global_buttons()
- group = rulespec["group"].split("/")[0]
- groupname = g_rulegroups[group][0]
- html.context_button(groupname,
- make_link([("mode", "rulesets"), ("group",
group), ("host", hostname)]), "back")
- html.context_button(_("Used Rulesets"),
- make_link([("mode", "rulesets"), ("group",
"used"), ("host", hostname)]), "usedrulesets")
+ if not rulespec:
+ html.context_button(_("All Rulesets"),
make_link([("mode", "ruleeditor")]), "back")
+ else:
+ group = rulespec["group"].split("/")[0]
+ groupname = g_rulegroups[group][0]
+ html.context_button(groupname,
+ make_link([("mode", "rulesets"),
("group", group), ("host", hostname)]), "back")
+ html.context_button(_("Used Rulesets"),
+ make_link([("mode", "rulesets"), ("group",
"used"), ("host", hostname)]), "usedrulesets")
if hostname:
html.context_button(_("Services"),
make_link([("mode", "inventory"), ("host",
hostname)]), "back")
return
elif phase == "action":
+ if not rulespec:
+ return
# Folder for the rule actions is defined by _folder
rule_folder = g_folders[html.var("_folder",
html.var("folder"))]
check_folder_permissions(rule_folder, "write", True)
@@ -10168,6 +10187,11 @@ def mode_edit_ruleset(phase):
_("Changed order of rules in ruleset %s") %
rulespec["title"])
return
+ if not rulespec:
+ text = html.var("service_description") or varname
+ html.write("<div class=info>" + _("There are no rules
availabe for %s.") % text + "</div>")
+ return
+
if not hostname:
render_folder_path(keepvarnames = ["mode", "varname"])
@@ -10335,7 +10359,7 @@ def mode_edit_ruleset(phase):
table.end()
- create_new_rule_form(rulespec, hostname, item)
+ create_new_rule_form(rulespec, hostname, item, varname)
def folder_selection(folder, depth=0):
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 8208221..c87343e 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -115,6 +115,27 @@ multisite_icons.append({
'columns': [ 'active_checks_enabled' ],
'paint': paint_reschedule,
})
+
+
+def paint_rule_editor(what, row, tags, custom_vars):
+ if config.may("wato.rulesets") and config.multisite_draw_ruleicon:
+ if what == 'service':
+ check_command = row["service_check_command"]
+ if check_command.startswith("check_mk-") or \
+ check_command.startswith("check_mk_active-"):
+ url = html.makeuri_contextless( [("mode",
"edit_ruleset"),
+ ("check_command",
row["service_check_command"]),
+ ("service_description",
row["service_description"]),
+ ("host",
row["host_name"])], "wato.py")
+ title = _("Edit rule for %s") % check_command
+ return '<a href="%s"><img title="%s"
class=icon src="images/icon_rulesets.png"></a>' % \
+ (url, title)
+
+multisite_icons.append({
+ 'service_columns': [ 'description', 'check_command',
"host_name" ],
+ 'paint': paint_rule_editor,
+})
+
# +----------------------------------------------------------------------+
# | _ _ _ _ |
# | / \ ___| | ___ __ _____ _| | ___ __| | __ _ ___ |
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 2ae1c3d..96766c6 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -219,6 +219,16 @@ register_configvar(group,
domain = "multisite")
register_configvar(group,
+ "multisite_draw_ruleicon",
+ Checkbox(title = _("Draw WATO rule editor icon for services"),
+ label = _("Draw rule editor icon"),
+ help = _("When enabled a rule editor icon is displayed for each "
+ "service in the multisite views. It is only displayed if the
user "
+ "does have the permission to edit rules"),
+ default_value = False),
+ domain = "multisite")
+
+register_configvar(group,
"wato_max_snapshots",
Integer(title = _("Number of configuration snapshots to keep"),
help = _("Whenever you successfully activate changes a snapshot of the
configuration "