From 55f4870b9189181d60f7630febd2dbdc4dc239bf Mon Sep 17 00:00:00 2001 From: Misha Komarovskiy Date: Tue, 19 Mar 2019 09:22:39 -0400 Subject: [PATCH] Added resources/sensors api call to list all sensors (#9837) * Added resources/sensors api call to list all sensors Signed-off-by: Misha Komarovskiy * Use global read permission check Signed-off-by: Misha Komarovskiy * fix typo Signed-off-by: Misha Komarovskiy * fix another typo Signed-off-by: Misha Komarovskiy * Use laravel style for call Signed-off-by: Misha Komarovskiy --- doc/API/Devices.md | 52 +++++++++++++++++++++++++++++ html/includes/api_functions.inc.php | 17 ++++++++++ html/legacy_api_v0.php | 1 + 3 files changed, 70 insertions(+) diff --git a/doc/API/Devices.md b/doc/API/Devices.md index ff4f2fd8a7..884b409a89 100644 --- a/doc/API/Devices.md +++ b/doc/API/Devices.md @@ -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. diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 71bbb9f94d..101de454c2 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -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(); diff --git a/html/legacy_api_v0.php b/html/legacy_api_v0.php index 86851f70d9..3b5b801525 100644 --- a/html/legacy_api_v0.php +++ b/html/legacy_api_v0.php @@ -188,6 +188,7 @@ $app->group( $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',