From 9930670119011061acedc322cafaedb1e2fb1f90 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Tue, 25 Nov 2014 21:45:15 +1000 Subject: [PATCH] Tidy API entry points & doc; error if something other than image/png is asked for from portgroup graphs --- html/api_v0.php | 10 +++++----- html/includes/api_functions.inc.php | 9 ++++++++- html/pages/api-docs.inc.php | 12 ++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/html/api_v0.php b/html/api_v0.php index cae760ae5f..a80370a98d 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -29,20 +29,20 @@ $app->setName('api'); $app->group('/api', function() use ($app) { $app->group('/v0', function() use ($app) { + $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bgp $app->group('/devices', function() use ($app) { + $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/: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 }); - $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) - $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bpg + $app->group('/portgroups', function() use ($app) { + $app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');//api/v0/portgroups/$group + }); }); $app->get('/v0', 'authToken', 'show_endpoints');//api/v0 }); diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index a0a6e1a23c..2b12d4a374 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -377,9 +377,16 @@ function list_bgp() { echo _json_encode($output); } -function get_graph_by_group() { +function get_graph_by_portgroup() { global $config; $app = \Slim\Slim::getInstance(); + if ($app->request->getMediaType() != "image/png") { + // we only support PNG graphs at the moment + $app->response->setStatus(406); // Not Acceptable + echo("

Not Acceptable

\n"); + echo("

Only media type 'image/png' is provided at present

\n"); + return; + } $router = $app->router()->getCurrentRoute()->getParams(); $group = $router['group']; $vars = array(); diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index 3cf2139399..bddb64729b 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -157,14 +157,14 @@ 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"
- + - Graphs by group + Graphs by portgroup /api /v0 - /graphs/ports/$group + /portgroups/$group - JSON + image/png - curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/graphs/ports/peering"
+ curl -H "Content-Type: image/png" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/portgroups/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"
+ curl -H "Content-Type: image/png" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
"https://librenms.example.com/api/v0/portgroups/peering,transit?width=1024&height=768&from=1405457456&to=1405543856&legend=no"