Created
January 15, 2014 21:37
-
-
Save ryanhoskin/8445196 to your computer and use it in GitHub Desktop.
PagerDuty webhooks email script for Nagios.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Nagios alerts with a custom subject line that includes the HOSTNAME, SERVICESTATE, SERVICEDESC, HOSTSTATE and PagerDuty incident status fields. | |
$messages = json_decode($HTTP_RAW_POST_DATA); | |
if ($messages) foreach ($messages->messages as $webhook) { | |
$service = $webhook->data->incident->service->name; | |
$description = $webhook->data->incident->trigger_summary_data->subject." ".$webhook->data->incident->trigger_summary_data->description; | |
$status = $webhook->data->incident->status; | |
$link = $webhook->data->incident->html_url; | |
$emailAddress = ($webhook->type == "incident.resolve" ? $webhook->data->incident->last_status_change_by->email : $webhook->data->incident->assigned_to_user->email); | |
$body = "PagerDuty Update\n\nAn incident has been $status.\n\nDetails: $description on service $service\n\nClick here for more details: $link\n"; | |
$subject = "[" . $webhook->data->incident->trigger_summary_data->HOSTNAME . "/" | |
. $webhook->data->incident->trigger_summary_data->SERVICESTATE . "/" | |
. $webhook->data->incident->trigger_summary_data->SERVICEDESC . "/" | |
. $webhook->data->incident->trigger_summary_data->HOSTSTATE . "] " | |
. $webhook->data->incident->status; | |
$success = mail($emailAddress, $subject, $body); | |
if (!$success) { | |
mail($emailAddress, "Mail failed", "Mail failed"); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment