Last active
November 22, 2019 02:12
-
-
Save ryanhoskin/7951269 to your computer and use it in GitHub Desktop.
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
Sample PHP code to accept PagerDuty webhooks and send out notifications by email on state changes. | |
For more information, see http://developer.pagerduty.com/documentation/rest/webhooks | |
This example sends emails to the assigned user for all status changes except resolved. Resolved incidents will email the user who last changed the incident status. | |
This code is unsupported by PagerDuty. | |
<?php | |
$messages = json_decode($HTTP_RAW_POST_DATA); // alternately, try file_get_contents('php://input'); | |
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; | |
$subject = "$status: $description on $service"; | |
$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"; | |
mail($emailAddress, $subject, $body); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment