mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
MAC Vendor OUI use scheduler (#15187)
* MAC Vendor OUI use scheduler Add command to update `lnms maintenance:fetch-ouis` Show vendor column in tables if mac_oui.enabled is set to true Improve scheduler validation handle non-standard install directories and systems without systemd Add index to table to improve speed and improve mac->vendor lookup speed Scheduled weekly with random wait to prevent stampeding herd issues for upstream drop oui update from daily * MAC Vendor OUI use scheduler Add command to update `lnms maintenance:fetch-ouis` Show vendor column in tables if mac_oui.enabled is set to true * Lint fixes and better prefix detection * update schema file
This commit is contained in:
@@ -1163,83 +1163,6 @@ function q_bridge_bits2indices($hex_data)
|
||||
return $indices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate Mac OUI Cache
|
||||
*/
|
||||
function mac_oui_to_database()
|
||||
{
|
||||
// Refresh timer
|
||||
$mac_oui_refresh_int_min = 86400 * rand(7, 11); // 7 days + a random number between 0 and 4 days
|
||||
|
||||
$lock = Cache::lock('vendor_oui_db_refresh', $mac_oui_refresh_int_min); // We want to refresh after at least $mac_oui_refresh_int_min
|
||||
|
||||
if (Config::get('mac_oui.enabled') !== true) {
|
||||
echo 'Mac OUI integration disabled' . PHP_EOL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($lock->get()) {
|
||||
echo 'Storing Mac OUI in the database' . PHP_EOL;
|
||||
try {
|
||||
$mac_oui_url = 'https://www.wireshark.org/download/automated/data/manuf';
|
||||
//$mac_oui_url = 'https://gitlab.com/wireshark/wireshark/-/raw/master/manuf';
|
||||
//$mac_oui_url_mirror = 'https://raw.githubusercontent.com/wireshark/wireshark/master/manuf';
|
||||
|
||||
echo ' -> Downloading ...' . PHP_EOL;
|
||||
$get = \LibreNMS\Util\Http::client()->get($mac_oui_url);
|
||||
echo ' -> Processing CSV ...' . PHP_EOL;
|
||||
$csv_data = $get->body();
|
||||
|
||||
// Process each line of the CSV data
|
||||
foreach (explode("\n", $csv_data) as $csv_line) {
|
||||
unset($oui);
|
||||
$entry = str_getcsv($csv_line, "\t");
|
||||
|
||||
$length = strlen($entry[0]);
|
||||
$prefix = strtolower(str_replace(':', '', $entry[0]));
|
||||
$vendor = $entry[1];
|
||||
|
||||
if (is_array($entry) && count($entry) >= 2 && $length == 8) {
|
||||
// We have a standard OUI xx:xx:xx
|
||||
$oui = $prefix;
|
||||
} elseif (is_array($entry) && count($entry) >= 2 && $length == 20) {
|
||||
// We have a smaller range (xx:xx:xx:X or xx:xx:xx:xx:X)
|
||||
if (substr($prefix, -2) == '28') {
|
||||
$oui = substr($prefix, 0, 7);
|
||||
} elseif (substr($prefix, -2) == '36') {
|
||||
$oui = substr($prefix, 0, 9);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($oui)) {
|
||||
// Store the OUI for the vendor in the database
|
||||
DB::table('vendor_ouis')->insert([
|
||||
'vendor' => $vendor,
|
||||
'oui' => $oui,
|
||||
]);
|
||||
|
||||
echo "Adding $oui for $vendor" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'Error processing Mac OUI:' . PHP_EOL;
|
||||
echo 'Exception: ' . get_class($e) . PHP_EOL;
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
|
||||
$lock->release(); // We did not succeed, so we'll try again next time
|
||||
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
echo 'Not able to acquire lock, skipping mac database update' . PHP_EOL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to generate PeeringDB Cache
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user