Module: check_mk
Branch: master
Commit: 032ef86b74f9def04e4d8dae4eeb679abcbd4378
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=032ef86b74f9de…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Aug 23 10:01:54 2016 +0200
3763 FIX Fixed playing sounds in views when using current Firefox
Changed the way the sounds are played in HTML code from "object" tag to
HTML5 "audio" tag. This should work in most modern browsers.
Also did some refactoring along the way.
---
.werks/3763 | 12 ++++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 28 ++++-----------------------
web/htdocs/views.py | 43 ++++++++++++++++++++++++++++++------------
web/plugins/views/layouts.py | 10 +++++-----
5 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/.werks/3763 b/.werks/3763
new file mode 100644
index 0000000..cf447c1
--- /dev/null
+++ b/.werks/3763
@@ -0,0 +1,12 @@
+Title: Fixed playing sounds in views when using current Firefox
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.4.0i1
+Date: 1471939240
+Class: fix
+
+Changed the way the sounds are played in HTML code from "object" tag to
+HTML5 "audio" tag. This should work in most modern browsers.
+
+Also did some refactoring along the way.
diff --git a/ChangeLog b/ChangeLog
index c7d049e..b5c9dc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -443,6 +443,7 @@
* 3753 FIX: Fixed graph hover popup of services having special characters in their
names
* 3758 FIX: Fixed wrong sorting of events in main dashboard in distributed
environments
* 3561 FIX: Removing a comment now also removes any linked acknowledgements...
+ * 3763 FIX: Fixed playing sounds in views when using current Firefox...
WATO:
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 6692f99..d373bff 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -717,6 +717,10 @@ class html(GUITester):
self.write('<script type="text/javascript"
src="js/%s.js"></script>\n' % name)
+ def play_sound(self, url):
+ self.write("<audio src=\"%s\" autoplay>\n" %
self.attrencode(url))
+
+
#
# HTML form rendering
#
@@ -1943,30 +1947,6 @@ class html(GUITester):
#
- # Sounds
- # TODO: Move to views. Only used there.
- #
-
- def register_event(self, name):
- self.events.add(name)
-
-
- def has_event(self, name):
- return name in self.events
-
-
- def play_sound(self, url):
- self.write('<object type="audio/x-wav" data="%s"
height="0" width="0">\n'
- '<param name="filename"
value="%s">\n'
- '<param name="src" value="%s">\n'
- '<param name="autostart"
value="true">\n'
- '<param name="playcount"
value="1">\n'
- '</object>\n' % (url, url, url))
- if self.enable_debug:
- self.write("(playing sound %s)" % url)
-
-
- #
# Keyboard control
# TODO: Can we move this specific feature to AQ?
#
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 4812bdb..2affdd5 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -41,6 +41,7 @@ def load_plugins(force):
# always reload the hosttag painters, because new hosttags might have been
# added during runtime
load_host_tag_painters()
+ clear_alarm_sound_states()
return
global multisite_datasources ; multisite_datasources = {}
@@ -57,6 +58,7 @@ def load_plugins(force):
load_web_plugins("views", globals())
load_host_tag_painters()
+ clear_alarm_sound_states()
# This must be set after plugin loading to make broken plugins raise
# exceptions all the time and not only the first time (when the plugins
@@ -1457,18 +1459,44 @@ def do_table_join(master_ds, master_rows, master_filters,
join_painters, join_co
row["JOIN"] = joininfo
+g_alarm_sound_states = set([])
+
+
+def clear_alarm_sound_states():
+ g_alarm_sound_states.clear()
+
+
+def save_state_for_playing_alarm_sounds(row):
+ if not config.enable_sounds or not config.sounds:
+ return
+
+ # TODO: Move this to a generic place. What about -1?
+ host_state_map = { 0: "up", 1: "down", 2:
"unreachable"}
+ service_state_map = { 0: "up", 1: "warning", 2:
"critical", 3: "unknown"}
+
+ for state_map, state in [
+ (host_state_map, row.get("host_hard_state",
row.get("host_state"))),
+ (service_state_map, row.get("service_last_hard_state",
row.get("service_state"))) ]:
+ if state != None:
+ g_alarm_sound_states.add(state_map[int(state)])
+
+
def play_alarm_sounds():
- if not config.enable_sounds:
+ if not config.enable_sounds or not config.sounds:
return
url = config.sound_url
if not url.endswith("/"):
url += "/"
- for event, wav in config.sounds:
- if not event or html.has_event(event):
+
+ html.debug(g_alarm_sound_states)
+ for state_name, wav in config.sounds:
+ html.debug(state_name)
+ if not state_name or state_name in g_alarm_sound_states:
html.play_sound(url + wav)
break # only one sound at one time
+
# How many data rows may the user query?
def get_limit():
limitvar = html.var("limit", "soft")
@@ -2423,15 +2451,6 @@ def paint_header(view, p, is_last_column_header=False):
html.guitest_record_output("view", ("header", title))
-def register_events(row):
- if config.sounds != []:
- host_state = row.get("host_hard_state",
row.get("host_state"))
- if host_state != None:
- html.register_event({0:"up", 1:"down",
2:"unreachable"}[saveint(host_state)])
- svc_state = row.get("service_last_hard_state",
row.get("service_state"))
- if svc_state != None:
- html.register_event({0:"up", 1:"warning",
2:"critical", 3:"unknown"}[saveint(svc_state)])
-
# The Group-value of a row is used for deciding wether
# two rows are in the same group or not
def group_value(row, group_painters):
diff --git a/web/plugins/views/layouts.py b/web/plugins/views/layouts.py
index 9f1e097..4b71696 100644
--- a/web/plugins/views/layouts.py
+++ b/web/plugins/views/layouts.py
@@ -69,7 +69,7 @@ def render_group_checkbox_th():
# '----------------------------------------------------------------------'
def render_single_dataset(rows, view, group_painters, painters, num_columns,
_ignore_show_checkboxes):
for row in rows:
- register_events(row) # needed for playing sounds
+ save_state_for_playing_alarm_sounds(row)
html.write('<table class="data single">\n')
rownum = 0
@@ -130,7 +130,7 @@ def render_grouped_boxes(rows, view, group_painters, painters,
num_columns, show
groups = []
last_group = None
for row in rows:
- register_events(row) # needed for playing sounds
+ save_state_for_playing_alarm_sounds(row)
this_group = group_value(row, group_painters)
if this_group != last_group:
last_group = this_group
@@ -209,7 +209,7 @@ def render_grouped_boxes(rows, view, group_painters, painters,
num_columns, show
show_header_line()
visible_row_number += 1
- register_events(row) # needed for playing sounds
+ save_state_for_playing_alarm_sounds(row)
odd = odd == "odd" and "even" or "odd"
@@ -536,7 +536,7 @@ def render_grouped_list(rows, view, group_painters, painters,
num_columns, show_
visible_row_number = 0
group_hidden, num_grouped_rows = None, 0
for index, row in rows_with_ids:
- register_events(row) # needed for playing sounds
+ save_state_for_playing_alarm_sounds(row)
# Show group header, if a new group begins. But only if grouping
# is activated
if len(group_painters) > 0:
@@ -848,7 +848,7 @@ def create_matrices(rows, group_painters, painters, num_columns):
col_num = 0
for row in rows:
- register_events(row) # needed for playing sounds
+ save_state_for_playing_alarm_sounds(row)
group_id = group_value(row, group_painters)
if group_id != last_group_id:
col_num += 1