mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Enabling general search for ports, devices, and more (#11571)
* Search engine for device, through API * reviewed port search through API * fixed die * Update api_functions.inc.php * Update api_functions.inc.php * Update api_functions.inc.php * Update api_functions.inc.php * Update api.php * Update api.php * Update Ports.md Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -44,6 +44,52 @@ Output:
|
||||
}
|
||||
```
|
||||
|
||||
### `search_ports`
|
||||
|
||||
Search for ports matching the query.
|
||||
|
||||
Route: `/api/v0/ports/search/:search`
|
||||
|
||||
- search string to search in fields: ifAlias, ifDescr, and ifName
|
||||
|
||||
Input:
|
||||
|
||||
-
|
||||
|
||||
Example:
|
||||
|
||||
```curl
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/ports/search/lo
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "ok",
|
||||
"ports": [
|
||||
{
|
||||
"device_id": 1,
|
||||
"port_id": 1,
|
||||
"ifIndex": 1,
|
||||
"ifName": "lo"
|
||||
},
|
||||
{
|
||||
"device_id": 2,
|
||||
"port_id": 3,
|
||||
"ifIndex": 1,
|
||||
"ifName": "lo"
|
||||
},
|
||||
{
|
||||
"device_id": 3,
|
||||
"port_id": 5,
|
||||
"ifIndex": 1,
|
||||
"ifName": "lo"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### `get_port_info`
|
||||
|
||||
Get all info for a particular port.
|
||||
|
@@ -355,7 +355,6 @@ function list_devices(\Illuminate\Http\Request $request)
|
||||
return api_success($devices, 'devices');
|
||||
}
|
||||
|
||||
|
||||
function add_device(\Illuminate\Http\Request $request)
|
||||
{
|
||||
// This will add a device using the data passed encoded with json
|
||||
@@ -937,6 +936,25 @@ function get_port_info(\Illuminate\Http\Request $request)
|
||||
});
|
||||
}
|
||||
|
||||
function search_ports(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$search = $request->route('search');
|
||||
$value = "%$search%";
|
||||
$ports = \App\Models\Port::hasAccess(Auth::user())
|
||||
->select(['device_id', 'port_id', 'ifIndex', 'ifName'])
|
||||
->where('ifAlias', 'like', $value)
|
||||
->orWhere('ifDescr', 'like', $value)
|
||||
->orWhere('ifName', 'like', $value)
|
||||
->orderBy('ifName')
|
||||
->get();
|
||||
|
||||
if ($ports->isEmpty()) {
|
||||
return api_error(404, 'No ports found');
|
||||
}
|
||||
|
||||
return api_success($ports, 'ports');
|
||||
}
|
||||
|
||||
function get_all_ports(\Illuminate\Http\Request $request)
|
||||
{
|
||||
$columns = $request->get('columns', 'port_id, ifName');
|
||||
|
@@ -113,6 +113,7 @@ Route::group(['prefix' => 'v0', 'namespace' => '\App\Api\Controllers'], function
|
||||
Route::group(['prefix' => 'ports'], function () {
|
||||
Route::get('{portid}', 'LegacyApiController@get_port_info')->name('get_port_info');
|
||||
Route::get('{portid}/ip', 'LegacyApiController@get_port_ip_addresses')->name('get_port_ip_info');
|
||||
Route::get('search/{search}', 'LegacyApiController@search_ports')->name('search_ports');
|
||||
Route::get(null, 'LegacyApiController@get_all_ports')->name('get_all_ports');
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user