Module: check_mk
Branch: master
Commit: fab7a6bd48037af64fa036d9b43bcad239ae35df
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fab7a6bd48037a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 22 14:40:39 2012 +0100
Logwatch: Added buttons to acknowledge all logs of a host or really all problematic logs
in a site
---
ChangeLog | 2 +
web/htdocs/logwatch.py | 116 ++++++++++++++++++++++++++++++++----------------
2 files changed, 79 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7465922..8bec320 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,8 @@
* Restructured cookie auth cookies (all auth cookies will be invalid
after update -> all users have to login again)
* Modularized login and cookie validation
+ * Logwatch: Added buttons to acknowledge all logs of all hosts or really
+ all logs which currently have a problem
WATO:
* FIX: Fixed generated manual check definitions for checks without items
diff --git a/web/htdocs/logwatch.py b/web/htdocs/logwatch.py
index 9c6a518..4b5c998 100644
--- a/web/htdocs/logwatch.py
+++ b/web/htdocs/logwatch.py
@@ -56,6 +56,16 @@ def level_state(level):
def page_show():
host = html.var('host')
filename = html.var('file')
+
+ # Acknowledging logs is supported on
+ # a) all logs on all hosts
+ # b) all logs on one host
+ # c) one log on one host
+ if html.has_var('_ack') and not html.var("_do_actions") ==
_("No"):
+ html.live.set_auth_domain('action')
+ do_log_ack(host, filename)
+ return
+
if not host:
show_log_list()
return
@@ -65,11 +75,7 @@ def page_show():
raise MKAuthException(_("You are not allowed to access the logs of the host
%s") % htmllib.attrencode(host))
if filename:
- if html.has_var('_ack') and not html.var("_do_actions") ==
_("No"):
- html.live.set_auth_domain('action')
- do_log_ack(host, filename)
- else:
- show_file(host, filename)
+ show_file(host, filename)
else:
show_host_log_list(host)
@@ -79,11 +85,13 @@ def show_log_list():
html.begin_context_buttons()
html.context_button(_("Analyze Patterns"),
"%swato.py?mode=pattern_editor" % html.var('master_url', ''),
'analyze')
+ ack_button()
html.end_context_buttons()
html.write("<table class=data>\n")
for host, logs in all_logs():
- html.write('<tr><td
colspan=2><h2>%s</h2></td></tr>' % host)
+ html.write('<tr><td colspan=2><h2><a
href="%s">%s</a></h2></td></tr>' % \
+ (html.makeuri([('host', host)]),
host))
list_logs(host, logs)
html.write("</table>\n")
@@ -99,6 +107,7 @@ def show_host_log_list(host):
html.context_button(_("All Logfiles"), html.makeuri([('host',
''), ('file', '')]))
html.context_button(_("Analyze Host Patterns"),
"%swato.py?mode=pattern_editor&host=%s" %
(master_url, htmllib.urlencode(host)),
'analyze')
+ ack_button(host)
html.end_context_buttons()
html.write("<table class=data>\n")
@@ -142,6 +151,18 @@ def list_logs(host, logfiles):
html.write('<tr><td colspan=4>'+_('No logs found for this
host.')+'</td></tr>\n')
+def ack_button(host = None, int_filename = None):
+ if not config.may("general.act") or (host and not may_see(host)):
+ return
+
+ if int_filename:
+ label = _("Clear Log")
+ else:
+ label = _("Clear Logs")
+
+ html.context_button(label, html.makeuri([('_ack', '1')]),
'delete')
+
+
def show_file(host, filename):
master_url = html.var('master_url', '')
@@ -176,13 +197,7 @@ def show_file(host, filename):
html.footer()
return
- if config.may("general.act") and may_see(host):
- html.context_button(
- _("Clear Log"),
- html.makeuri([('_ack', '1')]),
- 'delete'
- )
-
+ ack_button(host, int_filename)
html.context_button(hide_context_label, html.makeuri([('_hidecontext',
hide_context_param)]))
html.end_context_buttons()
@@ -214,22 +229,44 @@ def show_file(host, filename):
def do_log_ack(host, filename):
- file = form_file_to_int(filename)
- file_display = form_file_to_ext(file)
- html.header(_("Acknowledge Logfile %s - %s") % (htmllib.attrencode(host),
file_display), stylesheets = stylesheets)
+ todo = []
+ if not host and not filename: # all logs on all hosts
+ for this_host, logs in all_logs():
+ for int_filename in logs:
+ file_display = form_file_to_ext(int_filename)
+ todo.append((this_host, int_filename, file_display))
+ ack_msg = _('all logfiles on all hosts')
+
+ elif host and not filename: # all logs on one host
+ for int_filename in host_logs(host):
+ file_display = form_file_to_ext(int_filename)
+ todo.append((host, int_filename, file_display))
+ ack_msg = _('all logfiles of host <tt>%s</tt>') %
htmllib.attrencode(host)
+
+ elif host and filename: # one log on one host
+ int_filename = form_file_to_int(filename)
+ todo = [ (host, int_filename, form_file_to_ext(int_filename)) ]
+ ack_msg = _('the log file <tt>%s</tt> on host
<tt>%s</tt>') % \
+ (htmllib.attrencode(filename), htmllib.attrencode(host))
+
+ html.header(_("Acknowledge %s") % ack_msg, stylesheets = stylesheets)
html.begin_context_buttons()
- html.context_button(_("All Logfiles of Host"),
html.makeuri([('file', '')]))
+ html.context_button(_("All Logfiles"), html.makeuri([('host',
''), ('file', '')]))
+ if host:
+ html.context_button(_("All Logfiles of Host"),
html.makeuri([('file', '')]))
+ if host and filename:
+ html.context_button(_("Back to Logfile"), html.makeuri([]))
html.end_context_buttons()
- ack = html.var('_ack')
- if not html.confirm(_("Do you really want to acknowledge the log file
<tt>%s</tt> by <b>deleting</b> all stored messages?") %
filename):
+ ack = html.var('_ack')
+ if not html.confirm(_("Do you really want to acknowledge %s by
<b>deleting</b> all stored messages?") % ack_msg):
html.footer()
return
- if not (config.may("general.act") and may_see(host)):
+ if not config.may("general.act"):
html.write("<h1 class=error>"+_('Permission
denied')+"</h1>\n")
- html.write("<div class=error>" + _('You are not allowed to
acknowledge the logs of the host %s</div>') % htmllib.attrencode(host))
+ html.write("<div class=error>" + _('You are not allowed to
acknowledge %s</div>') % ack_msg)
html.footer()
return
@@ -237,18 +274,19 @@ def do_log_ack(host, filename):
if ack != '1':
raise MKUserError('_ack', _('Invalid value for ack parameter.'))
- try:
- os.remove(defaults.logwatch_dir + '/' + host + '/' + file)
-
- message = '<b>'+_('%s: %s Acknowledged') %
(htmllib.attrencode(host), htmllib.attrencode(file_display))
+'</b><br>'
- message += '<p>'
- message += _('The log messages from host "%s" in file
"%s" have been acknowledged.') % \
- (htmllib.attrencode(host),
htmllib.attrencode(file_display))
- message += '</p>'
- html.message(message)
- except Exception, e:
- html.show_error(_('The log file "%s" from host
"%s" could not be deleted: %s.') % \
- (htmllib.attrencode(file_display),
htmllib.attrencode(host), e))
+ for this_host, int_filename, display_name in todo:
+ try:
+ if not may_see(this_host):
+ raise MKAuthException(_('Permission denied.'))
+ os.remove(defaults.logwatch_dir + '/' + this_host + '/' +
int_filename)
+ except Exception, e:
+ html.show_error(_('The log file <tt>%s</tt> of host
<tt>%s</tt> could not be deleted: %s.') % \
+ (htmllib.attrencode(file_display),
htmllib.attrencode(this_host), e))
+
+ html.message('<b>%s</b><p>%s</p>' % (
+ _('Acknowledged %s') % ack_msg,
+ _('Acknowledged all messages in %s.') % ack_msg
+ ))
html.footer()
@@ -380,12 +418,12 @@ def form_level(level):
levels = [ 'OK', 'WARN', 'CRIT', 'UNKNOWN' ]
return levels[level]
-def form_file_to_int(file):
- return file.replace('/', '\\')
+def form_file_to_int(f):
+ return f.replace('/', '\\')
-def form_file_to_ext(file):
- return file.replace('\\', '/')
+def form_file_to_ext(f):
+ return f.replace('\\', '/')
-def form_datetime(dt, format = '%Y-%m-%d %H:%M:%S'):
+def form_datetime(dt, fmt = '%Y-%m-%d %H:%M:%S'):
# FIXME: Dateformat could be configurable
- return dt.strftime(format)
+ return dt.strftime(fmt)