@@ -43,12 +43,13 @@ sub set_default_stash {
43
43
$c -> stash-> {' servicegroup' } = $c -> {' request' }-> {' parameters' }-> {' servicegroup' } || ' ' ;
44
44
$c -> stash-> {' host' } = $c -> {' request' }-> {' parameters' }-> {' host' } || ' ' ;
45
45
$c -> stash-> {' service' } = $c -> {' request' }-> {' parameters' }-> {' service' } || ' ' ;
46
- $c -> stash-> {' data' } = " " ;
47
- $c -> stash-> {' style' } = " " ;
46
+ $c -> stash-> {' data' } = ' ' ;
47
+ $c -> stash-> {' style' } = ' ' ;
48
48
$c -> stash-> {' has_error' } = 0;
49
- $c -> stash-> {' pager' } = " " ;
49
+ $c -> stash-> {' pager' } = ' ' ;
50
50
$c -> stash-> {show_substyle_selector } = 1;
51
51
$c -> stash-> {imgsize } = 20;
52
+ $c -> stash-> {' audiofile' } = ' ' ;
52
53
53
54
return ;
54
55
}
@@ -455,6 +456,9 @@ sub fill_totals_box {
455
456
456
457
$c -> stash-> {' service_stats' } = $service_stats ;
457
458
459
+ # set audio file to play
460
+ Thruk::Utils::Status::set_audio_file($c );
461
+
458
462
return 1;
459
463
}
460
464
@@ -1596,6 +1600,79 @@ sub convert_time_amount {
1596
1600
return $value ;
1597
1601
}
1598
1602
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
+
1599
1676
=head1 AUTHOR
1600
1677
1601
1678
Sven Nierlein, 2009, <[email protected] >
0 commit comments