Skip to content

Commit

Permalink
Merge pull request #355 from laf/issue-laf-89
Browse files Browse the repository at this point in the history
Added new API route for retrieving available device graphs
  • Loading branch information
paulgear committed Dec 1, 2014
2 parents f253115 + 4d7b4ef commit 3e9b670
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions html/api_v0.php
Expand Up @@ -34,6 +34,7 @@
$app->delete('/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices/$hostname
$app->get('/:hostname', 'authToken', 'get_device')->name('get_device');//api/v0/devices/$hostname
$app->get('/:hostname/vlans', 'authToken', 'get_vlans')->name('get_vlans');//api/v0/devices/$hostname/vlans
$app->get('/:hostname/graphs', 'authToken', 'get_graphs')->name('get_graphs');//api/v0/devices/$hostname/graphs
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type
$app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName
$app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname')->name('get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type
Expand Down
25 changes: 25 additions & 0 deletions html/includes/api_functions.inc.php
Expand Up @@ -419,3 +419,28 @@ function get_graph_by_portgroup() {
$app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php");
}

function get_graphs() {
global $config;
$code = 200;
$status = 'ok';
$message = '';
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];

// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$graphs = array();
$graphs[] = array('desc' => 'Poller Time', 'name' => 'device_poller_perf');
$graphs[] = array('desc' => 'Ping Response', 'name' => 'device_ping_perf');
foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY graph", array($device_id)) as $graph) {
$desc = $config['graph_types']['device'][$graph['graph']]['descr'];
$graphs[] = array('desc' => $desc, 'name' => $graph['graph']);
}
$total_graphs = count($graphs);
$output = array("status" => "$status", "err-msg" => $message, "count" => $total_graphs, "graphs" => $graphs);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}

0 comments on commit 3e9b670

Please sign in to comment.