Module: check_mk
Branch: master
Commit: e9f69b692a94a1587748ebdbf1de886d42c2808a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e9f69b692a94a1…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Apr 4 09:53:18 2016 +0200
3310 New dashlet which shows user notifications
---
.werks/3310 | 9 +++++
ChangeLog | 1 +
web/htdocs/images/dashlet_notify_users.png | Bin 0 -> 3972 bytes
web/htdocs/js/sidebar.js | 2 +-
web/htdocs/notify.py | 4 ++
web/plugins/dashboard/dashlets.py | 60 +++++++++++++++++++++++++++-
web/plugins/pages/shipped.py | 1 +
7 files changed, 75 insertions(+), 2 deletions(-)
diff --git a/.werks/3310 b/.werks/3310
new file mode 100644
index 0000000..b5fb304
--- /dev/null
+++ b/.werks/3310
@@ -0,0 +1,9 @@
+Title: New dashlet which shows user notifications
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.9i1
+Date: 1459756320
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 482918c..a439e94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -126,6 +126,7 @@
* 3288 Implemented grouping of services in table views...
* 3297 SEC: Fixes possible XSS in views sidebar snapin...
* 2237 Unique name for columns of Host Groups and Service Groups...
+ * 3310 New dashlet which shows user notifications
* 3059 FIX: Fixed highlighting of availability timeline time slices
* 3175 FIX: Fix timeranges of graphs that are embedded in a dashboard...
* 3076 FIX: fixed broken views in check_mk raw edition
diff --git a/web/htdocs/images/dashlet_notify_users.png
b/web/htdocs/images/dashlet_notify_users.png
new file mode 100644
index 0000000..74b9891
Binary files /dev/null and b/web/htdocs/images/dashlet_notify_users.png differ
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 4b199cd..134281e 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -1004,7 +1004,7 @@ function read_message() {
if (!c)
return;
- // extract message from teh message container
+ // extract message from the message container
var hints = get_hint_messages(c);
var msg = hints[0];
c.removeChild(msg);
diff --git a/web/htdocs/notify.py b/web/htdocs/notify.py
index 727ba3e..f49a599 100644
--- a/web/htdocs/notify.py
+++ b/web/htdocs/notify.py
@@ -85,6 +85,10 @@ def load_plugins(force):
'title': _('Send an E-Mail'),
'handler': notify_mail,
},
+ 'dashlet': {
+ 'title': _('Send hint to dashlet'),
+ 'handler': notify_gui_msg,
+ },
}
dest_choices = [
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index 61fdad7..0af2067 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -29,7 +29,7 @@ try:
except ImportError:
import json
-import sites
+import sites, notify, table
# .--Overview------------------------------------------------------------.
# | ___ _ |
@@ -818,3 +818,61 @@ dashlet_types["snapin"] = {
)),
],
}
+
+
+#.
+# .--Notify users--------------------------------------------------------.
+# | _ _ _ _ __ |
+# | | \ | | ___ | |_(_)/ _|_ _ _ _ ___ ___ _ __ ___ |
+# | | \| |/ _ \| __| | |_| | | | | | | / __|/ _ \ '__/ __| |
+# | | |\ | (_) | |_| | _| |_| | | |_| \__ \ __/ | \__ \ |
+# | |_| \_|\___/ \__|_|_| \__, | \__,_|___/\___|_| |___/ |
+# | |___/ |
+# +----------------------------------------------------------------------+
+# | Dashlet for notify user pop up messages |
+# '----------------------------------------------------------------------'
+
+
+def ajax_delete_user_notification():
+ msg_id = html.var("id")
+ notify.delete_gui_message(msg_id)
+
+
+def dashlet_notify_users(nr, dashlet):
+
+ html.write('<div class="notify_users">')
+ table.begin("notify_users", sortable=False, searchable=False,
omit_if_empty=True)
+
+
+
+ for entry in sorted(notify.get_gui_messages(), key=lambda e: e["time"],
reverse=True):
+ if "dashlet" in entry["methods"]:
+ table.row()
+
+ msg_id = entry["id"]
+ datetime = time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(entry['time']))
+ message = entry["text"].replace("\n", " ")
+
+ table.cell(_("Actions"), css="buttons", sortable=False)
+ html.icon_button("", _("Delete"), "delete",
onclick="delete_user_notification('%s', this);" % msg_id)
+
+ table.cell(_("Message"), html.attrencode(message))
+ table.cell(_("Date"), datetime)
+
+ table.end()
+ html.javascript('function delete_user_notification(msg_id, btn) {'
+ 'post_url("ajax_delete_user_notification.py",
"id=" + msg_id);'
+ 'var row = btn.parentNode.parentNode;'
+ 'row.parentNode.removeChild(row);}')
+
+ html.write("</div>")
+
+
+dashlet_types["notify_users"] = {
+ "title" : _("User notifications"),
+ "description" : _("Display GUI notifications sent to users."),
+ "render" : dashlet_notify_users,
+ "sort_index" : 75,
+ "allowed" : config.builtin_role_ids,
+ "styles" : ".notify_users { width: 100%; height: 100%; overflow:
auto; }"
+}
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index bc01a31..797c99d 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -95,6 +95,7 @@ pagehandlers.update({
"create_view_dashlet" : dashboard.page_create_view_dashlet,
"create_view_dashlet_infos": dashboard.page_create_view_dashlet_infos,
"ajax_dashlet_pos" : dashboard.ajax_dashlet_pos,
+ "ajax_delete_user_notification" : lambda:
dashboard.ajax_delete_user_notification(),
"ajax_popup_add_visual" : visuals.ajax_popup_add,
"ajax_add_visual" : visuals.ajax_add_visual,