Added new route to display graphs for peering,transit and core

This commit is contained in:
laf
2014-11-12 23:05:47 +00:00
parent 62532e652f
commit 3522f66f69
3 changed files with 70 additions and 0 deletions

View File

@ -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', '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->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->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->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->delete('/devices/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices (json data needs to be passed)

View File

@ -376,3 +376,42 @@ function list_bgp() {
$app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output); 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 = " (";
foreach (explode(",", $group) as $type)
{
$type_where .= " $or `port_descr_type` = ?";
$or = "OR";
$type_param[] = $type;
}
$type_where .= ") ";
$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");
}

View File

@ -157,6 +157,34 @@ if ($_SESSION['userlevel'] == '10')
<tr> <tr>
<td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/ports/eth0"</code></td> <td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/ports/eth0"</code></td>
</tr> </tr>
<a name="graphs_group"></a>
<tr class="success">
<td colspan="5"><strong>Graphs by group</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v0</td>
<td>/graphs/ports/$group</td>
<td>
<ul class="list-unstyled">
<li>$group = transit,peering,core (or multiple separated by comma)</li>
<li>$width = the width of the graph to be returned</li>
<li>$height = the height of the graph to be returned</li>
<li>$from = the from date/time of the graph (unix timestamp)</li>
<li>$to = the to date/time of the graph (unix timestamp)</li>
<li>$legend = Enable or disable the graph legend (yes/no)</li>
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/graphs/ports/peering"</code></td>
</tr>
<tr>
<td colspan="5"><code>curl -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/graphs/ports/peering,transit?width=1024&height=768&from=1405457456&to=1405543856&legend=no"</code></td>
</tr>
<a name="list"></a> <a name="list"></a>
<tr class="success"> <tr class="success">
<td colspan="5"><strong>List</strong></td> <td colspan="5"><strong>List</strong></td>