-
-
Save smowtion/ccaae99a7adaf32f7c82abd93abf7b53 to your computer and use it in GitHub Desktop.
PHP Script to integrate UpTimeRobot with Cachet
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
<?php | |
ini_set('error_reporting', true); | |
error_reporting(E_ALL); | |
$CACHET_URL = ""; | |
$CACHET_KEY = ""; | |
$METRIC_ID = ""; | |
$UPTIMEROBOT_KEY = ""; | |
$UPTIMEROBOT_URL = "https://api.uptimerobot.com/v2/getMonitors"; | |
$UPTIMEROBOT_VARS = 'api_key='.$UPTIMEROBOT_KEY.'&format=json&response_times=1'; | |
$ch = curl_init($UPTIMEROBOT_URL); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $UPTIMEROBOT_VARS); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$UPTIME = curl_exec($ch); | |
$PARSE = json_decode($UPTIME, true); | |
if ($PARSE['stat'] != "ok") { | |
exit("Something went workng;"); | |
} | |
try { | |
$post = array( | |
'value' => $PARSE['monitors'][0]['response_times'][0]['value'], | |
'timestamp' => $PARSE['monitors'][0]['response_times'][0]['datetime'] | |
); | |
$ch = curl_init(); | |
$headers[] = 'X-Cachet-Token: '.$CACHET_KEY; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt_array($ch, array( | |
CURLOPT_URL => $CACHET_URL."/api/v1/metrics/".$METRIC_ID."/points", | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $post, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HEADER => true, | |
CURLOPT_SSL_VERIFYPEER => false | |
)); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
} | |
catch(Exception $ex){ | |
echo $ex->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment