Module: check_mk
Branch: master
Commit: afb1e0e3115ded4044db31c28b18fba8c6d27273
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=afb1e0e3115ded…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Oct 30 19:21:35 2010 +0200
First start of web configuration
---
web/htdocs/config.py | 10 +++++
web/htdocs/webconf.py | 84 ++++++++++++++++++++++++++++++++++++++++
web/plugins/pages/webconf.py | 5 ++
web/plugins/sidebar/webconf.py | 24 +++++++++++
4 files changed, 123 insertions(+), 0 deletions(-)
diff --git a/web/htdocs/config.py b/web/htdocs/config.py
index 76057d7..170c050 100644
--- a/web/htdocs/config.py
+++ b/web/htdocs/config.py
@@ -403,3 +403,13 @@ custom_style_sheet = None
# URL for start page in main frame (welcome page)
start_url = "main.py"
+
+# __ __ _ __
+# \ \ / /__| |__ ___ ___ _ __ / _|
+# \ \ /\ / / _ \ '_ \ / __/ _ \| '_ \| |_
+# \ V V / __/ |_) | (_| (_) | | | | _|
+# \_/\_/ \___|_.__/ \___\___/|_| |_|_|
+#
+
+config_files = []
+host_tags = []
diff --git a/web/htdocs/webconf.py b/web/htdocs/webconf.py
new file mode 100644
index 0000000..145179b
--- /dev/null
+++ b/web/htdocs/webconf.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+import config, pprint
+from lib import *
+
+config.declare_permission("use_webconf",
+ "Use Webconfiguration",
+ "Only with this permission, users are allowed to use Check_MK web configuration
GUI.",
+ [ "admin", ])
+
+def index(h):
+ global html
+ html = h
+ filename = html.var("filename")
+ if not filename:
+ raise MKGeneralException("You called this page without a filename!")
+ title = None
+ for fn, t, roles in config.config_files:
+ if fn == filename:
+ title = t
+ break
+
+ if not title:
+ raise MKGeneralException("No config file <tt>%s</tt> is declared
in <tt>multisite.mk</tt>" % filename)
+
+ if not config.may("use_webconf") or config.role not in roles:
+ raise MKAuthException("You are not allowed to edit this configuration
file!")
+
+ html.header("Check_MK Configuration: " + title)
+ hosts = read_configuration_file(filename)
+
+ html.write("<table class=services>\n")
+ html.write("<tr><th>Hostname</th><th>IP
Address</th><th>Tags</th></tr>\n")
+ odd = "even"
+ for hostname, ipaddress, tags in hosts:
+ odd = odd == "odd" and "even" or "odd"
+ html.write("<tr class=\"data
%s0\"><td>%s</td>" % (odd, hostname))
+ html.write("<td>%s</td>" % (ipaddress and ipaddress or
"(DNS)"))
+ html.write("<td>%s</td>" % ", ".join(tags))
+ html.write("</tr>\n")
+ html.write("</table>\n")
+
+
+ write_configuration_file(filename, hosts)
+ html.footer()
+
+
+def read_configuration_file(filename):
+ path = defaults.check_mk_configdir + "/" + filename
+
+ if os.path.exists(path):
+ variables = {
+ "all_hosts" : [],
+ "ipaddresses" : {},
+ }
+ execfile(path, variables, variables)
+ hosts = []
+ for h in variables["all_hosts"]:
+ parts = h.split('|')
+ hostname = parts[0]
+ tags = parts[1:]
+ ipaddress = variables["ipaddresses"].get(hostname)
+ hosts.append((hostname, ipaddress, tags))
+ return hosts
+ else:
+ return []
+
+def write_configuration_file(filename, hosts):
+ all_hosts = []
+ ipaddresses = {}
+ for hostname, ipaddress, tags in hosts:
+ all_hosts.append("|".join([hostname] + tags))
+ if ipaddress:
+ ipaddresses[hostname] = ipaddress
+ path = defaults.check_mk_configdir + "/" + filename
+ out = file(path, "w")
+ out.write("# Written by Check_MK Webconf\n\n")
+ if len(all_hosts) > 0:
+ out.write("all_hosts += ")
+ out.write(pprint.pformat(all_hosts))
+ if len(ipaddresses) > 0:
+ out.write("\n\nipaddresses.update(")
+ out.write(pprint.pformat(ipaddresses))
+ out.write(")")
+ out.write("\n")
diff --git a/web/plugins/pages/webconf.py b/web/plugins/pages/webconf.py
new file mode 100644
index 0000000..34cd557
--- /dev/null
+++ b/web/plugins/pages/webconf.py
@@ -0,0 +1,5 @@
+import webconf
+
+pagehandlers.update({
+ "webconf" : webconf.index,
+})
diff --git a/web/plugins/sidebar/webconf.py b/web/plugins/sidebar/webconf.py
new file mode 100644
index 0000000..3b01eb6
--- /dev/null
+++ b/web/plugins/sidebar/webconf.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import config
+
+def render_webconf_files():
+ if not config.may("use_webconf"):
+ html.write("You are not allowed to use Check_MK's web configuration
GUI.")
+ elif len(config.config_files)== 0:
+ html.write("No configuration files are defined. Please set the variable
<tt>config_files</tt> in <tt>multisite.mk</tt>.")
+
+ else:
+ for filename, title, roles in config.config_files:
+ if config.role in roles:
+ bulletlink(title, "webconf.py?filename=%s" % filename)
+
+sidebar_snapins["webconf"] = {
+ "title" : "Check_MK Webconfig",
+ "description" : "Web configuration GUI for Check_MK - manage hosts to
be monitored without access to the command line",
+ "author" : "Mathias Kettner",
+ "render" : render_webconf_files,
+ "allowed" : [ "admin", "user" ],
+}
+
+