Centreon add audioble alert to tacktical overview.


make sure you backup de original files when you dont know or understand the scripts used below.

browse to your centreon install location web dir default;

~>cd /usr/local/centreon/www/

browse to the tacticalOverview dir.

~>cd /include/home/tackticalOverview

Open the file tacticalOverview.php

~>vi /tacticalOverview.php

Add the following code in the bottom of the file.

                        /*
                        * Audiable allert on Warning, Critical, Unknown states.
                        * Values are recalculated because we dont accept NULL as an answer
                        */
                        if(!isset($_SESSION['amis_alert'])){
                                $_SESSION['amis_alert'] = false;
                        }
                        foreach($SvcStat as $key => $val){
                                if(($key == 1) || ($key == 2) || ($key == 3)){
                                        $sum = $val - $svcAck[$key];
                                        if($sum >= 1){

                                                /*This section will open a pop-up that contains the audio alert */
                                                if(!$_SESSION['amis_alert']){
                                                        print('<script>window.open(\'./include/home/tacticalOverview/alert.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
                                                        $_SESSION['amis_alert'] = true;
                                                        break;
                                                }
                                                break;
                                        }else{
                                                /* This section will close the popup when the alert is solved / acked */
                                                print('<script>window.open(\'./include/home/tacticalOverview/closeme.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
                                                $_SESSION['amis_alert'] = false;
                                        }

                                }
                        }

If you want this tidy add additional template entries. I was to lazy for that😉

Save the file and add the alert.ihtml

~>vim ./alert.ihtml

Add the following code

<html>
<head></head>
<body>
<div>
<object type="application/x-shockwave-flash" data="../../../mp3player.swf" height="20" width="180"><param name="FlashVars" value="mp3=../../../error.mp3&autoplay=1&loop=1&showslider=0"/></object></div>
</body>
</html>

Save the file and add the closeme.ihtml

~>vim closeme.ihtml

Add the following code

<html>
<head></head>
<body>
<script>window.close();</script>
</body>
</html>

Go back to the www dir

~>cd /usr/local/centreon/www

download the a nice error.mp3 (yeah you need to rename it😉

wget http://www.freeinfosociety.com/media/sounds/142.mp3
~>cp ./142.mp3 ./error.mp3

Download the flash player (yeah i renamed this one too🙂

~>wget http://flash-mp3-player.net/medias/player_mp3_maxi.swf
cp ./player_mp3_maxi.swf ./mp3player.swf

This should be all

Please do make a backup of the original files. Also when you find this script is not working for you, then please let me know, and why. Then maybe i can come up with an alternative solution. 

About Chris Gralike

Momenteel ben ik manager van de afdeling business continuity bij de zakelijke IT dienstverlener AMIS Services BV. Sinds 2003 ben ik actief in de ICT branche. Tussen 2003 en nu heb ik verschillende rollen vervuld. In de rollen: systeem- en netwerkbeheer, system engineer, servicemanager en nu practice manager ben ik in contact gekomen met uiteenlopende technologieën, methodologieën, ideeën, oplossingen en innovaties. Een rijke ervaring waarmee ik de klanten van Conclusion en AMIS elke dag probeer te ondersteunen. Mijn credo: 'Altijd opzoek een win-win tussen business en technologie.'

Posted on June 8, 2009, in centreon, Linux, Nagios / Centreon, PHP and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink. 14 Comments.

  1. chrisgralike

    Ow, Using this manual is at your own risk!! Always make a backup of the original files!!!

    Functionality

    #Code opperates between refreshes. This is significant because it will “NOT” update a manual closed popup when there is no state change in centreon.

    #Code will compare service problem (#) against acked problems. If the outcome is higher then 1, (there are unacked services) it will spawn the popup containing the alert.ihtml, else it will spawn the closeme.ihtml

    #usage might get confusing when manualy closing any popup or when a popup killer is active! this is because the code requires a statechange and a refresh the restore a stable state.

    #any refresh in a stable state (all problems acked or no service problems known) will generate a popup that closes itself instantly atm. This is to stop the alert from being played. window.focus might hide this behaviour. I will update the code with a state entry so we can limit this to once after a alert.

    #Why a popup? this is because we want the alert to continue even after ‘a’ engineer changes any settings on the monitoring host. So our alert will survive pagechanges, it also allows us to use mp3 files that are longer then the refresh rate of centreon, which is a nice feature if you ask me😉

    Any bugs or unexpected funct loss next to the above described points? please feel free to update this post😉

    Rgrds, and thx Chris

  2. thanks a lot! it worked!

  3. it does not work with centreon 2.1.8
    Can you contact me?

  4. Just send you a mail😉

    Rgrds, Chris

  5. Chris,

    Is there anyway to make this work for Criticals and Unreachables only.

    And what about an option to wait for X amount of time before the alarm is played?

    Thanks!
    Jon

  6. Hi Jon,

    First off, sorry for the late reply.

    I am sure that both of your requests are perfectly possible.

    First on the criticals and unreachables part could be done by simply editing the following rule in the code;

    if(($key == 1) || ($key == 2) || ($key == 3)){

    Not sure what number maps to what type of warning,it has been a while back. But im sure by test/trial you should be perfectly capable to figure out what keys to maintain.

    On the part to wait some time might be a bit more trickier. If I am not mistaken the monitoring page has a meta refresh active with X sec intervals. You might use the $_SESSION{} var in conjunction with this refresh to count the number of refreshes that has happened while the alert was active. This number times the time between the intervals is the time you have waited.

    This number can then be checked in a if statement behind the acknowledgments check in this rule, the new script might look somewhat like this;

    <?php
    
    // Check if the popup is active else set the alert false.
    if(!isset($_SESSION['amis_alert'])){
            $_SESSION['amis_alert'] = false;
    }
    
    // Loop through the itterated services //
    // The array SvcStat is generated by the centreon script
    foreach($SvcStat as $key => $val){
    	// Check the various states that we want the alert to be generated.
    	// TWEAK THIS STATEMENT IF YOU WANT TO ALERT ON DIFFERENT SERVICE STATES //
    	if(($key == 1) || ($key == 2) || ($key == 3)){
    		// calculate the difference between acked services and troubled services
    		// If the distance is bigger then 1 then we have new alerts
    		$sum = $val - $svcAck[$key];
    		if($sum >= 1){
    				// Count the number of refreshes that have occured while an unacked alert was
    				// active
    				if(!isset($_SESSION['num_refreshes'])){
    					$_SESSION['num_refreshes'] = 1;
    				}else{
    					$_SESSION['num_refreshes'] ++;
    				}
    				
    				// Trigger the popup containing the alert after ## number of refreshes
    				// TWEAK THIS SECTION IF YOU WANT IT LATER OR QUICKER
    				if($_SESSION['num_refreshes'] == '5'){
    					/*This section will open a pop-up that contains the audio alert */
    					if(!$_SESSION['amis_alert']){
    							print('<script>window.open(\'./include/home/tacticalOverview/alert.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
    							$_SESSION['amis_alert'] = true;
    							break;
    					}
    				}
    				break;
    		}else{
    				/* This section will close the popup when the alert is solved / acked */
    				print('<script>window.open(\'./include/home/tacticalOverview/closeme.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
    				$_SESSION['amis_alert'] = false;
    				$_SESSION['num_refreshes'] = false;
    		}
    	}else{
    		// We might want to close the alerts when there are no audiable states states.
    		print('<script>window.open(\'./include/home/tacticalOverview/closeme.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
    		$_SESSION['amis_alert'] = false;
    		$_SESSION['num_refreshes'] = false;
    	
    	}
    }
    
    ?>
    
    

    Im not able to test the code for you at this moment because I don’t have access to an test environment atm.

    I hope this helps enough…

    Let me know if I can be of further assistance.

    rgrds,

  7. hello,
    I’m running Centreon 2.2.2 and cannot add the sound alerts,

    I have added and configured all the files as you instracted and still no popup or sound,
    can you please help?

    thanks,
    Roei

  8. Some basic knowhow on php and html scripting might be usefull (its very dificult ‘guessing’ and troubleshooting the problem remotely)

    No-popup usually means one of a few things:
    1) Scripting is disabled in the browser.
    2) The browser has a popup killer active.
    3) The paths in the script arnt correct.
    4) The rights on the newly created files are faulty and inaccessible by the webserver.
    5) There is a typo in the script that results in an ‘js error’ (copy paste in linux might result in faulty quotes! check them ‘ vs `)

    last but not least

    I didnt check this script with the latest centreon versions. If the sourcefiles didnt change, the implementation shouldnt be an issue..

    Good luck🙂

    Kind regards,
    Chris.

  9. Hi,

    on newest Centreon (2.3.4) this solution is not working.

    Regards,
    Czarek

  10. You can try this (based on Chris code):
    1. In file /usr/local/centreon/www/include/home/tacticalOverview/xml/*/tacticalOverviewXml.php near end of file between last two $xml->endElement() line add following lines:
    if (!isset($_SESSION[‘amis_alert’])){
    $_SESSION[‘amis_alert’] = false;
    }

    if (!isset($_SESSION[‘old_modsvcUnhandled’])){
    foreach($SvcStat as $key => $val) {
    $_SESSION[‘old_modsvcUnhandled’][$key] = $val – $svcAck[$key];
    }
    }

    if ( $_SESSION[‘amis_alert’] ) {
    $_SESSION[‘amis_alert’] = false;
    $xml->writeElement(“mod_alert”,”close”);
    }

    foreach($SvcStat as $key => $val){
    if(($key == 1) || ($key == 2) || ($key == 3)){
    $modsvcUnhandled = $val – $svcAck[$key];

    if ( $modsvcUnhandled – $_SESSION[‘old_modsvcUnhandled’][$key] > 0 ) {
    $xml->writeElement(“mod_alert”,”alert”);
    $_SESSION[‘old_modsvcUnhandled’][$key] = $modsvcUnhandled;
    $_SESSION[‘amis_alert’] = true;
    break;
    } else {
    $_SESSION[‘old_modsvcUnhandled’][$key] = $modsvcUnhandled;
    }
    }
    }

    2. In file /usr/local/centreon/www/include/home/tacticalOverview/xsl/*/tacticalOverviewXml.xsl near end of line between and add:

    window.open(“include/home/tacticalOverview/closeme.ihtml”, “alert”,”width=180,height=20,scrollbars=no,toolbar=no,location=no”);

    window.open(“include/home/tacticalOverview/alert.ihtml”, “alert”,”width=180,height=20,scrollbars=no,toolbar=no,location=yes”);

    MP3 is played only when number of alarm increase. Tested on Centreon 2.3.4.

  11. there is no file file /usr/local/centreon/www/include/home/tacticalOverview/xsl/*/tacticalOverviewXml.xsl

    • You are right. Copy&paste failure. Right file is:
      /usr/local/centreon/www/include/home/tacticalOverview/xsl/tacticalOverview.xsl

  12. Hi,

    What is version of centreon that you used ?

    I have use centreon 2.3.8.

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: