Added new API route to obtain available ports for a device

This commit is contained in:
laf
2014-11-30 15:45:10 +00:00
parent f25311587a
commit 1a3f5504d0
2 changed files with 22 additions and 0 deletions

View File

@ -419,3 +419,24 @@ function get_graph_by_portgroup() {
$app->response->headers->set('Content-Type', 'image/png');
require("includes/graphs/graph.inc.php");
}
function get_port_graphs() {
global $config;
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];
if(isset($_GET['columns'])) {
$columns = $_GET['columns'];
} else {
$columns = 'ifName';
}
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$ports = dbFetchRows("SELECT $columns FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `ifIndex` ASC", array($device_id));
$total_ports = count($ports);
$output = array("status" => "ok", "err-msg" => '', "count" => $total_ports, "ports" => $ports);
$app->response->setStatus('200');
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}