Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
5.6 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* Linux.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2023 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\OS;
Entity Physical discovery: Rewrite to modern style (#16289) * Initial entity-physical code * Split out Entity-MIB trait * Cisco Cellular inventory * Fix bad test data * alfo80hd - we now include all entPhysical entries * Correct aos7 test data * Add entPhysicalClass as last resort for label in ui * aos add previously filtered data * Fixup arista-eos data * Update ariast_eos data * Arris, clean garbage in Rev fields * Aruba Instant custom inventory ported * ArubaOS CX add vendor type mib * aviat-wtm test data refresh * axos add shelf fix data fields a bit * ciena-rls * ciena-sds * Skip cimc for now... no test data * Cisco updates * Comware data update * Update dnos * Clean Edgeos garbage, make code from Arris shareable * Relaxed ifIndex match, some devices cheat and send back static strings instead of formatted OIDs * Regex refinement and updated edgeos with new clean data * Update edgeswitch data * Update eltex-mes21xx data * eltex-mes23xx * Guess at eltex-mes24xx since there is no test data * Update eurostor, fix firmware version * Apply fixes from StyleCI * fixes * Update fortigate data * Update fortiweb, ftd, and fusion * Update linux LSI * Fix hexToAscii null removal with different seperator handling * icotera add final snmprec data to avoid snmpsim bug * Update IOS data * Update mrv-od * Add junos translation * Generic data updates n-r * ruijie workaround snmpsim bug * Port saf-cfm * Recode Schleifenbauer, and fix entPhysicalIndex values * SmartAX fixes * sm-os and tait-infra93 * timos inventory was not right, fix it up * ubiquoss-pon * VRP, has custom data collection on top of normal adapt port ifIndex lookup to handle it * VRP exceeded the string length specified in ENTITY-MIB... * data updates * Final data update and code cleanup * Apply fixes from StyleCI * Lint fixes * Add missing SnmpResponse->pluck() code * Update db_schema.yaml * Fix bad test data * Another instant-on update * oops * Remove some unused code # Conflicts: # includes/html/pages/device/overview.inc.php --------- Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
2024-08-21 01:12:09 -05:00
use App\Models\EntPhysical;
use Illuminate\Support\Collection;
use LibreNMS\Interfaces\Discovery\VminfoDiscovery;
use LibreNMS\OS\Traits\VminfoLibvirt;
use LibreNMS\OS\Traits\VminfoVmware;
Entity Physical discovery: Rewrite to modern style (#16289) * Initial entity-physical code * Split out Entity-MIB trait * Cisco Cellular inventory * Fix bad test data * alfo80hd - we now include all entPhysical entries * Correct aos7 test data * Add entPhysicalClass as last resort for label in ui * aos add previously filtered data * Fixup arista-eos data * Update ariast_eos data * Arris, clean garbage in Rev fields * Aruba Instant custom inventory ported * ArubaOS CX add vendor type mib * aviat-wtm test data refresh * axos add shelf fix data fields a bit * ciena-rls * ciena-sds * Skip cimc for now... no test data * Cisco updates * Comware data update * Update dnos * Clean Edgeos garbage, make code from Arris shareable * Relaxed ifIndex match, some devices cheat and send back static strings instead of formatted OIDs * Regex refinement and updated edgeos with new clean data * Update edgeswitch data * Update eltex-mes21xx data * eltex-mes23xx * Guess at eltex-mes24xx since there is no test data * Update eurostor, fix firmware version * Apply fixes from StyleCI * fixes * Update fortigate data * Update fortiweb, ftd, and fusion * Update linux LSI * Fix hexToAscii null removal with different seperator handling * icotera add final snmprec data to avoid snmpsim bug * Update IOS data * Update mrv-od * Add junos translation * Generic data updates n-r * ruijie workaround snmpsim bug * Port saf-cfm * Recode Schleifenbauer, and fix entPhysicalIndex values * SmartAX fixes * sm-os and tait-infra93 * timos inventory was not right, fix it up * ubiquoss-pon * VRP, has custom data collection on top of normal adapt port ifIndex lookup to handle it * VRP exceeded the string length specified in ENTITY-MIB... * data updates * Final data update and code cleanup * Apply fixes from StyleCI * Lint fixes * Add missing SnmpResponse->pluck() code * Update db_schema.yaml * Fix bad test data * Another instant-on update * oops * Remove some unused code # Conflicts: # includes/html/pages/device/overview.inc.php --------- Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
2024-08-21 01:12:09 -05:00
use LibreNMS\Util\StringHelpers;
use SnmpQuery;
class Linux extends Shared\Unix implements VminfoDiscovery
{
// NOTE: Only Linux specific stuff should go here, most things should be in Unix
use VminfoLibvirt, VminfoVmware {
VminfoLibvirt::discoverVminfo as discoverLibvirtVminfo;
VminfoVmware::discoverVmInfo as discoverVmwareVminfo;
}
public function discoverVmInfo(): Collection
{
$vms = $this->discoverLibvirtVminfo();
if ($vms->isNotEmpty()) {
return $vms;
}
return $this->discoverVmwareVminfo();
}
Entity Physical discovery: Rewrite to modern style (#16289) * Initial entity-physical code * Split out Entity-MIB trait * Cisco Cellular inventory * Fix bad test data * alfo80hd - we now include all entPhysical entries * Correct aos7 test data * Add entPhysicalClass as last resort for label in ui * aos add previously filtered data * Fixup arista-eos data * Update ariast_eos data * Arris, clean garbage in Rev fields * Aruba Instant custom inventory ported * ArubaOS CX add vendor type mib * aviat-wtm test data refresh * axos add shelf fix data fields a bit * ciena-rls * ciena-sds * Skip cimc for now... no test data * Cisco updates * Comware data update * Update dnos * Clean Edgeos garbage, make code from Arris shareable * Relaxed ifIndex match, some devices cheat and send back static strings instead of formatted OIDs * Regex refinement and updated edgeos with new clean data * Update edgeswitch data * Update eltex-mes21xx data * eltex-mes23xx * Guess at eltex-mes24xx since there is no test data * Update eurostor, fix firmware version * Apply fixes from StyleCI * fixes * Update fortigate data * Update fortiweb, ftd, and fusion * Update linux LSI * Fix hexToAscii null removal with different seperator handling * icotera add final snmprec data to avoid snmpsim bug * Update IOS data * Update mrv-od * Add junos translation * Generic data updates n-r * ruijie workaround snmpsim bug * Port saf-cfm * Recode Schleifenbauer, and fix entPhysicalIndex values * SmartAX fixes * sm-os and tait-infra93 * timos inventory was not right, fix it up * ubiquoss-pon * VRP, has custom data collection on top of normal adapt port ifIndex lookup to handle it * VRP exceeded the string length specified in ENTITY-MIB... * data updates * Final data update and code cleanup * Apply fixes from StyleCI * Lint fixes * Add missing SnmpResponse->pluck() code * Update db_schema.yaml * Fix bad test data * Another instant-on update * oops * Remove some unused code # Conflicts: # includes/html/pages/device/overview.inc.php --------- Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
2024-08-21 01:12:09 -05:00
public function discoverEntityPhysical(): Collection
{
return $this->discoverLsiMegaRaidInventory();
}
private function discoverLsiMegaRaidInventory(): Collection
{
$inventory = new Collection;
$controller_array = SnmpQuery::hideMib()->walk('LSI-MegaRAID-SAS-MIB::adapterInfoTable')->table(1);
if (empty($controller_array)) {
return $inventory; // no controllers, skip the rest.
}
foreach ($controller_array as $controller) {
$inventory->push(new EntPhysical([
'entPhysicalIndex' => 200 + $controller['adapterID-AIT'],
'entPhysicalParentRelPos' => $controller['adapterID-AIT'] ?? -1,
'entPhysicalDescr' => '/C' . $controller['adapterID-AIT'],
'entPhysicalClass' => 'port',
'entPhysicalModelName' => $controller['productName'],
'entPhysicalSerialNum' => $controller['serialNo'],
'entPhysicalContainedIn' => '0',
'entPhysicalVendorType' => $controller['adapterVendorID'],
'entPhysicalFirmwareRev' => $controller['firmwareVersion'],
]));
}
$bbus = SnmpQuery::hideMib()->walk('LSI-MegaRAID-SAS-MIB::bbuTable')->table(1);
foreach ($bbus as $bbu) {
$inventory->push(new EntPhysical([
'entPhysicalIndex' => 1000 + $bbu['pdIndex'],
'entPhysicalClass' => 'charge',
'entPhysicalModelName' => $bbu['deviceName'],
'entPhysicalSerialNum' => $bbu['serialNumber'],
'entPhysicalContainedIn' => 200 + $bbu['adpID'],
'entPhysicalIsFRU' => 'true',
'entPhysicalFirmwareRev' => $bbu['firmwareStatus'],
]));
}
$enclosures = SnmpQuery::hideMib()->walk('LSI-MegaRAID-SAS-MIB::enclosureTable')->table(1);
foreach ($enclosures as $enclosure) {
$inventory->push(new EntPhysical([
'entPhysicalIndex' => 210 + $enclosure['deviceId'],
'entPhysicalVendorType' => $enclosure['slotCount'],
'entPhysicalParentRelPos' => $enclosure['deviceId'] ?? -1,
'entPhysicalDescr' => '/C' . ($enclosure['adapterID-ET'] ?? '0') . '/E' . $enclosure['deviceId'],
'entPhysicalClass' => 'chassis',
'entPhysicalModelName' => $enclosure['productID'],
'entPhysicalSerialNum' => $enclosure['enclSerialNumber'],
'entPhysicalContainedIn' => 200 + $enclosure['adapterID-ET'],
'entPhysicalMfgName' => $enclosure['vendorID'],
'entPhysicalFirmwareRev' => $this->handleHex($enclosure['enclFirmwareVersion']),
]));
}
$drives = SnmpQuery::hideMib()->walk('LSI-MegaRAID-SAS-MIB::physicalDriveTable')->table(1);
foreach ($drives as $drive) {
$enclDeviceId = $drive['enclDeviceId'] ?? 0;
$inventory->push(new EntPhysical([
'entPhysicalIndex' => 500 + $enclDeviceId * 100 + $drive['physDevID'],
'entPhysicalParentRelPos' => $drive['slotNumber'] ?? -1,
'entPhysicalDescr' => '/C' . ($drive['adpID-PDT'] ?? '0') . '/E' . $enclDeviceId . '/S' . ($drive['slotNumber'] ?? '0'),
'entPhysicalClass' => 'drive',
'entPhysicalModelName' => $drive['pdProductID'] ?? null,
'entPhysicalSerialNum' => $drive['pdSerialNumber'] ?? null,
'entPhysicalContainedIn' => 210 + $enclDeviceId,
'entPhysicalIsFRU' => 'true',
'entPhysicalFirmwareRev' => $drive['pdFwversion'] ?? null, // missing
]));
}
return $inventory;
}
private function handleHex(string $string): string
{
$string = str_replace("\n", '', $string);
if (StringHelpers::isHex($string)) {
$ascii = StringHelpers::hexToAscii($string, ' ');
return preg_split('/[^ -~]/', $ascii)[0] ?? $ascii;
}
return $string;
}
}