Skip to content

Instantly share code, notes, and snippets.

@StewartJohn
Created February 25, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StewartJohn/74af47b7fe7438aa0c06 to your computer and use it in GitHub Desktop.
Save StewartJohn/74af47b7fe7438aa0c06 to your computer and use it in GitHub Desktop.
Check the Reclaim API status of a server and publish it to WordPress
<?php
$response = wp_remote_get( 'http://status.reclaimhosting.com/api/v1/components' ); //use HTTP GET to retrieve server status information from the API
if( is_array($response) ) {
$body = $response['body']; // use the content
$a = json_decode($body, true); //parse the json from the HTTP GET
$serverName1 = $a[data][7][name]; //Set a variable called serverName1 equal to the name attribute for the 7th item in the Server List
$status1 = $a[data][7][status_name]; //Set a variable called status1 equal to the status_name attribute for the 7th item in the Server List
$serverName2 = $a[data][15][name]; //Set a variable called serverName2 equal to the name attribute for the 15th item in the Server List
$status2 = $a[data][15][status_name]; //Set a variable called status2 equal to the status_name attribute for the 15th item in the Server List
if( $status1=="Operational") {
echo $serverName1, ": ", $status1, " ", "<img src='https://create.ou.edu/wp-content/uploads/2016/02/2000px-MW-Icon-CheckMark.svg_-e1456421962246.png'>", PHP_EOL; //Print the information for the first server to the screen
} else {
echo $serverName1, ": ", $status1, " ", "<img src='https://create.ou.edu/wp-content/uploads/2016/02/420px-X_mark.svg_-4-e1456422394441.png'>", PHP_EOL; //Print the information for the first server to the screen
}
if( $status2=="Operational") {
echo $serverName2, ": ", $status2, " ", "<img src='https://create.ou.edu/wp-content/uploads/2016/02/2000px-MW-Icon-CheckMark.svg_-e1456421962246.png'>"; //Print the information for the second server to the screen
} else {
echo $serverName2, ": ", $status2, " ", "<img src='https://create.ou.edu/wp-content/uploads/2016/02/420px-X_mark.svg_-4-e1456422394441.png'>"; //Print the information for the second server to the screen
}
} else {
echo "Error communicating with Reclaim Hosting Status API";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment