
Notifications
Server Push Notifications for Android
Description:
This “Addon” (Changes) lets you push all Nagios notifications to your Android device running an App called “Server Push Notifications” that also supports Tasker.
Current Version
1.0.0
Last Release Date
2014-03-08
Compatible With
- Nagios 3.x
Owner
Website
Download URL
License
GPL
Project Notes
To send push notifications to the Android App you need to apply these changes. Example using PHP but you can also use a shell script etc. In this tutorial i use Debian Squeeze so path and files could be different to your Linux distribution
1) Edit /etc/nagios3/comands.cfg and insert the following code under the "NOTIFICATION COMMANDS" section
# 'server-push-notifications' comannd definition
define command{
command_name server-push-notifications
command_line php /etc/nagios3/send.php $NOTIFICATIONTYPE$ $SERVICEDESC$ "***** Nagios *****nnHost: $HOSTALIAS$nAddress: $HOSTADDRESS$nState: $SERVICESTATE$nnDate/Time: $LONGDATETIME$nnAdditional Info:nn$SERVICEOUTPUT$"
}
2) Create a new file /etc/nagios3/send.php with the following content
notification = array(
"username"=>"",
"password"=>"",
"category"=>"",
"encrypted"=>"",
"flags"=>"",
"service"=>"",
"title"=>"",
"message"=>""
);
}
}
$pushmsg = new notify_obj();
$pushmsg->notification["username"] = "YOUR USERNAME"; // Change this to the username in your app
$pushmsg->notification["password"] = "YOUR PASSWORD"; // Change this to the password set in your app
$pushmsg->notification["category"] = "1";
$pushmsg->notification["encrypted"] = "0";
$pushmsg->notification["flags"] = "0";
$pushmsg->notification["service"] = htmlentities($argv[2], ENT_QUOTES, "UTF-8");
$pushmsg->notification["title"] = htmlentities($argv[1], ENT_QUOTES, "UTF-8");
$pushmsg->notification["message"] = htmlentities($argv[3], ENT_QUOTES, "UTF-8");
$jsonString = json_encode($pushmsg);
// Send JSON Object to Push Server via Curl
$ch = curl_init();
// Replace SERVERNAME with the one mentioned in the settings of the APP.
curl_setopt($ch, CURLOPT_URL, "https://SERVERNAME/pushjson.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // See API docs in forum to activate!
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
curl_setopt($ch, CURLOPT_TIMEOUT, '10'); // wait max 10s to complete
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '8' ); // wait max 8s to connect
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
)
);
$result = curl_exec($ch);
curl_close($ch);
// Check $result for any status codes coming back from the server if you need
?>
3) Save the file and assign correct permissions so Nagios can execute it later
chown nagios:nagios /etc/nagios3/send.php
chmod 755 /etc/nagios3/send.php
4) Edit /etc/nagios3/conf.d/contacts_nagios2.cfg and configure the default contact like below. Please take note for this example I removed any email notification from the default contact for better readability. For more options see the Nagios Manual.
define contact{
contact_name root
alias Root
service_notification_period 24x7
service_notification_options w,u,c,r,f
service_notification_commands server-push-notifications
host_notification_period 24x7
host_notification_options d,u,f,r,s
host_notification_commands server-push-notifications
}
5) Save the file and restart Nagios
/etc/init.d/nagios3 restart
Page Sections
Project Stats
Rating
1 (1)
Favorites
0
Views
32,843