mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Merge pull request #300 from laf/issue-laf-44
Added a route to the API that will get vlans for a given device
This commit is contained in:
@@ -31,6 +31,7 @@ $app->group('/api', function() use ($app) {
|
|||||||
$app->group('/v0', function() use ($app) {
|
$app->group('/v0', function() use ($app) {
|
||||||
$app->group('/devices', function() use ($app) {
|
$app->group('/devices', function() use ($app) {
|
||||||
$app->get('/:hostname', 'authToken', 'get_device');//api/v0/devices/$hostname
|
$app->get('/:hostname', 'authToken', 'get_device');//api/v0/devices/$hostname
|
||||||
|
$app->get('/:hostname/vlans', 'authToken', 'get_vlans');//api/v0/devices/$hostname/vlans
|
||||||
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type
|
$app->get('/:hostname/:type', 'authToken', 'get_graph_generic_by_hostname');//api/v0/devices/$hostname/$type
|
||||||
$app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName
|
$app->get('/:hostname/ports/:ifname', 'authToken', 'get_port_stats_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName
|
||||||
$app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type
|
$app->get('/:hostname/ports/:ifname/:type', 'authToken', 'get_graph_by_port_hostname');//api/v0/devices/$hostname/ports/$ifName/$type
|
||||||
|
|||||||
@@ -447,3 +447,34 @@ function del_device()
|
|||||||
$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_vlans() {
|
||||||
|
// This will list all vlans for a given device
|
||||||
|
global $config;
|
||||||
|
$app = \Slim\Slim::getInstance();
|
||||||
|
$router = $app->router()->getCurrentRoute()->getParams();
|
||||||
|
$hostname = $router['hostname'];
|
||||||
|
$code = 500;
|
||||||
|
if(empty($hostname)) {
|
||||||
|
$output = $output = array("status" => "error", "message" => "No hostname has been provided");
|
||||||
|
} else {
|
||||||
|
require_once("../includes/functions.php");
|
||||||
|
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||||
|
$device = null;
|
||||||
|
if ($device_id) {
|
||||||
|
// save the current details for returning to the client on successful delete
|
||||||
|
$device = device_by_id_cache($device_id);
|
||||||
|
}
|
||||||
|
if ($device) {
|
||||||
|
$vlans = dbFetchRows("SELECT vlan_vlan,vlan_domain,vlan_name,vlan_type,vlan_mtu FROM vlans WHERE `device_id` = ?", array($device_id));
|
||||||
|
$total_vlans = count($vlans);
|
||||||
|
$output = array("status" => "ok", "count" => $total_vlans, "vlans" => $vlans);
|
||||||
|
} else {
|
||||||
|
$code = 404;
|
||||||
|
$output = array("status" => "error", "Device $hostname not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$app->response->setStatus($code);
|
||||||
|
$app->response->headers->set('Content-Type', 'application/json');
|
||||||
|
echo _json_encode($output);
|
||||||
|
}
|
||||||
|
|||||||
@@ -231,6 +231,25 @@ if ($_SESSION['userlevel'] == '10')
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="5"><code>curl -X DELETE -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost"</code></td>
|
<td colspan="5"><code>curl -X DELETE -H "Content-Type: application/json" -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \<br/> "https://librenms.example.com/api/v0/devices/localhost"</code></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="success">
|
||||||
|
<td colspan="5"><strong>List VLANs</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>/api</td>
|
||||||
|
<td>/v0</td>
|
||||||
|
<td>/devices/$hostname/vlans</td>
|
||||||
|
<td>
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li>hostname = the hostname to list vlans for</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/vlans"</code></td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user