Created
January 19, 2015 01:28
-
-
Save lippytak/50872c663465ed02080d to your computer and use it in GitHub Desktop.
Make Pingometer events trigger StatusPageIO incidents
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 | |
// connection settings | |
// define('PINGOMETER_MONITOR_ID', ''); | |
define('STATUSPAGE_API_KEY', $_ENV["STATUSPAGE_API_KEY"]); | |
define('STATUSPAGE_PAGE_ID', $_ENV["STATUSPAGE_PAGE_ID"]); | |
define('STATUSPAGE_BASE_URI', 'https://api.statuspage.io/v1'); | |
define('STATUSPAGE_DEFAULT_INCIDENT_NAME', 'Unknown Issue'); | |
define('STATUSPAGE_DEFAULT_INCIDENT_STATUS', 'investigating'); | |
// validations | |
$result = false; | |
if (isset($_POST['monitor_id']) && !empty($_POST['monitor_id']) && isset($_POST['monitor_status'])) { | |
// if ($_POST['monitor_id'] == PINGOMETER_MONITOR_ID && $_POST['monitor_status'] == 0) { | |
if ($_POST['monitor_status'] == 0) { | |
$result = true; | |
} | |
} | |
// process webhook | |
if ($result) { | |
// statuspage api | |
$statuspage_ch = curl_init(sprintf("%s/pages/%s/incidents.json", STATUSPAGE_BASE_URI, STATUSPAGE_PAGE_ID)); | |
curl_setopt($statuspage_ch, CURLOPT_HTTPHEADER, array("Authorization: OAuth " . STATUSPAGE_API_KEY, "Expect: 100-continue")); | |
curl_setopt($statuspage_ch, CURLOPT_POST, true); | |
curl_setopt($statuspage_ch, CURLOPT_RETURNTRANSFER, 1); | |
$postparams = array("incident[name]" => STATUSPAGE_DEFAULT_INCIDENT_NAME, "incident[status]" => STATUSPAGE_DEFAULT_INCIDENT_STATUS); | |
curl_setopt($statuspage_ch, CURLOPT_POSTFIELDS, $postparams); | |
$statuspage_result = curl_exec($statuspage_ch); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment