Skip to content

Instantly share code, notes, and snippets.

@jacobgardiner
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobgardiner/6efb730e54dfb1daa9de to your computer and use it in GitHub Desktop.
Save jacobgardiner/6efb730e54dfb1daa9de to your computer and use it in GitHub Desktop.
nagios config for sms alerts
define contact{
contact_name johndoe
alias jdoe
service_notification_period 24x7
host_notification_period 24x7
service_notification_options u,c,r
host_notification_options d,r
service_notification_commands notify-via-sms
host_notification_commands notify-via-sms
pager 0400111222
}
# 'notify-via-sms' command definition
define command{
command_name notify-via-sms
command_line $USER1$/sms_alert.php "$NOTIFICATIONTYPE$-$NOTIFICATIONAUTHOR$: $HOSTALIAS$ $SERVICEDESC$ is $SERVICESTATE$ at $TIME$: $SERVICEOUTPUT$" $CONTACTPAGER$
}
<?php
#var_dump($argv);
define('SMS_API_URL', 'https://api.clickatell.com/http/sendmsg');
define('SMS_API_ID', '');
define('SMS_USERNAME', '');
define('SMS_PASSWORD', '');
define('SMS_FROM', 'Nagios');
$ch = curl_init(SMS_API_URL);
curl_setopt($ch, CURLOPT_POST, true);
$post_data = array(
'user' => SMS_USERNAME,
'password' => SMS_PASSWORD,
'api_id' => SMS_API_ID,
'to' => "$argv[2]",
'from' => SMS_FROM,
'text' => "$argv[1]",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$sms_response=curl_exec($ch);
//need to perform email or alternative messaging to let us know the attempt to send the sms failed, this may be due to insufficient credit, change in their API and etc... for the time being this works
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment