Created
July 23, 2015 15:48
-
-
Save laxapple/a09b9a452567742a702b to your computer and use it in GitHub Desktop.
Digital Ocean API Implementation
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Digital Ocean API Implementation</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<meta http-equiv="Content-Style-Type" content="text/css" /> | |
</head> | |
<body> | |
| |
<table width="700px"> | |
<tr> | |
<td colspan="6">Data Center Control</td> | |
</tr> | |
<tr> | |
<td style="text-align:center">Server ID</td> | |
<td style="text-align:center">Server Name</td> | |
<td style="text-align:center">IP</td> | |
<td style="text-align:center">Status</td> | |
<td style="text-align:center">Creation Date</td> | |
<td style="text-align:center">Actions</td> | |
</tr> | |
<?php | |
/* PHP script written by W. Al Maawali | |
# (c) 2014 Founder of Eagle Eye Digital Solutions | |
# http://www.digi77.com | |
# http://www.oman0.net | |
# script starts here:*/ | |
// Add your own client keys here | |
$myClientID="xxxxxxxxxxxx"; | |
// Add your own API keys here | |
$myDOApi="xxxxxxxxxxxxxxxxxxxx"; | |
// Get current time to speed | |
$loadingtime = time(); | |
// Get your data from the API provider | |
$json = file_get_contents("https://api.digitalocean.com/v1/droplets/?client_id=$myClientID&api_key=$myDOApi"); | |
$data = json_decode($json); | |
// Get live hosts | |
$liveCounter = substr_count($json, 'status":"active'); | |
// Get Offline hosts | |
$deadCounter = substr_count($json, 'status":"off'); | |
// Sum the total | |
$counterSum=$liveCounter + $deadCounter; | |
foreach($data -> droplets as $mydata) | |
{ | |
// Set the droplet id for further actions | |
$serverid=$mydata->id; | |
?> | |
<tr> | |
<td style="text-align:center"><?php echo $mydata->id; ?></td> | |
<td style="text-align:center"><?php echo $mydata->name; ?></td> | |
<td style="text-align:center"><?php echo $mydata->ip_address; ?></td> | |
<td style="text-align:center"><?php echo $mydata->status; ?></td> | |
<td style="text-align:center"><?php echo $mydata->created_at; ?></td> | |
<td class="td_title4" style="text-align:center"><?php echo "<a href=\"https://api.digitalocean.com/droplets/$serverid/reboot/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Reboot</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/shutdown/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Shut Down</font></a> - <a href=\"https://api.digitalocean.com/droplets/$serverid/power_on/?client_id=$myClientID&api_key=$myDOApi\" target=\"_blank\"><font color=\"red\">Power On</font></a>" ?></td> | |
<?php | |
}//end for | |
?> | |
</tr> | |
<tr> | |
<td colspan="2"> | |
Online Droplets: <?php echo "<font color=\"green\">" . $liveCounter . "</font>"?><br /> | |
Offline Droplets: <?php echo "<font color=\"red\">" . $deadCounter . "</font>"?><br /> | |
Total Droplets: <?php echo "<font color=\"black\">" . $counterSum . "</font>"?><br /> | |
<?php echo "Query Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br />\n"; ?> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment