Module: check_mk
Branch: master
Commit: ff54d7106a50ad69d8e82f0b0e8bc9013d926692
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ff54d7106a50ad…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Nov 14 16:20:25 2011 +0100
New filter for the (new) state in host/service alerts
---
ChangeLog | 1 +
web/htdocs/views.py | 5 +----
web/plugins/views/builtin.py | 8 +++++---
web/plugins/views/filters.py | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b6f11e7..e862d05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@
Multisite:
* New nifty sidebar snapin "Speed-O-Meter"
* Implemented logout functionality in OMD environments
+ * New filter for the (new) state in host/service alerts
WATO:
* Evolved to full featured monitoring configuration tool!
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 7a1b648..7e89114 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -600,7 +600,7 @@ function toggle_section(nr, oImg) {
html.write("<table class=filters>")
html.write("<tr><th>")
html.write(_("Filter"))
-
html.write("</th><th>"+_('usage')+"</th><th>"+_('hardcoded
settings')+"</th><th>"+_('HTML
variables')+"</th></tr>\n")
+
html.write("</th><th>"+_('usage')+"</th><th>"+_('hardcoded
settings')+"</th></tr>\n")
allowed_filters = filters_allowed_for_datasource(datasourcename)
# sort filters according to title
s = [(filt.sort_index, filt.title, fname, filt)
@@ -623,9 +623,6 @@ function toggle_section(nr, oImg) {
html.write("</td><td class=widget>")
filt.display()
html.write("</td>")
- html.write("<td><tt>")
- html.write(" ".join(filt.htmlvars))
- html.write("</tt></td>")
html.write("</tr>\n")
html.write("</table>\n")
# Set all filters into the proper display state
diff --git a/web/plugins/views/builtin.py b/web/plugins/views/builtin.py
index b010dc7..661a083 100644
--- a/web/plugins/views/builtin.py
+++ b/web/plugins/views/builtin.py
@@ -1581,7 +1581,8 @@ multisite_builtin_views.update({
'show_filters': ['hostregex',
'serviceregex',
'logtime',
- 'log_plugin_output'],
+ 'log_plugin_output',
+ 'log_state',],
'sorters': [('log_time', True), ('log_lineno',
True)],
'title': _('Host- and Service events'),
'topic': _('Other')},
@@ -1680,7 +1681,7 @@ multisite_builtin_views.update({
],
'play_sounds': False,
'public': True,
- 'show_filters': ['logtime'],
+ 'show_filters': ['logtime', 'log_state'],
'sorters': [('log_time', True), ('log_lineno',
True)],
'title': _('Events of host & services')},
'logfile': {'browser_reload': 0,
@@ -1732,7 +1733,8 @@ multisite_builtin_views.update({
'hostregex',
'serviceregex',
'opthostgroup',
- 'logtime'],
+ 'logtime',
+ 'log_state'],
'sorters': [('log_time', True), ('log_lineno',
True)],
'title': _('Search Global Logfile'),
'topic': _('Other')},
diff --git a/web/plugins/views/filters.py b/web/plugins/views/filters.py
index 60da59c..2a22f2d 100644
--- a/web/plugins/views/filters.py
+++ b/web/plugins/views/filters.py
@@ -510,3 +510,39 @@ declare_filter(255, FilterLogClass())
declare_filter(202, FilterText("log_plugin_output", _("Log: plugin
output"), "log", "log_plugin_output",
"log_plugin_output", "~~"))
declare_filter(260, FilterText("log_contact_name", _("Log: contact
name"), "log", "log_contact_name",
"log_contact_name", "="),
_("Exact match, used for linking"))
+
+class FilterLogState(Filter):
+ def __init__(self):
+ self._items = [ ("h0", "host", 0,
_("Up")),("h1", "host", 1,
_("Down")),("h2", "host", 2, _("Unreachable")),
+ ("s0", "service", 0, _("OK")),
("s1", "service", 1, _("Warning")),
+ ("s2", "service", 2,
_("Critical")),("s3", "service", 3, _("Unknown"))
]
+
+ Filter.__init__(self, "log_state", _("Type of alerts of hosts and
services"),
+ "log", [ "logst_" + e[0] for e in self._items ], [])
+
+ def display(self):
+ html.write("<table><tr><td>")
+ for varsuffix, what, state, text in self._items:
+ if state == 0:
+ html.write("%s %s:<br>" % (_(what.title()),
_("alerts")))
+ html.write(" ")
+ html.checkbox("logst_" + varsuffix, True)
+ html.write(" " + text + "<br>")
+ if varsuffix == "h2":
+ html.write("</td><td>")
+ html.write("</td></tr></table>")
+
+ def filter(self, infoname):
+ headers = []
+ for varsuffix, what, state, text in self._items:
+ if html.get_checkbox("logst_" + varsuffix) != False: # None = form
not filled in = allow
+ headers.append("Filter: log_type = %s ALERT\nFilter: log_state =
%d\nAnd: 2\n" %
+ (what.upper(), state))
+ if len(headers) == 0:
+ return "Limit: 0\n" # no allowed state
+ elif len(headers) == len(self._items):
+ return "" # all allowed or form not filled in
+ else:
+ return "".join(headers) + ("Or: %d\n" % len(headers))
+
+declare_filter(270, FilterLogState())