示例#1
0
 public function api($name)
 {
     switch ($name) {
         case 'postback':
         case 'postbacks':
             return new Api\PostBacks($this);
         default:
             return parent::api($name);
     }
 }
示例#2
0
<?php

namespace serverdensity;

use DateTime;
require __DIR__ . '/vendor/autoload.php';
use serverdensity\Client;
include "config.php";
$client = new Client();
$client->authenticate($TOKEN);
$currTime = time();
$allDevices = $client->api('devices')->all();
$allServices = $client->api('services')->all();
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
		<meta name="description" content="">
		<meta name="author" content="">
		<title><?php 
echo $brandName;
?>
 Status Page</title>
		<!-- Latest compiled and minified CSS -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
		<!-- Optional theme -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous">
 /**
  * Send a DELETE request with Json encoded parameters
  * @param string $path           Request path
  * @param array  $parameters     POST parameters to be json encoded
  * @param array  $requestHeaders Request headers
  */
 protected function HTTPdelete($path, array $parameters = array(), $requestHeaders = array())
 {
     $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders);
     return ResponseMediator::getContent($response);
 }
示例#4
0
$DEVICE = $argv[1];
if (isset($_SERVER["SDTOKEN"])) {
    $TOKEN = $_SERVER["SDTOKEN"];
} else {
    $TOKEN = '';
    // you can hardcore the API Token here
}
if (empty($TOKEN)) {
    die("Server Density API Token missing.");
}
// configure time period for the report
$end_date = time();
// now
$start_date = $end_date - 60 * 60 * 24 * 31;
// last 31 days
$client = new Client();
$client->authenticate($TOKEN);
// find deviceId
$filter = array("name" => $DEVICE, "type" => "device");
$fields = array("name", "type", "_id");
$device = $client->api('devices')->search($filter, $fields);
$device_id = $device[0]['_id'];
// available metrics
$available = $client->api('metrics')->available($device_id, $start_date, $end_date);
//print_r($available);
// NETWORK TRAFFIC
$table = array();
$filter = array('networkTraffic' => ['eth0' => ['rxMBitS', 'txMBitS']]);
$metrics = $client->api('metrics')->metrics($device_id, $filter, $start_date, $end_date);
//print_r($metrics);
$data = $client->api('metrics')->formatMetrics($metrics);