-
-
Save blueprintmrk/300cc70c38a03f862e24 to your computer and use it in GitHub Desktop.
Simple example of using PagerDuty webhooks and PHP to forward all incident state changes to an email address.
This file contains hidden or 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 threads emails based on "$status: $description on $service" so each update to each incident would start a new thread. | |
This code is unsupported by PagerDuty. | |
<?php | |
$emailAddress = "[email protected]"; | |
$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; | |
$body = "$subject\n$link\n\n$HTTP_RAW_POST_DATA"; | |
mail($emailAddress, $subject, $body); | |
} | |
//PagerDuty doesn't keep the output of this script. | |
?> |
This file contains hidden or 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 threads emails based on "$status on $service" so each service will have its own thread. | |
It also only sends emails for incidents that have been resolved. | |
This code is unsupported by PagerDuty. | |
<?php | |
$emailAddress = "[email protected]"; | |
$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 on $service"; | |
$link = $webhook->data->incident->html_url; | |
$body = "$subject\n$link\n\n$HTTP_RAW_POST_DATA"; | |
if($status == "Resolved") { | |
mail($emailAddress, $subject, $body); | |
} | |
} | |
//PagerDuty doesn't keep the output of this script. | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment