mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add port description API endpoints and documentation (#15578)
* Add port description API endpoints and documentation * Change "update_port_description" behaviour to mimic webUI behaviour * Fix code style issue * Fix another code style issue
This commit is contained in:
@@ -1107,6 +1107,62 @@ function get_port_info(Illuminate\Http\Request $request)
|
||||
});
|
||||
}
|
||||
|
||||
function update_port_description(Illuminate\Http\Request $request)
|
||||
{
|
||||
$port_id = $request->route('portid');
|
||||
$port = Port::hasAccess(Auth::user())
|
||||
->where([
|
||||
'port_id' => $port_id,
|
||||
])->first();
|
||||
if (empty($port)) {
|
||||
return api_error(400, 'Invalid port ID.');
|
||||
}
|
||||
|
||||
$data = json_decode($request->getContent(), true);
|
||||
$field = 'description';
|
||||
$description = $data[$field];
|
||||
|
||||
if (empty($description)) {
|
||||
// from update-ifalias.inc.php:
|
||||
// "Set to repoll so we avoid using ifDescr on port poll"
|
||||
$description = 'repoll';
|
||||
}
|
||||
|
||||
$port->ifAlias = $description;
|
||||
$port->save();
|
||||
|
||||
$ifName = $port->ifName;
|
||||
$device = $port->device_id;
|
||||
|
||||
if ($description == 'repoll') {
|
||||
// No description provided, clear description
|
||||
del_dev_attrib($port, 'ifName:' . $ifName); // "port" object has required device_id
|
||||
log_event("$ifName Port ifAlias cleared via API", $device, 'interface', 3, $port_id);
|
||||
|
||||
return api_success_noresult(200, 'Port description cleared.');
|
||||
} else {
|
||||
// Prevent poller from overwriting new description
|
||||
set_dev_attrib($port, 'ifName:' . $ifName, 1); // see above
|
||||
log_event("$ifName Port ifAlias set via API: $description", $device, 'interface', 3, $port_id);
|
||||
|
||||
return api_success_noresult(200, 'Port description updated.');
|
||||
}
|
||||
}
|
||||
|
||||
function get_port_description(Illuminate\Http\Request $request)
|
||||
{
|
||||
$port_id = $request->route('portid');
|
||||
$port = Port::hasAccess(Auth::user())
|
||||
->where([
|
||||
'port_id' => $port_id,
|
||||
])->first();
|
||||
if (empty($port)) {
|
||||
return api_error(400, 'Invalid port ID.');
|
||||
} else {
|
||||
return api_success($port->ifAlias, 'port_description');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \LibreNMS\Exceptions\ApiException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user