Module: check_mk
Branch: master
Commit: ec21a24facfd34ff362f96f3f02a07225f8cc639
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec21a24facfd34…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 20 16:06:49 2012 +0100
WATO: global host validator
---
web/htdocs/htmllib.py | 5 +++-
web/htdocs/wato.css | 17 +++++++++++-
web/htdocs/wato.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 89 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 58399cd..d045b1b 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -324,9 +324,12 @@ class html:
# self.write("<a href=\"%s\"
class=button%s%s>%s</a>" % (href, obj_id, style, text))
def icon(self, help, icon):
- self.write('<img class=icon title="%s"
src="images/icon_%s.png">' % (
+ self.write('<img align=absmiddle class=icon title="%s"
src="images/icon_%s.png">' % (
help, icon))
+ def empty_icon(self):
+ self.write('<img class=icon src="images/trans.png">')
+
def icon_button(self, url, help, icon):
self.write('<a href="%s">'
'<img class=iconbutton title="%s"
src="images/button_%s_lo.png" '
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index 62de082..296c666 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -199,6 +199,21 @@ Boston, MA 02110-1301 USA.
margin-bottom: 2px;
}
+/* host validation error */
+table.validationerror {
+ width: 100%;
+}
+
+table.validationerror td.img {
+ width: 68px;
+}
+
+table.validationerror img {
+ margin-left: 5px;
+ margin-top: 10px;
+ margin-right: 15px;
+}
+
/* Path to current folder at top of screen */
.wato div.folderpath {
margin-bottom: 10px;
@@ -248,7 +263,7 @@ Boston, MA 02110-1301 USA.
margin-top: 10px;
margin-bottom: 10px;
padding: 5px 8px;
- width: 800px;
+ width: 834px;
-moz-border-radius: 3px;
background-image: url("images/form_background.png");
background-repeat: repeat;
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index a202235..71ecbde 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -1182,7 +1182,15 @@ def show_hosts(folder):
html.write("</td>\n")
# Hostname with link to details page (edit host)
- html.write('<td><a
href="%s">%s</a></td>\n' % (edit_url, hostname))
+ html.write('<td>')
+ errors = validate_host(host)
+ if errors:
+ msg = _("Warning: This host has an invalid configuration: ")
+ msg += ", ".join(errors)
+ html.icon(msg, "validation_error")
+ html.write(" ")
+ html.write('<a href="%s">%s</a></td>\n' %
(edit_url, hostname))
+
# Am I authorized?
auth = check_host_permissions(hostname, False)
@@ -1728,16 +1736,34 @@ def mode_edithost(phase, new):
save_folder_and_hosts(g_folder)
call_hook_hosts_changed(g_folder)
reload_hosts(g_folder)
- if new:
+
+ errors = validate_host(g_folder[".hosts"][hostname])
+ if errors: # keep on this page if host does not validate
+ return
+ elif new:
return go_to_services and "firstinventory" or
"folder"
else:
return go_to_services and "inventory" or "folder"
-
else:
if new:
render_folder_path()
+ # Show outcome of host validation
+ errors = validate_host(host)
+ if errors:
+ html.write("<div class=info>")
+ html.write('<table class=validationerror border=0 cellspacing=0
cellpadding=0><tr><td class=img>')
+ html.write('<img
src="images/icon_validation_error.png"></td><td>')
+
html.write('<p><h3>%s</h3><ul>%s</ul></p>' %
+ (_("Warning: This host has an invalid configuration!"),
+ "".join(["<li>%s</li>" % error for error
in errors])))
+
+ if html.form_submitted():
+ html.write("<br><b>%s</b>" % _("Your
changes have been saved nevertheless."))
+
+ html.write("</td></tr></table></div>")
+
html.begin_form("edithost")
html.write('<table class="form nomargin">\n')
@@ -2643,6 +2669,14 @@ def mode_changelog(phase):
html.context_button(_("Site Configuration"),
make_link([("mode", "sites")]), "sites")
elif phase == "action":
+ defective_hosts = validate_all_hosts()
+ if defective_hosts:
+ raise MKUserError(None, _("You cannot activate changes while some hosts
have "
+ "an invalid configuration: ") + ", ".join(
+ [ '<a href="%s">%s</a>' %
(make_link([("mode", "edithost"), ("host", hn)]), hn)
+ for hn in defective_hosts ]))
+
+
sitestatus_do_async_replication = False # see below
if html.has_var("_siteaction"):
config.need_permission("wato.activate")
@@ -9443,6 +9477,38 @@ def call_hook_roles_saved(roles):
if hook_registered('roles-saved'):
call_hooks("roles-saved", roles)
+# This hook is called in order to determine if a host has a 'valid'
+# configuration. It used used for displaying warning symbols in the
+# host list and in the host detail view.
+def validate_host(host):
+ if hook_registered('validate-host'):
+ errors = []
+ eff = effective_attributes(host, host[".folder"])
+ for hk in g_hooks.get('validate-host', []):
+ try:
+ hk(eff)
+ except MKUserError, e:
+ errors.append(e.message)
+ return errors
+ else:
+ return []
+
+def validate_all_hosts():
+ if hook_registered('validate-host'):
+ hosts = collect_hosts(g_root_folder)
+ defective_hosts = []
+ for hn, eff in hosts.iteritems():
+ for hk in g_hooks.get('validate-host', []):
+ try:
+ hk(eff)
+ except MKUserError, e:
+ defective_hosts.append(hn)
+ break # reason not interesting here
+ defective_hosts.sort()
+ return defective_hosts
+ else:
+ return []
+
#.
# .-Helpers--------------------------------------------------------------.