See www.zabbix.com for the official Zabbix site.

Notification Asterisk

From Zabbix.org
Jump to: navigation, search

It is possible to use Asterisk for calling notifications for Zabbix. Based on https://www.zabbix.com/wiki/howto/config/alerts/notificationsusingasterisk it should be possible, but it doesn't mention how it is possible. On this page an example is provided that is very basic.

We use a script called zabbix_asterisk_notification.php located in alert.d/. The script is provided below and informs us using a call file for Asterisk that there is a problem, if we add additional code to it we could probably mention the server having the problem (in that case it might be required to make a soundfile per server).

 #!/usr/bin/php
 <?php
 $from = '31123456789'; // Caller ID
 $context = 'sip-internal'; // Context for Asterisk
 
 // Debugging?
 $debug    = true; // Enable or disable debugging, if true it is enabled if false it is disabled
 
 
 $time = date("YmdHis");
 if (count($argv)<3) {
     die ("Usage: ".$argv[0]." recipientmobilenumber \"subject\" \"message\"\n");
 }
 
 if ( $debug ) file_put_contents("/tmp/zabbix_asterisk_".$time, serialize($argv));
 
 $to         = $argv[1];
 $subject    = $argv[2];  // not being used
 $message    = $argv[3];
 
 $string = 'Channel: '.$to.'
 Context: '.$context.'
 Callerid: '.$from.'
 Archive: Yes
 Application: Playback
 ';
 
 $up = 'Data: server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up&server&is&now&up
 ';
 $down = 'Data: warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down&warning&server&down
 ';
 
 if($subject == 'up'){
        $string .= $up;
 }elseif($subject == 'down'){
        $string .= $down;
 }elseif($subject == 'OK'){
        $string .= $up;
 }elseif($subject == 'PROBLEM'){
        $string .= $down;
 }else{
        // You should never hear this message
        $string .= 'Data: hello-world&hello-world&hello-world&hello-world
 ';
 }
 
 file_put_contents('/tmp/notification_'.$time,$string);
 exec('/bin/chmod 777 /tmp/notification_'.$time,$output,$return);
 exec('/bin/cp -a /tmp/notification_'.$time.' /var/spool/asterisk/outgoing/notification_'.$time,$output,$return);
 
 if ( $debug !== true) exec('/bin/rm /tmp/notification_'.$time,$output,$return);
 ?>

In Zabbix we have a Administration -> Media type defined as script with the name zabbix_asterisk_notification.php and description Zabbix Asterisk notification. Configuration -> Actions has an action named Call notification with both subjects set to {TRIGGER.STATUS} and both messages set to "{TRIGGER.STATUS}: {TRIGGER.NAME}" and the action set to "Send only to" Zabbix Asterisk notification and to the group Zabbix administrators and the operation type is send message. There are a few conditions (we only want to get phone calls if the trigger severity is high and/or disaster).

The administrators have the following Media set in their account:

Type: Zabbix Asterisk notification
Send to: LOCAL/1234 // Dialplan in a context of Asterisk, setting a SIP/0123456789@trunk should also be possible
When active: when should they be notified
Use if severity: High + Disaster
Status: enabled

Hopefully you can use the information above, it is tested on Zabbix 1.8.11 and when we discover updates are required when we use a newer Zabbix version we will update it. Questions can be mailed to mark@mscholten.eu.