Add API endpoint to get service graphs (#15138)

* Add API endpoint to get service graphs

* Docs: Add missing title to get_graph_by_service
This commit is contained in:
richard-ririe
2023-07-20 04:19:43 +01:00
committed by GitHub
parent 7cdb81b2e9
commit 4c8e5fc783
3 changed files with 51 additions and 0 deletions

View File

@@ -564,6 +564,38 @@ Output:
Output is an image.
### `get_graph_by_service`
Get the graph for a service
Route: `/api/v0/devices/:hostname/services/:service_id/graphs/:datasource`
- hostname can be either the device hostname or id
- service id
- datasource is the name of the service datasource
Input:
- from: This is the date you would like the graph to start - See
[http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html](http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html)
for more information.
- to: This is the date you would like the graph to end - See
[http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html](http://oss.oetiker.ch/rrdtool/doc/rrdgraph.en.html)
for more information.
- width: The graph width, defaults to 1075.
- height: The graph height, defaults to 300.
Example:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/localhost/35/graphs/loss
```
Output:
Output is an image.
### `get_port_graphs`
Get a list of ports for a particular device.

View File

@@ -248,6 +248,24 @@ function get_graph_generic_by_hostname(Request $request)
});
}
function get_graph_by_service(Request $request)
{
$vars = [];
$vars['id'] = $request->route('id');
$vars['type'] = 'service_graph';
$vars['ds'] = $request->route('datasource');
$hostname = $request->route('hostname');
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$device = device_by_id_cache($device_id);
$vars['device'] = $device['device_id'];
return check_device_permission($device_id, function () use ($request, $vars) {
return api_get_graph($request, $vars);
});
}
function list_locations()
{
$locations = dbFetchRows('SELECT `locations`.* FROM `locations` WHERE `locations`.`location` IS NOT NULL');

View File

@@ -119,6 +119,7 @@ Route::prefix('v0')->namespace('\App\Api\Controllers')->group(function () {
// 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');
Route::get('{hostname}/services/{id}/graphs/{datasource}', 'LegacyApiController@get_graph_by_service')->name('get_graph_by_service');
Route::get('{hostname}/{type}', 'LegacyApiController@get_graph_generic_by_hostname')->name('get_graph_generic_by_hostname');
Route::get('', 'LegacyApiController@list_devices')->name('list_devices');