Skip to content

Instantly share code, notes, and snippets.

Last active November 22, 2019 02:12
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Sample PHP code to accept PagerDuty webhooks and send out notifications by email on state changes.
For more information, see
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.
$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