mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Added resources/sensors api call to list all sensors (#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>
This commit is contained in:
		
				
					committed by
					
						
						Tony Murray
					
				
			
			
				
	
			
			
			
						parent
						
							00a1185980
						
					
				
				
					commit
					55f4870b91
				
			@@ -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 @@ $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',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user