Skip to content
Permalink
Browse files

Added resources/sensors api call to list all sensors (librenms#9837)

* Added resources/sensors api call to list all sensors

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>

* Use global read permission check

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>

* fix typo

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>

* fix another typo

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>

* Use laravel style for call

Signed-off-by: Misha Komarovskiy <zombah@gmail.com>
  • Loading branch information...
zombah authored and funzoneq committed Mar 19, 2019
1 parent a2a6b92 commit 7fc8228eb9516c4e49382745d20266fc1f1610ff
Showing with 70 additions and 0 deletions.
  1. +52 −0 doc/API/Devices.md
  2. +17 −0 html/includes/api_functions.inc.php
  3. +1 −0 html/legacy_api_v0.php
@@ -758,6 +758,58 @@ Output:
}
```

### `list_sensors`

Get a list of all Sensors.

Route: `/api/v0/resources/sensors`

Input:

-

Example:
```curl
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/resources/sensors
```

Output:
```json
{
"status": "ok",
"sensors": [
{
"sensor_id": 218810,
"sensor_deleted": 0,
"sensor_class": "dbm",
"device_id": 136,
"poller_type": "snmp",
"sensor_oid": ".1.3.6.1.4.1.2636.3.60.1.1.1.1.7.919",
"sensor_index": "tx-919",
"sensor_type": "junos",
"sensor_descr": "xe-2/1/4 Tx Power",
"group": null,
"sensor_divisor": 100,
"sensor_multiplier": 1,
"sensor_current": -1.81,
"sensor_limit": 2,
"sensor_limit_warn": 0.5,
"sensor_limit_low": -9.7,
"sensor_limit_low_warn": -8.21,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": "919",
"entPhysicalIndex_measured": "ports",
"lastupdate": "2019-02-18 02:47:09",
"sensor_prev": -1.77,
"user_func": null
},
...
],
"count": 100
}
```

### `list_devices`

Return a list of devices.
@@ -2024,6 +2024,23 @@ function get_link()
}
function list_sensors()
{
check_is_read();
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$sensors = \App\Models\Sensor::hasAccess(Auth::user())->get();
$total_sensors = $sensors->count();
if ($total_sensors == 0) {
api_error(404, 'Sensors do not exist');
}
api_success($sensors, 'sensors');
}
function list_ip_addresses()
{
check_is_read();
@@ -188,6 +188,7 @@ function () use ($app) {
$app->get('/links', 'authToken', 'list_links')->name('list_links');
$app->get('/links/:id', 'authToken', 'get_link')->name('get_link');
$app->get('/locations', 'authToken', 'list_locations')->name('list_locations');
$app->get('/sensors', 'authToken', 'list_sensors')->name('list_sensors');
$app->get('/vlans', 'authToken', 'list_vlans')->name('list_vlans');
$app->group(
'/ip',

0 comments on commit 7fc8228

Please sign in to comment.
You can’t perform that action at this time.