diff --git a/html/api_v0.php b/html/api_v0.php index 346829c534..cae760ae5f 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -36,6 +36,9 @@ $app->group('/api', function() use ($app) { $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 }); + $app->group('/graphs', function() use ($app) { + $app->get('/ports/:group', 'authToken', 'get_graph_by_group')->name('get_graph_by_group');//api/v0/graphs/ports/$group + }); $app->get('/devices', 'authToken', 'list_devices')->name('list_devices');//api/v0/devices $app->post('/devices', 'authToken', 'add_device')->name('add_device');//api/v0/devices (json data needs to be passed) $app->delete('/devices/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices (json data needs to be passed) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 5a0725f65b..a0a6e1a23c 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -376,3 +376,46 @@ function list_bgp() { $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } + +function get_graph_by_group() { + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $group = $router['group']; + $vars = array(); + if(!empty($_GET['from'])) + { + $vars['from'] = $_GET['from']; + } + if(!empty($_GET['to'])) + { + $vars['to'] = $_GET['to']; + } + $vars['width'] = $_GET['width'] ?: 1075; + $vars['height'] = $_GET['height'] ?: 300; + $auth = "1"; + $type_where = " ("; + $or = ''; + $type_param = array(); + foreach (explode(",", $group) as $type) + { + $type_where .= " $or `port_descr_type` = ?"; + $or = "OR"; + $type_param[] = $type; + } + + $type_where .= ") "; + $if_list = ''; + $seperator = ''; + $ports = dbFetchRows("SELECT * FROM `ports` as I, `devices` AS D WHERE $type_where AND I.device_id = D.device_id ORDER BY I.ifAlias", $type_param); + foreach ($ports as $port) + { + $if_list .= $seperator . $port['port_id']; + $seperator = ","; + } + unset($seperator); + $vars['type'] = "multiport_bits_separate"; + $vars['id'] = $if_list; + $app->response->headers->set('Content-Type', 'image/png'); + require("includes/graphs/graph.inc.php"); +} diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index 5c6bb18df5..3cf2139399 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -157,6 +157,34 @@ if ($_SESSION['userlevel'] == '10')
curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/devices/localhost/ports/eth0"curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/graphs/ports/peering"curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/graphs/ports/peering,transit?width=1024&height=768&from=1405457456&to=1405543856&legend=no"