Module: check_mk
Branch: master
Commit: 44ddff698635134c0858143d382eb827de944d1a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=44ddff69863513…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Feb 27 14:31:28 2013 +0100
Availability: add summary line to table
---
web/htdocs/views.css | 12 +++++++
web/plugins/views/availability.py | 63 +++++++++++++++++++++++++++++++-----
2 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/web/htdocs/views.css b/web/htdocs/views.css
index 3a82d5a..46fa294 100644
--- a/web/htdocs/views.css
+++ b/web/htdocs/views.css
@@ -485,6 +485,17 @@ table.data.availability td.unused {
text-shadow: 1px 1px 0.5px #fff;
}
+table.data.availability tr.summary {
+ background-color: #bbb;
+}
+table.data.availability tr.summary td {
+ border-top: 1px solid black;
+ font-weight: bold;
+ border-bottom-style: none;
+ padding-bottom: 1px;
+ padding-top: 1px;
+}
+
table.data td.flapping, table.timeline td.flapping {
/* background-image: url("images/bg_flapping.png");
background-repeat: repeat; */
@@ -520,6 +531,7 @@ div#avoptions_on {
margin-right: 3px;
}
+
table.timeline {
width: 800px;
margin-bottom: 20px;
diff --git a/web/plugins/views/availability.py b/web/plugins/views/availability.py
index 17c90a0..bf2c401 100644
--- a/web/plugins/views/availability.py
+++ b/web/plugins/views/availability.py
@@ -242,6 +242,21 @@ avoption_entries = [
title = _("Phase Merging"),
label = _("Do not merge consecutive phases with equal state")),
),
+
+ # Summary line
+ ( "summary",
+ "single",
+ DropdownChoice(
+ title = _("Summary line"),
+ choices = [
+ ( None, _("Do not show a summary line") ),
+ ( "sum", _("Display total sum (for % the average)")
),
+ ( "average", _("Display average") ),
+ ],
+ default_value = sum,
+ )
+ ),
+
]
@@ -267,6 +282,7 @@ def render_availability_options():
},
"short_intervals" : 0,
"dont_merge" : False,
+ "summary" : "sum",
})
is_open = False
@@ -679,8 +695,25 @@ def render_availability_table(availability, from_time, until_time,
range_title,
sg = avoptions["state_grouping"]
state_groups = [ sg["warn"], sg["unknown"],
sg["host_down"] ]
+ # Helper function, needed in row and in summary line
+ def cell_active(sid):
+ if sid == "outof_notification_period" and not
avoptions["consider"]["notification_period"]:
+ return False
+ elif sid == "in_downtime" and
avoptions["downtimes"]["include"] == "ignore":
+ return False
+ elif sid == "unmonitored" and not
avoptions["consider"]["unmonitored"]:
+ return False
+ elif sid == "flapping" and not
avoptions["consider"]["flapping"]:
+ return False
+ elif sid in [ "warn", "unknown", "host_down" ] and
sid not in state_groups:
+ return False
+ else:
+ return True
+
# Render the stuff
availability.sort()
+ show_summary = what != "bi" and avoptions.get("summary")
+ summary = {}
table.begin(_("Availability") + " " + range_title,
css="availability")
for site, host, service, states, considered_duration in availability:
table.row()
@@ -712,20 +745,32 @@ def render_availability_table(availability, from_time, until_time,
range_title,
availability_columns = host_availability_columns
for sid, css, sname, help in availability_columns:
- if sid == "outof_notification_period" and not
avoptions["consider"]["notification_period"]:
- continue
- elif sid == "in_downtime" and
avoptions["downtimes"]["include"] == "ignore":
- continue
- elif sid == "unmonitored" and not
avoptions["consider"]["unmonitored"]:
- continue
- elif sid == "flapping" and not
avoptions["consider"]["flapping"]:
- continue
- elif sid in [ "warn", "unknown", "host_down" ]
and sid not in state_groups:
+ if not cell_active(sid):
continue
number = states.get(sid, 0)
if not number:
css = "unused"
+ elif show_summary:
+ summary.setdefault(sid, 0.0)
+ summary[sid] += number
+ table.cell(sname, render_number(number, considered_duration),
css="number " + css, help=help)
+
+ if show_summary:
+ table.row(css="summary")
+ table.cell("")
+ table.cell("", _("Summary"))
+ if what == "service":
+ table.cell("", "")
+ considered_duration = until_time - from_time
+
+ for sid, css, sname, help in availability_columns:
+ number = summary.get(sid, 0)
+ if show_summary == "average" or
avoptions["timeformat"].startswith("percentage"):
+ number /= len(availability)
+ if not number:
+ css = "unused"
table.cell(sname, render_number(number, considered_duration),
css="number " + css, help=help)
+
table.end()