Page 1 of 1

Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 2:06 pm
by derekb
Is it possible to modify the php for the Operation Screen to play a sound file (.wav) when a down host is detected?

Re: Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 2:51 pm
by ssax
Should be doable, are you requesting any critical (host and service) or just if a host is down?

Re: Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 2:53 pm
by derekb
Well, I imagine the php/HTML code is extremely similar for both. My preference is just for critical hosts at the moment.

Re: Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 3:48 pm
by ssax
I can point you in the right direction but it will get reverted if/when you do an upgrade and it's not something that we support.

Edit /usr/local/nagiosxi/html/includes/components/opscreen/opscreen.php and add this under the <script type="text/javascript"> section:

Code: Select all

    function play_sound() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', 'http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        audioElement.load();
        audioElement.play();
    }
Edit /usr/local/nagiosxi/html/includes/components/opscreen/merlin.php

Find this code:

Code: Select all

$hosts_down = $row[0];
Add this code right beneath it:

Code: Select all

        $file = '/tmp/hosts_down_temp.txt';
        // Add host count to file
        // Open the file to get existing content
        $old_hosts_down = file_get_contents($file);
        // Write the new host down count to the file
        file_put_contents($file, $hosts_down);

        if ($old_hosts_down < $hosts_down) {
                echo '<script type="text/javascript">play_sound();</script>';
        }
That should get you going in the right direction, works for me, you may modify it to your liking.

Re: Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 3:51 pm
by derekb
Awesome!
I'll give it a shot and report back with my results. Thank you very very much

Re: Operation Screen - Play Sound

Posted: Thu Jun 11, 2015 4:07 pm
by ssax
You could also just copy your mp3 file to /usr/local/nagiosxi/html/images

Code: Select all

chmod 640 /usr/local/nagiosxi/html/images/alarm.mp3
chown nagios.nagios /usr/local/nagiosxi/html/images/alarm.mp3
Then you could change the code to:

Code: Select all

function play_sound() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', '/nagiosxi/images/alarm.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        audioElement.load();
        audioElement.play();
}