mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add support for a maintenance boolean in API results. (#15904)
* Add support for a maintenance boolean in API results. If a device is under maintenance, it would be nice to see that from the API. This can help drive other automation workflows where LibreNMS forms a cornerstone in the management source of truth. * Revert changes made by VSCode formatting. * Revert two more formatting changes. * Create a new API endpoint for GETing maintenance status. This uses the same endpoint name as for setting a device to maintenance but with a GET verb. --------- Co-authored-by: Joe Clarke <jclarke@cisco.com>
This commit is contained in:
@@ -538,6 +538,33 @@ function maintenance_device(Illuminate\Http\Request $request)
|
||||
}
|
||||
}
|
||||
|
||||
function device_under_maintenance(Illuminate\Http\Request $request)
|
||||
{
|
||||
// return whether or not a device is in an active maintenance window
|
||||
|
||||
$hostname = $request->route('hostname');
|
||||
|
||||
if (empty($hostname)) {
|
||||
return api_error(400, 'No hostname has been provided to get maintenance status');
|
||||
}
|
||||
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
$model = null;
|
||||
if ($device_id) {
|
||||
$model = DeviceCache::get((int) $device_id);
|
||||
}
|
||||
|
||||
if (! $model) {
|
||||
return api_error(404, "Device $hostname not found");
|
||||
}
|
||||
|
||||
return check_device_permission($device_id, function () use ($model) {
|
||||
$maintenance = $model->isUnderMaintenance() ?? false;
|
||||
|
||||
return api_success($maintenance, 'is_under_maintenance');
|
||||
});
|
||||
}
|
||||
|
||||
function device_availability(Illuminate\Http\Request $request)
|
||||
{
|
||||
// return availability per device
|
||||
|
||||
Reference in New Issue
Block a user