#! /usr/local/bin/php */ // This script sends Nagios plugins to Pushover // // See: http://www.barryodonovan.com/index.php/2013/05/31/nagios-icinga-alerts-via-pushover // // USAGE: notify-by-pushover.php date_default_timezone_set('Europe/Dublin'); define( "VERSION", '1.0.0' ); ini_set( 'max_execution_time', '55' ); ini_set( 'display_errors', true ); ini_set( 'display_startup_errors', true ); define( 'PO_PRI_LOW', -1 ); define( 'PO_PRI_NORMAL', 0 ); define( 'PO_PRI_HIGH', 1 ); define( 'PO_PRI_EMERG', 2 ); // not used at present in this script // get the message from STDIN $message = trim( fgets( STDIN ) ); // get the parameters $mode = isset( $argv[1] ) ? $argv[1] : false; // SERVICE or HOST $app = isset( $argv[2] ) ? $argv[2] : false; $user = isset( $argv[3] ) ? $argv[3] : false; $type = isset( $argv[4] ) ? $argv[4] : false; // NOTIFICATIONTYPE $state = isset( $argv[5] ) ? $argv[5] : false; // STATE if( !$mode || !$app || !$user || !$type || !$state ) die( "ERROR - USAGE: notify-by-pushover.php \n\n" ); switch( $state ) { case 'WARNING': case 'UNKNOWN': $priority = PO_PRI_LOW; break; case 'OK': $priority = PO_PRI_NORMAL; break; case 'DOWN': case 'CRITICAL': $priority = PO_PRI_HIGH; break; default: $priority = PO_PRI_NORMAL; break; } curl_setopt_array( $ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => array( "token" => $app, "user" => $user, "message" => $message, "title" => "Nagios Alert - $mode - $type - $state", "priority" => $priority ) )); curl_exec($ch); curl_close($ch);