Module: check_mk
Branch: master
Commit: cae74dc496842668b600deaa4747714d8a88b024
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cae74dc4968426…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Nov 12 17:12:47 2010 +0100
Editing hosts and restarting Nagios works
---
web/htdocs/.f12 | 3 +
web/htdocs/webconf.py | 111 +++++++++++++++++++++++++++---------------------
web/plugins/pages/.f12 | 2 +
3 files changed, 68 insertions(+), 48 deletions(-)
diff --git a/web/htdocs/.f12 b/web/htdocs/.f12
index 6b5892f..1df668e 100644
--- a/web/htdocs/.f12
+++ b/web/htdocs/.f12
@@ -1,2 +1,5 @@
+#!/bin/bash
+set -e
sudo cp -v *.py /omd/versions/default/share/check_mk/web/htdocs
+sudo cp -v ../plugins/pages/*.py /omd/versions/default/share/check_mk/web/plugins/pages/
sudo omd restart webconf apache
diff --git a/web/htdocs/webconf.py b/web/htdocs/webconf.py
index 6ab4db6..4e5974d 100644
--- a/web/htdocs/webconf.py
+++ b/web/htdocs/webconf.py
@@ -5,7 +5,7 @@ import config
#config = importer.import_module("config", path =
["/omd/sites/webconf/share/check_mk/web/htdocs"])
# config = importer.import_module("config")
-import sys, pprint, socket, re
+import sys, pprint, socket, re, subprocess
from lib import *
import htmllib
# import config
@@ -17,6 +17,49 @@ config.declare_permission("use_webconf",
[ "admin", ])
+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[hostname] = (ipaddress, tags)
+ return hosts
+ else:
+ return {}
+
+def write_configuration_file(filename, hosts):
+ all_hosts = []
+ ipaddresses = {}
+ hostnames = hosts.keys()
+ hostnames.sort()
+ for hostname in hostnames:
+ ipaddress, tags = hosts[hostname]
+ 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")
+
def check_filename():
filename = html.var("filename")
if not filename:
@@ -44,16 +87,22 @@ def page_index(h):
html.header("Check_MK Configuration: " + title)
hosts = read_configuration_file(filename)
+ # Context buttons
+ html.begin_context_buttons()
+ html.context_button("Create new host",
"webconf_edithost.py?filename=" + filename)
+ html.context_button("Activate Changes!",
html.makeuri([("_action", "activate")]))
+ html.end_context_buttons()
+
+ action = html.var("_action")
+ if action == "activate":
+ activate_configuration()
+
# Deletion of entries
delname = html.var("_delete")
if delname and delname in hosts and html.confirm("Do you really want to delete
the host <tt>%s</tt>?" % delname):
del hosts[delname]
write_configuration_file(filename, hosts)
- # Form for creating a new host
- html.begin_context_buttons()
- html.context_button("Create new host",
"webconf_edithost.py?filename=" + filename)
- html.end_context_buttons()
# Show table of hosts in this file
html.write("<table class=services>\n")
@@ -88,49 +137,6 @@ def page_index(h):
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[hostname] = (ipaddress, tags)
- return hosts
- else:
- return {}
-
-def write_configuration_file(filename, hosts):
- all_hosts = []
- ipaddresses = {}
- hostnames = hosts.keys()
- hostnames.sort()
- for hostname in hostnames:
- ipaddress, tags = hosts[hostname]
- 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")
-
def page_edithost(h):
global html
html = h
@@ -233,3 +239,12 @@ def page_edithost(h):
html.hidden_fields()
html.end_form()
html.footer()
+
+def activate_configuration():
+ f = os.popen("check_mk -R 2>&1 >/dev/null")
+ errors = f.read()
+ exitcode = f.close()
+ if exitcode:
+ html.show_error(errors)
+ else:
+ html.message("The new configuration has been successfully activated.")
diff --git a/web/plugins/pages/.f12 b/web/plugins/pages/.f12
new file mode 100644
index 0000000..92ab928
--- /dev/null
+++ b/web/plugins/pages/.f12
@@ -0,0 +1,2 @@
+sudo cp -pv *.py /omd/versions/default/share/check_mk/web/plugins/pages
+sudo omd restart webconf