Skip to content

Commit 8c42d11

Browse files
committed
added sound alerts (fixes sni#68)
1 parent 0c8449b commit 8c42d11

25 files changed

+176
-9
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This file documents the revision history for the Monitoring Webinterface Thruk.
99
- added init script
1010
- added event details to logs excel export
1111
- added site name to excel export (Mark Wilkinson)
12+
- added sound alerts
1213
- internal changes ( removed prototype library )
1314
- mobile:
1415
- added performance graph to mobile interface

MANIFEST

+7
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ plugins/plugins-available/conf/t/data/4/dir/file3.cfg
140140
plugins/plugins-available/conf/t/data/4/file1.cfg
141141
plugins/plugins-available/conf/t/data/4/file2.cfg
142142
plugins/plugins-available/conf/t/data/5/hosts.cfg
143+
plugins/plugins-available/conf/t/data/6/servicegroups_iso-8859.cfg
144+
plugins/plugins-available/conf/t/data/6/servicegroups_utf8.cfg
143145
plugins/plugins-available/conf/t/model_Objects.t
144146
plugins/plugins-available/conf/templates/_conf_action_menu.tt
145147
plugins/plugins-available/conf/templates/_conf_frame.tt
@@ -292,6 +294,10 @@ root/thruk/javascript/jquery-ui/css/smoothness/jquery-ui-1.8.16.custom.css
292294
root/thruk/javascript/jquery-ui/js/jquery-ui-1.8.16.custom.min.js
293295
root/thruk/javascript/overlib.js
294296
root/thruk/javascript/thruk-1.27.js
297+
root/thruk/media/critical.wav
298+
root/thruk/media/ok.wav
299+
root/thruk/media/unknown.wav
300+
root/thruk/media/warning.wav
295301
root/thruk/startup.html
296302
root/thruk/themes
297303
script/append.make
@@ -391,6 +397,7 @@ templates/_service_command_box.tt
391397
templates/_service_command_box_full.tt
392398
templates/_service_status_details_box.tt
393399
templates/_show_link.tt
400+
templates/_sounds.tt
394401
templates/_status_cmd_pane.tt
395402
templates/_status_detail_table.tt
396403
templates/_status_filter.tt

THANKS

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Pierre Mavro
2525
Mark Wilkinson
2626

2727

28+
2829
STYLES:
2930
=======
3031
Nagios Neat Style:
@@ -41,7 +42,7 @@ http://exchange.nagios.org/directory/Addons/Frontends-%28GUIs-and-CLIs%29/Web-In
4142

4243

4344

44-
ICONS:
45+
MEDIA:
4546
======
4647

4748
Silk Icon Set:
@@ -53,6 +54,10 @@ http://glyphish.com/
5354
Find Icons
5455
http://findicons.com/
5556

57+
Alarm Sound
58+
http://www.freeaudioclips.com
59+
60+
5661

5762
JAVASCRIPT:
5863
===========

cgi.cfg

+25
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,28 @@ notes_url_target=_blank
176176
# 1 = lock author names (disallow editing)
177177

178178
lock_author_names=1
179+
180+
181+
# SOUND OPTIONS
182+
# These options allow you to specify an optional audio file
183+
# that should be played in your browser window when there are
184+
# problems on the network. The audio files are used only in
185+
# the status CGI. Only the sound for the most critical problem
186+
# will be played. Order of importance (higher to lower) is as
187+
# follows: unreachable hosts, down hosts, critical services,
188+
# warning services, and unknown services. If there are no
189+
# visible problems, the sound file optionally specified by
190+
# 'normal_sound' variable will be played.
191+
#
192+
# <varname>=<sound_file>
193+
#
194+
# Note: All audio files use relative paths from /thruk/cgi-bin/status.cgi
195+
# and must be accessible by web
196+
197+
host_unreachable_sound=../media/critical.wav
198+
host_down_sound=../media/critical.wav
199+
service_critical_sound=../media/critical.wav
200+
service_warning_sound=../media/warning.wav
201+
service_unknown_sound=../media/unknown.wav
202+
#normal_sound=../media/ok.wav
203+

lib/Thruk/Controller/Root.pm

+12
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ sub begin : Private {
280280
# additional views on status pages
281281
$c->stash->{'additional_views'} = $Thruk::Utils::Status::additional_views || {};
282282

283+
# sound cookie set?
284+
$c->stash->{'play_sounds'} = 0;
285+
if(defined $c->request->cookie('thruk_sounds')) {
286+
my $sound_cookie = $c->request->cookie('thruk_sounds');
287+
if(defined $sound_cookie->value and $sound_cookie->value eq 'off') {
288+
$c->stash->{'play_sounds'} = 0;
289+
}
290+
if(defined $sound_cookie->value and $sound_cookie->value eq 'on') {
291+
$c->stash->{'play_sounds'} = 1;
292+
}
293+
}
294+
283295
# make private _ hash keys available
284296
$Template::Stash::PRIVATE = undef;
285297

lib/Thruk/Controller/status.pm

+3
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,9 @@ sub _process_combined_page {
804804
$c->stash->{'show_host_attempts'} = 1;
805805
if( $sortoption == 6 and defined $hosts ) { @{ $c->stash->{'hosts'} } = reverse @{ $c->stash->{'hosts'} }; }
806806

807+
# set audio file to play
808+
Thruk::Utils::Status::set_audio_file($c);
809+
807810
return 1;
808811
}
809812

lib/Thruk/Utils/Status.pm

+80-3
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ sub set_default_stash {
4343
$c->stash->{'servicegroup'} = $c->{'request'}->{'parameters'}->{'servicegroup'} || '';
4444
$c->stash->{'host'} = $c->{'request'}->{'parameters'}->{'host'} || '';
4545
$c->stash->{'service'} = $c->{'request'}->{'parameters'}->{'service'} || '';
46-
$c->stash->{'data'} = "";
47-
$c->stash->{'style'} = "";
46+
$c->stash->{'data'} = '';
47+
$c->stash->{'style'} = '';
4848
$c->stash->{'has_error'} = 0;
49-
$c->stash->{'pager'} = "";
49+
$c->stash->{'pager'} = '';
5050
$c->stash->{show_substyle_selector} = 1;
5151
$c->stash->{imgsize} = 20;
52+
$c->stash->{'audiofile'} = '';
5253

5354
return;
5455
}
@@ -455,6 +456,9 @@ sub fill_totals_box {
455456

456457
$c->stash->{'service_stats'} = $service_stats;
457458

459+
# set audio file to play
460+
Thruk::Utils::Status::set_audio_file($c);
461+
458462
return 1;
459463
}
460464

@@ -1596,6 +1600,79 @@ sub convert_time_amount {
15961600
return $value;
15971601
}
15981602

1603+
##############################################
1604+
1605+
=head2 set_audio_file
1606+
1607+
set_audio_file($c)
1608+
1609+
set if browser should play a sound file
1610+
1611+
=cut
1612+
sub set_audio_file {
1613+
my( $c ) = @_;
1614+
1615+
return unless $c->stash->{'play_sounds'};
1616+
1617+
if(defined $c->stash->{'host_stats'} and defined $c->stash->{'service_stats'}) {
1618+
for my $s (qw/unreachable down/) {
1619+
if($c->stash->{'host_stats'}->{$s} > 0 and defined $c->config->{'cgi_cfg'}->{'host_'.$s.'_sound'}) {
1620+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'host_'.$s.'_sound'};
1621+
return;
1622+
}
1623+
}
1624+
for my $s (qw/critical warning unknown/) {
1625+
if($c->stash->{'service_stats'}->{$s} > 0 and defined $c->config->{'cgi_cfg'}->{'service_'.$s.'_sound'}) {
1626+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'service_'.$s.'_sound'};
1627+
return;
1628+
}
1629+
}
1630+
}
1631+
1632+
elsif(defined $c->stash->{'hosts'} and defined $c->stash->{'services'}) {
1633+
my $worst_host = 0;
1634+
for my $h (@{$c->stash->{'hosts'}}) {
1635+
$worst_host = $h->{'state'} if $worst_host < $h->{'state'};
1636+
}
1637+
if($worst_host == 2 and defined $c->config->{'cgi_cfg'}->{'host_unreachable_sound'}) {
1638+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'host_unreachable_sound'};
1639+
return;
1640+
}
1641+
if($worst_host == 1 and defined $c->config->{'cgi_cfg'}->{'host_down_sound'}) {
1642+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'host_down_sound'};
1643+
return;
1644+
}
1645+
1646+
my $worst_service = 0;
1647+
for my $s (@{$c->stash->{'services'}}) {
1648+
my $state = $s->{'state'} + 1;
1649+
$state = $state - 3 if $state == 4;
1650+
$worst_service = $state if $worst_host < $state;
1651+
}
1652+
if($worst_host == 3 and defined $c->config->{'cgi_cfg'}->{'service_critical_sound'}) {
1653+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'service_critical_sound'};
1654+
return;
1655+
}
1656+
if($worst_host == 2 and defined $c->config->{'cgi_cfg'}->{'service_warning_sound'}) {
1657+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'service_warning_sound'};
1658+
return;
1659+
}
1660+
if($worst_host == 1 and defined $c->config->{'cgi_cfg'}->{'service_unknown_sound'}) {
1661+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'service_unknown_sound'};
1662+
return;
1663+
}
1664+
}
1665+
1666+
if($c->stash->{'audiofile'} eq '' and defined $c->config->{'cgi_cfg'}->{'normal_sound'}) {
1667+
$c->stash->{'audiofile'} = $c->config->{'cgi_cfg'}->{'normal_sound'};
1668+
return;
1669+
}
1670+
1671+
return;
1672+
}
1673+
1674+
##############################################
1675+
15991676
=head1 AUTHOR
16001677
16011678
Sven Nierlein, 2009, <[email protected]>

plugins/plugins-available/dashboard/templates/status_dashboard.tt

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<link rel='stylesheet' type='text/css' href='[% url_prefix %]thruk/plugins/dashboard/thruk/stylesheets/dashboard.css' />
2222
[% END %]
2323
[% PROCESS _header.tt extra_header => dashboard_header %]
24+
[% PROCESS _message.tt %]
25+
[% PROCESS _sounds.tt %]
2426

2527
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="top_pane"[% IF hidetop == 1 %]style="visibility:hidden; display:none;"[% END %]>
2628
<tr>

plugins/plugins-available/minemap/templates/minemap.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[% USE date %]
22
[% PROCESS _header.tt %]
33
[% PROCESS _message.tt %]
4+
[% PROCESS _sounds.tt %]
45

56
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="top_pane"[% IF hidetop == 1 %]style="visibility:hidden; display:none;"[% END %]>
67
<tr>

root/thruk/javascript/all_in_one-1.27.js

+9
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ function prefSubmit(url, current_theme) {
151151
}
152152
}
153153

154+
/* save settings in a cookie */
155+
function prefSubmitSound(url, value) {
156+
var now = new Date();
157+
var expires = new Date(now.getTime() + (10*365*86400*1000)); // let the cookie expire in 10 years
158+
document.cookie = "thruk_sounds="+value+"; path="+url_prefix+"thruk; expires=" + expires.toGMTString() + ";";
159+
window.status = "thruk preferences saved";
160+
reloadPage();
161+
}
162+
154163
/* page refresh rate */
155164
function setRefreshRate(rate) {
156165
curRefreshVal = rate;

root/thruk/javascript/thruk-1.27.js

+9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ function prefSubmit(url, current_theme) {
134134
}
135135
}
136136

137+
/* save settings in a cookie */
138+
function prefSubmitSound(url, value) {
139+
var now = new Date();
140+
var expires = new Date(now.getTime() + (10*365*86400*1000)); // let the cookie expire in 10 years
141+
document.cookie = "thruk_sounds="+value+"; path="+url_prefix+"thruk; expires=" + expires.toGMTString() + ";";
142+
window.status = "thruk preferences saved";
143+
reloadPage();
144+
}
145+
137146
/* page refresh rate */
138147
function setRefreshRate(rate) {
139148
curRefreshVal = rate;

root/thruk/media/critical.wav

33.3 KB
Binary file not shown.

root/thruk/media/ok.wav

17.6 KB
Binary file not shown.

root/thruk/media/unknown.wav

9.99 KB
Binary file not shown.

root/thruk/media/warning.wav

23.9 KB
Binary file not shown.

script/thruk

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Getopt::Long::Configure('bundling');
1414
GetOptions (
1515
"h|help" => \$options->{'help'},
1616
"v|verbose" => \$options->{'verbose'},
17+
"V|version" => \$options->{'version'},
1718
"r|remote-url=s" => \$options->{'remoteurl'},
1819
"local" => \$options->{'local'},
1920
"c|credential=s" => \$options->{'credential'},
@@ -24,6 +25,7 @@ GetOptions (
2425
"<>" => sub { $options->{'url'} = "".shift },
2526
) or pod2usage( { -verbose => 2, -message => 'error in options' } );
2627

28+
if($options->{'version'}) { require Thruk; print "Thruk Version $Thruk::VERSION\n"; exit 0; }
2729
pod2usage( { -verbose => 2, -exit => 1 } ) if $options->{'help'};
2830
pod2usage( { -verbose => 2, -exit => 1 } ) if !$options->{'action'} and !$options->{'url'} and !$options->{'listbackends'};
2931

t/92_todo.t

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ plan skip_all => 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.' un
77

88
my $cmds = [
99
"grep -nr 'TODO' lib/. templates/. plugins/plugins-available/. root/.",
10-
"grep -nr Dumper lib/ plugins/plugins-available/ | grep STDERR | grep use",
10+
"grep -nr 'print STDERR Dumper' lib/ plugins/plugins-available/",
1111
];
1212

1313
# find all TODOs
1414
for my $cmd (@{$cmds}) {
1515
open(my $ph, '-|', $cmd.' 2>&1') or die('cmd '.$cmd.' failed: '.$!);
16+
ok($ph, 'cmd started');
1617
while(<$ph>) {
1718
my $line = $_;
1819
chomp($line);
@@ -22,15 +23,13 @@ for my $cmd (@{$cmds}) {
2223
or $line =~ m|Unicode/Encoding\.pm|mx
2324
or $line =~ m|/excanvas.js|mx
2425
or $line =~ m|jquery\.mobile\-.*.js|mx
25-
or $line =~ m|:\d+:\#|mx
2626
) {
2727
next;
2828
}
2929

3030
fail($line);
3131
}
3232
close($ph);
33-
ok($? == 0, 'cmd '.$cmd.' exited with: '.$?);
3433
}
3534

3635

templates/_header.tt

+8-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@
114114
<table class="pref_pane" border=1 width="450">
115115
<tr>
116116
<td>
117-
<table>
117+
<table width="430">
118118
<tr>
119-
<th>Theme:</th>
119+
<th width="100">Theme:</th>
120120
<td>
121121
<select name="theme" id="pref_theme">
122122
[% FOR t = themes %]
@@ -126,6 +126,12 @@
126126
<input type="button" name="submit" value="change" onClick="prefSubmit('[% escape_html(c.request.uri) %]', '[% theme %]')">
127127
</td>
128128
</tr>
129+
<tr>
130+
<th>Sounds:</th>
131+
<td>
132+
<input type="button" name="submit" value="[% IF play_sounds %]sound is on[% ELSE %]sound is off[% END %]" onClick="prefSubmitSound('[% escape_html(c.request.uri) %]', '[% IF play_sounds %]off[% ELSE %]on[% END %]')">
133+
</td>
134+
</tr>
129135
<tr>
130136
<th>Page Refresh:</th>
131137
<td nowrap>

templates/_sounds.tt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[% IF audiofile %]
2+
<object height="0" width="0" data="[% audiofile %]" ></object>
3+
[% END %]

templates/status_combined.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[% USE date %]
22
[% PROCESS _header.tt %]
33
[% PROCESS _message.tt %]
4+
[% PROCESS _sounds.tt %]
45
[% authorized_for_read_only = 0 %][% IF c.check_user_roles_wrapper('authorized_for_read_only') %][% authorized_for_read_only = 1 %][% END %]
56

67
[% UNLESS authorized_for_read_only %]

templates/status_detail.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[% USE date %]
22
[% PROCESS _header.tt %]
33
[% PROCESS _message.tt %]
4+
[% PROCESS _sounds.tt %]
45
[% authorized_for_read_only = 0 %][% IF c.check_user_roles_wrapper('authorized_for_read_only') %][% authorized_for_read_only = 1 %][% END %]
56

67
[% UNLESS authorized_for_read_only %]

templates/status_grid.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[% PROCESS _header.tt %]
2+
[% PROCESS _sounds.tt %]
23

34
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="top_pane"[% IF hidetop == 1 %]style="visibility:hidden; display:none;"[% END %]>
45
<tr>

templates/status_hostdetail.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[% USE date %]
22
[% PROCESS _header.tt %]
33
[% PROCESS _message.tt %]
4+
[% PROCESS _sounds.tt %]
45
[% authorized_for_read_only = 0 %][% IF c.check_user_roles_wrapper('authorized_for_read_only') %][% authorized_for_read_only = 1 %][% END %]
56

67
[% UNLESS authorized_for_read_only %]

templates/status_overview.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[% PROCESS _header.tt %]
2+
[% PROCESS _sounds.tt %]
23

34
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="top_pane"[% IF hidetop == 1 %]style="visibility:hidden; display:none;"[% END %]>
45
<tr>

templates/status_summary.tt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[% PROCESS _header.tt %]
2+
[% PROCESS _sounds.tt %]
23

34
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="top_pane"[% IF hidetop == 1 %]style="visibility:hidden; display:none;"[% END %]>
45
<tr>

0 commit comments

Comments
 (0)