[embed=425,349]<?php
// Arguments for input
$to = $argv [ 1 ] ;
$Subject = $argv [ 2 ] ;
$Message = $argv [ 3 ] ;
$Zendesk = explode ( ‘;’ , $to ) ;
define ( ‘ZDURL’ , ‘https: //’ . $Zendesk [ 0 ] . ‘.zendesk.com / api / v2’ ) ;
define ( ‘ZDUSER’ , $Zendesk [ 1 ] ) ;
define ( ‘ZDAPIKEY’ , $Zendesk [ 2 ] ) ;
$Message = explode ("\ n", $message);
$Trigger = array (
‘Name’ => explode (’:’, $message [0]) [1],
‘Id’ => explode (’:’, $message [1]) [1],
‘Status’ => explode (’:’, $message [2]) [1],
‘Hostname’ => explode (’:’, $message [3]) [1],
‘Ip’ => explode (’:’, $message [4]) [1],
‘Value’ => explode (’:’, $message [5]) [1],
‘Event_id’ => explode (’:’, $message [6]) [1],
‘Severity’ => explode (’:’, $message [7]) [1],
‘Zendesk_id’ => ‘’);
$Trigger [‘zendesk_id’] = md5 ($trigger [‘id’]. $Trigger [‘hostname’]);
$Ticket_id = ticket_exists ($trigger [‘zendesk_id’]);
Function ticket_exists ( $external_id )
{
$data = zendesk_API ( ‘/tickets.json?external_id=’ . $External_id , null , ‘GET’ ) ;
If ( isset ( $data -> tickets [ 0 ] -> id ))
return $data -> tickets [ 0 ] -> id ;
Else
return - 1 ;
}
if ($subject == ‘trigger’ )
{
if ($ticket_id < 0)
{
$ticket [ ‘external_id’ ] = $trigger [ ‘zendesk_id’ ] ;
$Ticket [ ‘subject’ ] = 'ZABBIX [ ‘. $Trigger [’ severity ']. ’ ] - Problem on '. $Trigger [ ‘hostname’ ] . ’ : '. $Trigger [ ‘name’ ] ;
$ticket [ ‘message’ ] = 'An alert is currently in course : “\ n”.
$Ticket [ “message” ] . = ’ - '. $Trigger [ “name” ] . “\ N”;
$Ticket [ “message” ] . = ’ - '. $Trigger [ “hostname” ] . ’ ( '. $Trigger [ " ip " ] . “) \ N”;
$Ticket [ “message” ] . = ’ - '. $Trigger [ “severity” ] . “\ N \ n”;
Switch ($trigger [ "severity" ] )
{
case " Not classified ":
$ticket [ "priority" ] = " low ";
Break;
Case " Information ":
$ticket [ "priority" ] = " low ";
Break;
Case " Warning ":
$ticket [ "priority" ] = " normal ";
Break;
Case " Average ":
$ticket [ "priority" ] = " high ";
Break;
Case " High ":
$ticket [ "priority" ] = " high ";
Break;
Case " Disaster ":
$ticket [ "priority" ] = " urgent " ;
Break ;
Create_ticket ($ticket [ "external_id" ] , $ticket [ "subject" ] , $ticket [ "message" ] , $ticket [ "priority" ] ) ;
}
}
function create_ticket ( $external_id , $subject , $message , $priority )
{
$data = array (
“ticket” => array (
“external_id” => $external_id ,
“subject” => $subject ,
“description” => $Message ,
“priority” => $priority ,
“type” => “incident” ,
“requester” => array (
“name” => “Zabbix” ,
“email” => "[email protected]" )
));
Zendesk_API ( "/tickets.json" , json_encode ( $data ), "POST" );
}
else
{
If ($ticket_id> 0)
{
Delete_ticket ($ticket_id);
}
}
function delete_ticket ( $id )
{
zendesk_API ( “/ tickets /” . $id . “.json” , null , “DELETE” ) ;
}
?>[/embed]