Module: check_mk
Branch: master
Commit: 632a78be8d3e7964c4ca9c40040af6154157ebb4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=632a78be8d3e79…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Wed Jun 15 16:57:02 2016 +0200
failed notification acknowledgements are now stored per user
---
web/htdocs/default_permissions.py | 10 +++++-----
web/htdocs/notifications.py | 33 ++++++++++++---------------------
web/htdocs/sidebar.py | 9 +++++++--
web/plugins/sidebar/shipped.py | 35 +++++++++++++++++++++++------------
4 files changed, 47 insertions(+), 40 deletions(-)
diff --git a/web/htdocs/default_permissions.py b/web/htdocs/default_permissions.py
index 481a5c8..1049241 100644
--- a/web/htdocs/default_permissions.py
+++ b/web/htdocs/default_permissions.py
@@ -148,12 +148,12 @@ def load_plugins(force):
"if the user has this permission."),
[ "admin" ])
- config.declare_permission("general.acknowledge_failed_notifications",
- _("Acknowledge Failed Notifications"),
+ config.declare_permission("general.see_failed_notifications",
+ _("See Failed Notifications"),
_("If check_mk is unable to notify users about problems, the site will warn
about this situation "
- "very visibly inside the UI (both in the Tactical Overview and the
Dashboard). Only a user "
- "with this permission can acknowledge this situation and thereby disable
the warnings."),
- [ "admin" ])
+ "very visibly inside the UI (both in the Tactical Overview and the
Dashboard). This affects only "
+ "users with this permission ."),
+ [ "admin", "user" ])
loaded_with_language = current_language
diff --git a/web/htdocs/notifications.py b/web/htdocs/notifications.py
index 26d1da9..e61d534 100644
--- a/web/htdocs/notifications.py
+++ b/web/htdocs/notifications.py
@@ -29,46 +29,37 @@ import config
import defaults
import lib
import errno
+import os
+
+g_acknowledgement_time = {}
-g_acknowledgement_path = defaults.var_dir + "/acknowledged_notifications.mk"
-g_acknowledgement_time = None
def acknowledge_failed_notifications(timestamp):
- config.need_permission("general.acknowledge_failed_notifications")
+ config.need_permission("general.see_failed_notifications")
global g_acknowledgement_time
- g_acknowledgement_time = timestamp
+ g_acknowledgement_time[config.user_id] = timestamp
save_acknowledgements()
def save_acknowledgements():
- config.need_permission("general.acknowledge_failed_notifications")
- with open(g_acknowledgement_path, "w") as f:
- f.write("%r\n" % g_acknowledgement_time)
+ config.need_permission("general.see_failed_notifications")
+ config.save_user_file("acknowledged_notifications",
int(g_acknowledgement_time[config.user_id]))
def acknowledged_time():
- if g_acknowledgement_time is None:
+ if g_acknowledgement_time.get(config.user_id) is None:
load_acknowledgements()
- return g_acknowledgement_time
+ return g_acknowledgement_time[config.user_id]
def load_acknowledgements():
global g_acknowledgement_time
- try:
- with open(g_acknowledgement_path, "r") as f:
- content = f.read().strip()
- if content:
- g_acknowledgement_time = literal_eval(content)
- except IOError, e:
- if e.errno == errno.ENOENT:
- g_acknowledgement_time = 0
- else:
- raise
+ g_acknowledgement_time[config.user_id] =
config.load_user_file("acknowledged_notifications", 0)
def render_page_confirm(acktime, prev_url):
html.set_render_headfoot(False)
html.header(_("Confirm"), javascripts=[], stylesheets=[ "pages",
"check_mk" ])
html.debug_vars()
html.write('<div class="really">\n')
- html.write(_("Do you really want to acknowledge all failed notifications up to
%s?</br>"
- "This removes the warning for all users.") %
lib.datetime_human_readable(acktime))
+ html.write(_("Do you really want to acknowledge all failed notifications up to
%s?") %\
+ lib.datetime_human_readable(acktime))
html.begin_form("confirm", method="GET", action=prev_url)
html.hidden_field('acktime', acktime),
html.image_button('_confirm', _("Yes"))
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index e35e325..9655070 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -24,8 +24,13 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import config, defaults, views, pprint, os, copy, userdb, pagetypes
-import notify, werks, urlparse
+import pprint
+import os
+import copy
+import urlparse
+
+import config, defaults, views, userdb, pagetypes
+import notify, werks
import sites
from lib import *
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index f23e4cf..7175596 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -546,7 +546,7 @@ table.sitestate td.state {
# | |
# '----------------------------------------------------------------------'
-def render_tactical_overview(extra_filter_headers="", extra_url_variables=[]):
+def get_tactical_overview_data(extra_filter_headers):
host_query = \
"GET hosts\n" \
"Stats: state >= 0\n" \
@@ -588,15 +588,28 @@ def render_tactical_overview(extra_filter_headers="",
extra_url_variables=[]):
try:
hstdata = sites.live().query_summed_stats(host_query)
svcdata = sites.live().query_summed_stats(service_query)
- notdata = sites.live().query_summed_stats(notification_query)
+ if config.may("general.see_failed_notifications"):
+ notdata = sites.live().query_summed_stats(notification_query)
+ else:
+ notdata = [0]
except livestatus.MKLivestatusNotFoundError:
+ return None, None, None
+
+ return hstdata, svcdata, notdata
+
+def render_tactical_overview(extra_filter_headers="",
extra_url_variables=None):
+ if extra_url_variables is None:
+ extra_url_variables = []
+
+ hstdata, svcdata, notdata = get_tactical_overview_data(extra_filter_headers)
+ if hstdata is None or svcdata is None or notdata is None:
html.write("<center>No data from any site</center>")
return
+
html.write("<table class=\"content_center tacticaloverview\"
cellspacing=2 cellpadding=0 border=0>\n")
for title, data, view, what in [
(_("Hosts"), hstdata, 'hostproblems', 'host'),
- (_("Services"), svcdata, 'svcproblems',
'service'),
- ]:
+ (_("Services"), svcdata, 'svcproblems',
'service')]:
html.write("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n"
% (title, _('Problems'), _('Unhandled')))
html.write("<tr>")
@@ -620,14 +633,12 @@ def render_tactical_overview(extra_filter_headers="",
extra_url_variables=[]):
content = '<a target="main" href="%s">%d failed
notifications</a>' %\
(view_url, failed_notifications)
- if config.may("general.acknowledge_failed_notifications"):
-
- confirm_url = html.makeuri_contextless(
- [("acktime", str(time.time()))] + extra_url_variables,
- filename="clear_failed_notifications.py")
- content = ('<a target="main" href="%s">'
- '<img src="images/button_closetimewarp.png"
style="width:16px;height:16px;">'
- '</a> ' % confirm_url) + content
+ confirm_url = html.makeuri_contextless(
+ [("acktime", str(time.time()))] + extra_url_variables,
+ filename="clear_failed_notifications.py")
+ content = ('<a target="main" href="%s">'
+ '<img src="images/button_closetimewarp.png"
style="width:16px;height:16px;">'
+ '</a> ' % confirm_url) + content
html.write('<div class=spacertop><div
class=tacticalalert>%s</div></div>' % content)