<?php
require '/usr/src/aws.phar';
# Setup
$debug = false;
$key = getenv("NOTIFY_PARAMETER_1");
$secret = getenv("NOTIFY_PARAMETER_2");
if ($key == false || $secret == false) {
echo "API key or secret are missing\n";
exit(1);
}
$number = getenv("NOTIFY_CONTACTPAGER");
if ($number == false) {
echo "Pager number is missing\n";
exit(1);
}
# Variables exported by check_mk
$what = getenv('NOTIFY_WHAT');
$type = getenv('NOTIFY_NOTIFICATIONTYPE');
$toi = getenv('NOTIFY_CONTACTPAGER');
$host = getenv('NOTIFY_HOSTALIAS');
$service = '';
$status = '';
$output = '';
$author = '';
$comment = '';
$message = '';
# Determine type of alert and build message
if ($type == 'ACKNOWLEDGEMENT') {
if ($what == 'SERVICE') {
$service = getenv('NOTIFY_SERVICEDESC');
$author = getenv('NOTIFY_NOTIFICATIONAUTHOR');
$comment = getenv('NOTIFY_NOTIFICATIONCOMMENT');
$message = "$service on $host ack'd by $author: $comment";
} else {
$author = getenv('NOTIFY_NOTIFICATIONAUTHOR');
$comment = getenv('NOTIFY_NOTIFICATIONCOMMENT');
$message = "$host ack'd by $author: $comment";
}
} else {
if ($what == 'SERVICE') {
$service = getenv('NOTIFY_SERVICEDESC');
$status = getenv('NOTIFY_SERVICESTATE');
$output = getenv('NOTIFY_SERVICEOUTPUT');
$message = "$service on $host is $status: $output";
} else {
$status = getenv('NOTIFY_HOSTSTATE');
$output = getenv('NOTIFY_HOSTOUTPUT');
$message = "$host is $status: $output";
}
}
# Send the message to SNS
$credentials = new Aws\Credentials\Credentials($key, $secret);
$sns = new Aws\Sns\SnsClient([
'credentials' => $credentials,
'version' => 'latest',
'region' => 'us-east-1'
]);
$result = $sns->publish([
'Message' => substr($message, 0, 160),
'PhoneNumber' => $number,
]);
if ($debug == true) {
echo $result;
}