Added API to feed into Oxidized

This commit is contained in:
laf
2015-05-07 00:32:58 +01:00
parent 7f5a64967e
commit f5d02ab18d
3 changed files with 46 additions and 0 deletions

View File

@ -17,6 +17,7 @@
- [`get_graph_by_port_hostname`](#api-route-9) - [`get_graph_by_port_hostname`](#api-route-9)
- [`list_devices`](#api-route-10) - [`list_devices`](#api-route-10)
- [`add_device`](#api-route-11) - [`add_device`](#api-route-11)
- [`list_oxidized`](#api-route-21)
- [`routing`](#api-routing) - [`routing`](#api-routing)
- [`list_bgp`](#api-route-1) - [`list_bgp`](#api-route-1)
- [`switching`](#api-switching) - [`switching`](#api-switching)
@ -395,6 +396,36 @@ Output:
} }
``` ```
### <a name="api-route-21">Function: `list_oxidized`</a> [`top`](#top)
List devices for use with Oxidized.
Route: /api/v0/oxidized
Input (JSON):
-
Examples:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/oxidized
```
Output:
```text
[
{
"hostname": "localhost",
"os": "linux"
},
{
"hostname": "otherserver",
"os": "linux"
}
]
```
## <a name="api-routing">`Routing`</a> [`top`](#top) ## <a name="api-routing">`Routing`</a> [`top`](#top)
### <a name="api-route-1">Function: `list_bgp`</a> [`top`](#top) ### <a name="api-route-1">Function: `list_bgp`</a> [`top`](#top)

View File

@ -29,6 +29,7 @@ $app->setName('api');
$app->group('/api', function() use ($app) { $app->group('/api', function() use ($app) {
$app->group('/v0', function() use ($app) { $app->group('/v0', function() use ($app) {
$app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bgp $app->get('/bgp', 'authToken', 'list_bgp')->name('list_bgp');//api/v0/bgp
$app->get('/oxidized', 'authToken', 'list_oxidized')->name('list_oxidized');
$app->group('/devices', function() use ($app) { $app->group('/devices', function() use ($app) {
$app->delete('/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices/$hostname $app->delete('/:hostname', 'authToken', 'del_device')->name('del_device');//api/v0/devices/$hostname
$app->get('/:hostname', 'authToken', 'get_device')->name('get_device');//api/v0/devices/$hostname $app->get('/:hostname', 'authToken', 'get_device')->name('get_device');//api/v0/devices/$hostname

View File

@ -699,3 +699,17 @@ function get_inventory() {
$app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output); echo _json_encode($output);
} }
function list_oxidized() {
// return details of a single device
$app = \Slim\Slim::getInstance();
$app->response->headers->set('Content-Type', 'application/json');
$devices = array();
foreach (dbFetchRows("SELECT hostname,os FROM `devices` WHERE `status`='1'") as $device) {
$devices[] = $device;
}
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($devices);
}