type); // DEBUG if ($event->secret != 'topsecret!!') { // The post did not contain the secret code configured for my webhook. Fail the request http_response_code(401); fprintf($fp, "Invalid secret code (%s) received\n", $event->secret); // DEBUG exit; } if ($event->type == 'alert') { // Got an alert webhook $alert = $event->data; date_default_timezone_set('America/Toronto'); fprintf($fp, "Got Alert Event: %s\n%s\n", date('r'), print_r($alert, true)); // DEBUG date_default_timezone_set('UTC'); } http_response_code(200); exit; // End of Mainline // Helper Functions // Function to provide informative error message if the json decode fails. function get_json_error() { switch (json_last_error()) { case JSON_ERROR_NONE: return false; break; case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: return 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: return 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: return 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: return 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; } return 'Unknown error'; }