Snippets

Martin Wimpress Caxton WebHook for StatusCake

Created by Martin Wimpress last modified
<?php
// Reference
//  * https://www.statuscake.com/kb/knowledge-base/how-to-use-the-web-hook-url/
//  * https://caxton.herokuapp.com/#api

$statuscake_username = "your_sc_username";
$statuscake_apikey = "your_sc_apikey";

$caxton_api = 'https://caxton.herokuapp.com/api/send';
$caxton_token = 'your_caxton_token';

//Santise GET/POST variables from StatusCake
$ip = filter_var($_REQUEST['IP'], FILTER_VALIDATE_IP);
$status = filter_var($_REQUEST['Status'], FILTER_SANITIZE_STRING);
$statuscode = filter_var($_REQUEST['StatusCode'], FILTER_SANITIZE_STRING);
$tags = filter_var($_REQUEST['Tags'], FILTER_SANITIZE_STRING);
$token = filter_var($_REQUEST['Token'], FILTER_SANITIZE_STRING);
$url = filter_var($_REQUEST['URL'], FILTER_SANITIZE_URL);

//Validate that this came from StatusCake
if ( $token != md5($statuscake_username . $statuscake_apikey) ) {
    exit();
}

$fields = array(
    'appname' => "StatusCake",
    'token' => urlencode($caxton_token),
    'url' => $url,
    'message' => urlencode($url . ' is ' . $status . ': ' . $statuscode),
    'tag' => $tags,
);

//url-ify the data for the POST
$fields_string = NULL;
foreach($fields as $key=>$value) {
    $fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $caxton_api);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

?>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.