Module: check_mk
Branch: master
Commit: 6cf03cd77562d6eb36495ecf7881b6afccc9c1d8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6cf03cd77562d6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Dec 14 14:27:41 2010 +0100
WATO: use and show common pending changes log
---
ChangeLog | 1 +
modules/check_mk.py | 20 +++++++++++++++++---
web/htdocs/wato.py | 49 ++++++++++++++++++++++++++++---------------------
3 files changed, 46 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c4facbc..beec4f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
Multisite:
* WATO: Fixed omd mode/site detection
+ * WATO: Use and show common log for pending changes
* Sidebar Quicksearch: Now really disabling browser built-in completion
dropdown selections
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 5a7ce51..9598889 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3144,8 +3144,8 @@ def do_restart_nagios(only_reload):
process = os.popen(command, "r")
output = process.read()
if process.close():
- sys.stdout.write("ERROR:\n")
- raise MKGeneralException("Cannot re%s Nagios" % action)
+ sys.stdout.write("ERROR: %s\n" % output)
+ raise MKGeneralException("Cannot re%s Nagios: %s" % (action, output))
else:
sys.stdout.write(tty_ok + "\n")
@@ -3506,7 +3506,20 @@ def automation_try_inventory(args):
infotype = ct.split('.')[0]
opt_use_cachefile = True
opt_no_tcp = True
- info = get_host_info(hostname, ipaddress, infotype)
+ try:
+ info = get_host_info(hostname, ipaddress, infotype)
+ # Handle cases where agent does not output data
+ except MKAgentError, e:
+ if str(e) == "":
+ continue
+ else:
+ raise
+ except MKSNMPError, e:
+ if str(e) == "":
+ continue
+ else:
+ raise
+
check_function = check_info[ct][0]
# apply check_parameters
try:
@@ -3706,6 +3719,7 @@ def do_automation(cmd, args):
if opt_debug:
raise
sys.exit(1)
+
except Exception, e:
if opt_debug:
raise
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 0231071..9af1fa1 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -22,8 +22,8 @@ import htmllib
# config = importer.import_module("config")
config.declare_permission("use_wato",
- "Use Webconfiguration",
- "Only with this permission, users are allowed to use Check_MK web configuration
GUI.",
+ "Use WATO",
+ "This permissions allows users to use WATO - Check_MK's Web Administration
Tool. Please make sure, that they also have the permission for the WATO snapin.",
[ "admin", ])
conf_dir = defaults.var_dir + "/wato"
@@ -169,7 +169,7 @@ def mode_index(phase):
if not ipaddress:
try:
ip = socket.gethostbyname(hostname)
- ipaddress = "(DNS: %s)" % ip
+ ipaddress = "%s (DNS)" % ip
tdclass = ' class="dns"'
except:
ipaddress = "(hostname not resolvable!)"
@@ -206,14 +206,19 @@ def host_link(hostname):
return hostname
-def render_audit_log(log, what):
+def render_audit_log(log, what, with_filename = False):
htmlcode = '<table class="wato auditlog %s">'
even = "even"
- for t, user, action, text in log:
+ for t, filename, user, action, text in log:
text = parse_host_names(text)
even = even == "even" and "odd" or "even"
- htmlcode += '<tr
class="%s0"><td>%s</td><td>%s</td><td>%s</td><td
width="100%%">%s</td></tr>\n' % (
- even,
+ htmlcode += '<tr class="%s0">' % even
+ if with_filename:
+ if filename != g_filename:
+ htmlcode += '<td><a
href="wato.py?mode=changelog&filename=%s">%s</a></td>' %
(filename, filename)
+ else:
+ htmlcode += '<td>%s</td>' % filename
+ htmlcode +=
'<td>%s</td><td>%s</td><td>%s</td><td
width="100%%">%s</td></tr>\n' % (
time.strftime("%Y-%m-%d", time.localtime(float(t))),
time.strftime("%H:%M:%S", time.localtime(float(t))),
user,
@@ -241,11 +246,10 @@ def mode_changelog(phase):
return None, "The new configuration has been successfully activated."
else:
-
pending = parse_audit_log("pending")
if len(pending) > 0:
message = "<h1>Changes which are not yet
activated:</h1>"
- message += render_audit_log(pending, "pending")
+ message += render_audit_log(pending, "pending", True)
message += '<a href="%s" class=button>Activate
Changes!</a>' % \
html.makeuri([("_action", "activate"),
("_transid", html.current_transid(html.req.user))])
html.show_warning(message)
@@ -254,7 +258,8 @@ def mode_changelog(phase):
audit = parse_audit_log("audit")
if len(audit) > 0:
- html.write(render_audit_log(audit, "audit"))
+ html.write("<b>Audit log of configuration file
%s</b><br>" % g_filename)
+ html.write(render_audit_log(audit, "audit", False))
else:
html.write("<p>Logfile is empty. No host has been created or
changed yet.</p>")
@@ -453,8 +458,8 @@ def log_entry(hostname, action, message, logfilename):
log_dir = conf_dir + "/" + g_filename
make_nagios_directory(log_dir)
log_file = log_dir + "/" + logfilename
- create_user_file(log_file, "a").write("%d %s %s %s\n" %
- (int(time.time()), html.req.user, action, message))
+ create_user_file(log_file, "a").write("%d %s %s %s %s\n" %
+ (int(time.time()), g_filename, html.req.user, action, message))
def log_audit(hostname, what, message):
@@ -462,22 +467,24 @@ def log_audit(hostname, what, message):
def log_pending(hostname, what, message):
- log_entry(hostname, what, message, "pending.log")
+ log_entry(hostname, what, message, "../pending.log")
log_entry(hostname, what, message, "audit.log")
-
def log_commit_pending():
- pending = conf_dir + "/" + g_filename + "/pending.log"
+ pending = conf_dir + "/pending.log"
if os.path.exists(pending):
os.remove(pending)
def parse_audit_log(what):
- path = "%s/%s/%s.log" % (conf_dir, g_filename, what)
+ if what == "pending":
+ path = "%s/%s.log" % (conf_dir, what)
+ else:
+ path = "%s/%s/%s.log" % (conf_dir, g_filename, what)
if os.path.exists(path):
entries = []
for line in file(path):
line = line.rstrip()
- entries.append(line.split(None, 3))
+ entries.append(line.split(None, 4))
entries.reverse()
return entries
return []
@@ -491,13 +498,13 @@ def check_mk_automation(command, args=[], indata=""):
# - OMD 'shared' apache mode: Full path to the binary and the defaults
if defaults.check_mk_automation:
commandargs = defaults.check_mk_automation.split()
- cmd = commandargs + [ command ] + args
+ cmd = commandargs + [ command ] + args
else:
omd_mode, omd_site = html.omd_mode()
if not omd_mode or omd_mode == 'own':
commandargs = [ 'check_mk', '--automation' ]
cmd = commandargs + [ command ] + args
- else:
+ else: # OMD shared mode
commandargs = [ 'sudo', '/bin/su', '-', omd_site,
'-c', 'check_mk --automation' ]
cmd = commandargs[:-1] + [ commandargs[-1] + ' ' + ' '.join([
command ] + args) ]
@@ -528,8 +535,8 @@ def check_mk_automation(command, args=[], indata=""):
outdata = p.stdout.read()
exitcode = p.wait()
if exitcode != 0:
- raise MKGeneralException("Error running <tt>%s</tt>:
<pre>%s</pre>%s" %
- (" ".join(cmd), outdata, sudo_msg))
+ raise MKGeneralException("Error running <tt>%s</tt> (exit code
%d): <pre>%s</pre>%s" %
+ (" ".join(cmd), exitcode, outdata, sudo_msg))
try:
return eval(outdata)
except Exception, e: