Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a maintenance boolean in API results. #15904

Merged
merged 6 commits into from Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions doc/API/Devices.md
Expand Up @@ -1102,6 +1102,31 @@ Output:
}
```

### `device_under_maintenance`

Get the current maintenance status of a device.

Route: `/api/v0/devices/:hostname/maintenance`

Input:

-

Example:

```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/devices/localhost/maintenance
```

Output:

```json
{
"status": "ok",
"is_under_maintenance": true
}
```

### `maintenance_device`

Set a device into maintenance mode.
Expand Down
27 changes: 27 additions & 0 deletions includes/html/api_functions.inc.php
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Expand Up @@ -123,6 +123,7 @@
Route::get('{hostname}/port_stack', 'LegacyApiController@get_port_stack')->name('get_port_stack');
Route::get('{hostname}/components', 'LegacyApiController@get_components')->name('get_components');
Route::get('{hostname}/groups', 'LegacyApiController@get_device_groups')->name('get_device_groups_device');
Route::get('{hostname}/maintenance', 'LegacyApiController@device_under_maintenance')->name('device_under_maintenance');
// consumes the route below, but passes to it when detected
Route::get('{hostname}/ports/{ifname}', 'LegacyApiController@get_port_stats_by_port_hostname')->name('get_port_stats_by_port_hostname')->where('ifname', '.*');
Route::get('{hostname}/ports/{ifname}/{type}', 'LegacyApiController@get_graph_by_port_hostname')->name('get_graph_by_port_hostname');
Expand Down