mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
Added a total vlan response in api
This commit is contained in:
@@ -449,30 +449,31 @@ function del_device()
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_vlans() {
|
function get_vlans() {
|
||||||
// This will list all vlans for a given device
|
// This will list all vlans for a given device
|
||||||
global $config;
|
global $config;
|
||||||
$app = \Slim\Slim::getInstance();
|
$app = \Slim\Slim::getInstance();
|
||||||
$router = $app->router()->getCurrentRoute()->getParams();
|
$router = $app->router()->getCurrentRoute()->getParams();
|
||||||
$hostname = $router['hostname'];
|
$hostname = $router['hostname'];
|
||||||
$status = "error";
|
$status = "error";
|
||||||
$code = 500;
|
$code = 500;
|
||||||
if(empty($hostname)) {
|
if(empty($hostname)) {
|
||||||
$output = $output = array("status" => "error", "message" => "No hostname has been provided");
|
$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));
|
|
||||||
$output = array("status" => "ok", "vlans" => array($vlans));
|
|
||||||
} else {
|
} else {
|
||||||
$code = 404;
|
require_once("../includes/functions.php");
|
||||||
$output = array("status" => "error", "Device $hostname not found");
|
$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" => array($vlans));
|
||||||
|
} else {
|
||||||
|
$code = 404;
|
||||||
|
$output = array("status" => "error", "Device $hostname not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
echo _json_encode($output);
|
||||||
echo _json_encode($output);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user