Merge remote-tracking branch 'laf/issue-laf-90'

Conflicts:
	html/api_v0.php
	html/includes/api_functions.inc.php
This commit is contained in:
Paul Gear
2014-12-01 20:27:50 +00:00
3 changed files with 45 additions and 0 deletions

View File

@ -36,6 +36,7 @@ $app->group('/api', function() use ($app) {
$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', 'authToken', 'get_port_graphs')->name('get_port_graphs');//api/v0/devices/$hostname/ports
$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
});

View File

@ -444,3 +444,24 @@ function get_graphs() {
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
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);
}

View File

@ -296,6 +296,29 @@ if ($_SESSION['userlevel'] == '10')
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/bgp"</code></td>
</tr>
<tr class="success">
<td colspan="5"><strong>List ports for a device</strong></td>
</tr>
<tr>
<td>/api</td>
<td>/v0</td>
<td>/devices/$hostname/ports</td>
<td>
<ul class="list-unstyled">
<li>hostname = the hostname to list vlans for</li>
<li>columns = the columns to return in the response</li>
</ul>
</td>
<td>
JSON
</td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/ports"</code></td>
</tr>
<tr>
<td colspan="5"><code>curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost/ports?columns=ifDescr,ifName"</code></td>
</tr>
</table>
</div>
</div>