Adds API to fetch all inventory items for a given device (#10885)

Adds API to fetch all inventory items for a given device
This commit is contained in:
Albert Siersema
2019-12-17 13:49:13 +01:00
committed by Jellyfrog
parent acfc2e7c81
commit ae7eee438f
2 changed files with 16 additions and 0 deletions

View File

@@ -1209,6 +1209,21 @@ function get_inventory(\Illuminate\Http\Request $request)
}
function get_inventory_for_device(\Illuminate\Http\Request $request)
{
$hostname = $request->route('hostname');
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
return check_device_permission($device_id, function ($device_id) use ($request) {
$params = [];
$sql = 'SELECT * FROM `entPhysical` WHERE device_id = ?';
$params[] = $device_id;
$inventory = dbFetchRows($sql, $params);
return api_success($inventory, 'inventory');
});
}
function search_oxidized(\Illuminate\Http\Request $request)
{
$search_in_conf_textbox = $request->route('searchstring');

View File

@@ -133,6 +133,7 @@ Route::group(['prefix' => 'v0', 'namespace' => '\App\Api\Controllers'], function
});
Route::get('inventory/{hostname}', 'LegacyApiController@get_inventory')->name('get_inventory');
Route::get('inventory/{hostname}/all', 'LegacyApiController@get_inventory_for_device')->name('get_inventory_for_device');
// Route not found