Module: check_mk
Branch: master
Commit: 673231e52d10eb7d0b6e074aa68936cdbf74f5d3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=673231e52d10eb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 4 19:01:04 2013 +0100
Availability: link to events of host/service
---
web/htdocs/valuespec.py | 5 ++++-
web/htdocs/views.py | 13 ++++++++++---
web/plugins/views/availability.py | 30 ++++++++++++++++++++++++++----
web/plugins/views/filters.py | 13 ++++++++-----
4 files changed, 48 insertions(+), 13 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index bb5df0b..e8edbdf 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1000,7 +1000,10 @@ class CascadingDropdown(ValueSpec):
return "" # Nothing selected? Should never happen
def from_html_vars(self, varprefix):
- sel = int(html.var(varprefix + "_sel"))
+ try:
+ sel = int(html.var(varprefix + "_sel"))
+ except:
+ sel = 0
val, title, vs = self._choices[sel]
if vs:
val = (val, vs.from_html_vars(varprefix + "_%d" % sel))
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 9792000..9850f5f 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1369,7 +1369,11 @@ def render_view(view, rows, datasource, group_painters, painters,
# Take into account: permissions, display_options
row_count > 0 and command_form,
# Take into account: layout capabilities
- can_display_checkboxes, show_checkboxes)
+ can_display_checkboxes, show_checkboxes,
+ # Show link to availability. This exists only for plain hosts
+ # and services table. The grouping tables have columns that
statehist
+ # is missing. That way some of the filters might fail.
+ datasource["table"] in [ "hosts",
"services"] )
# User errors in filters
html.show_user_errors()
@@ -1653,7 +1657,8 @@ def togglebutton(id, isopen, icon, help, hidden = False):
'onclick="view_toggle_form(this,
\'%s\');"%s></div>' % (id, icon, cssclass, help, id, hide))
def show_context_links(thisview, active_filters, show_filters, display_options,
- painter_options, enable_commands, enable_checkboxes,
show_checkboxes):
+ painter_options, enable_commands, enable_checkboxes,
show_checkboxes,
+ show_availability):
# html.begin_context_buttons() called automatically by html.context_button()
# That way if no button is painted we avoid the empty container
if 'B' in display_options:
@@ -1733,7 +1738,9 @@ def show_context_links(thisview, active_filters, show_filters,
display_options,
url = "edit_view.py?clonefrom=%s&load_view=%s&back=%s" % \
(thisview["owner"], thisview["name"], backurl)
html.context_button(_("Edit View"), url, "edit",
id="edit", bestof=config.context_buttons_to_show)
- html.context_button(_("Availability"), html.makeuri([("mode",
"availability")]), "availability")
+
+ if show_availability:
+ html.context_button(_("Availability"),
html.makeuri([("mode", "availability")]), "availability")
if 'B' in display_options:
execute_hooks('buttons-end')
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index f4dff82..7a26a8c 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -138,10 +138,10 @@ avoption_entries = [
columns = 2,
elements = [
( "warn_is_ok",
- Checkbox(label = _("Consider WARN as OK")),
+ Checkbox(label = _("Treat WARN as OK")),
),
( "unknown_is_crit",
- Checkbox(label = _("Consider UNKNOWN as CRIT")),
+ Checkbox(label = _("Treat UNKNOWN as CRIT")),
),
],
optional_keys = False,
@@ -176,6 +176,7 @@ def render_availability_options():
if html.form_submitted():
for name, height, vs in avoption_entries:
try:
+ html.debug(name)
avoptions[name] = vs.from_html_vars("avo_" + name)
except MKUserError, e:
html.add_user_error(e.varname, e.message)
@@ -283,7 +284,9 @@ def compute_range(rangespec):
def get_availability_data(datasource, filterheaders, range, only_sites, limit):
has_service = "service" in datasource["infos"]
av_filter = "Filter: time >= %d\nFilter: time <= %d\n" % range
- if not has_service:
+ if has_service:
+ av_filter += "Filter: service_description !=\n"
+ else:
av_filter += "Filter: service_description =\n"
query = "GET statehist\n" + av_filter
@@ -415,7 +418,26 @@ def do_render_availability(datasource, filterheaders, avoptions,
only_sites, lim
for site, host, service, states, considered_duration in availability:
table.row()
table.cell("", css="buttons")
- html.icon_button("URL", _("Event History"),
"history")
+ history_url_vars = [
+ ("site", site),
+ ("host", host),
+ ("logtime_from_range", "unix"), # absolute timestamp
+ ("logtime_until_range", "unix"), # absolute timestamp
+ ("logtime_from", str(int(from_time))),
+ ("logtime_until", str(int(until_time)))]
+ if has_service:
+ history_url_vars += [
+ ("service", service),
+ ("view_name", "svcevents"),
+ ]
+ else:
+ history_url_vars += [
+ ("view_name", "hostevents"),
+ ]
+
+ history_url = "view.py?" + htmllib.urlencode_vars(history_url_vars)
+
+ html.icon_button(history_url, _("Event History"), "history")
host_url = "view.py?" + htmllib.urlencode_vars([("view_name",
"hoststatus"), ("site", site), ("host", host)])
table.cell(_("Host"), '<a
href="%s">%s</a>' % (host_url, host))
service_url = "view.py?" +
htmllib.urlencode_vars([("view_name", "service"), ("site",
site), ("host", host), ("service", service)])
diff --git a/web/plugins/views/filters.py b/web/plugins/views/filters.py
index 559cd43..b53286a 100644
--- a/web/plugins/views/filters.py
+++ b/web/plugins/views/filters.py
@@ -374,10 +374,10 @@ class FilterTime(Filter):
self.column = column
self.name = name
self.ranges = [
- (86400, _("days")),
- (3600, _("hours")),
- (60, _("min")),
- (1, _("sec")),
+ (86400, _("days")),
+ (3600, _("hours")),
+ (60, _("min")),
+ (1, _("sec")),
]
varnames = [ name + "_from", name + "_from_range",
name + "_until", name + "_until_range" ]
@@ -389,7 +389,8 @@ class FilterTime(Filter):
def display(self):
choices = [ (str(sec), title + " " + _("ago")) for sec, title
in self.ranges ] + \
- [ ("abs", _("Date (YYYY-MM-DD)")) ]
+ [ ("abs", _("Date (YYYY-MM-DD)")),
+ ("unix", _("UNIX timestamp")) ]
html.write("<table class=filtertime>")
for what, whatname in [
@@ -431,6 +432,8 @@ class FilterTime(Filter):
except:
html.add_user_error(varprefix, _("Please enter the date in
the format YYYY-MM-DD."))
range.append(None)
+ elif rangename == "unix":
+ range.append(int(count))
else:
try:
count = int(count)