mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add FDB table vendor search drop down (#15072)
* Add vendor search and related functions * Add OUIDB cache for vendor lookup * Add vendor drop down * appy style CI changes * Apply style CI and lint changes * more styleCI changes * update type hinting * Edit mac_oui cache lock name and function * Update MAC OUI message during daily * Use DB for vendor lookup * New vendor_oui table migration * New MAC OUI to database function * Update readbleOUI to use DB rather than cache * Make StyleCI changes * styleCI tweak * Remove lock release to allow refresh timer * change migration name to match table * add schema dump * update schema * styleCI tweak
This commit is contained in:
40
app/Http/Controllers/Table/FdbTablesController.php
Normal file → Executable file
40
app/Http/Controllers/Table/FdbTablesController.php
Normal file → Executable file
@@ -31,6 +31,7 @@ use App\Models\PortsFdb;
|
||||
use App\Models\Vlan;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\Rewrite;
|
||||
use LibreNMS\Util\Url;
|
||||
@@ -91,6 +92,10 @@ class FdbTablesController extends TableController
|
||||
return $query->whereIn('ports_fdb.mac_address', $this->findMacs($search));
|
||||
case 'description':
|
||||
return $query->whereIntegerInRaw('ports_fdb.port_id', $this->findPorts($search));
|
||||
case 'vendor':
|
||||
$vendor_ouis = $this->ouisFromVendor($search);
|
||||
|
||||
return $this->findPortsByOui($vendor_ouis, $query);
|
||||
default:
|
||||
return $query->where(function ($query) use ($search, $mac_search) {
|
||||
$query->where('ports_fdb.mac_address', 'like', $mac_search)
|
||||
@@ -296,4 +301,39 @@ class FdbTablesController extends TableController
|
||||
|
||||
return $this->macCountCache[$port->port_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OUI list for a specific vendor
|
||||
*
|
||||
* @param string $vendor
|
||||
* @return array
|
||||
*/
|
||||
protected function ouisFromVendor($vendor)
|
||||
{
|
||||
$matching_ouis = DB::table('vendor_ouis')
|
||||
->where('vendor', 'LIKE', '%' . $vendor . '%')
|
||||
->pluck('oui')
|
||||
->toArray();
|
||||
|
||||
return $matching_ouis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all port ids from vendor OUIs
|
||||
*
|
||||
* @param array $vendor_ouis
|
||||
* @return Builder
|
||||
*/
|
||||
protected function findPortsByOui($vendor_ouis, $query)
|
||||
{
|
||||
$condition = '';
|
||||
foreach ($vendor_ouis as $oui) {
|
||||
$clean_oui = str_replace(':', '', $oui);
|
||||
$condition .= " ports_fdb.mac_address LIKE '$clean_oui%' OR";
|
||||
}
|
||||
$condition = rtrim($condition, ' OR');
|
||||
$query->whereRaw($condition);
|
||||
|
||||
return $query; // Return the query builder instance
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user