diff --git a/LibreNMS/Device/WirelessSensor.php b/LibreNMS/Device/WirelessSensor.php index 14d65c94ec..c3ba0b687a 100644 --- a/LibreNMS/Device/WirelessSensor.php +++ b/LibreNMS/Device/WirelessSensor.php @@ -253,7 +253,7 @@ class WirelessSensor extends Sensor * @param int $channel * @return int */ - public static function channelToFrequency($channel) + public static function channelToFrequency($channel): int { $channels = [ 1 => 2412, @@ -300,6 +300,6 @@ class WirelessSensor extends Sensor 165 => 5825, ]; - return $channels[$channel]; + return $channels[$channel] ?? 0; } } diff --git a/LibreNMS/Model.php b/LibreNMS/Model.php index 7d899997cc..17f2d2790a 100644 --- a/LibreNMS/Model.php +++ b/LibreNMS/Model.php @@ -145,9 +145,13 @@ abstract class Model $params ); - $this->$key = $row[$key]; + if (is_array($row)) { + $this->$key = $row[$key]; - return $row; + return $row; + } + + return null; } /** diff --git a/LibreNMS/Modules/Xdsl.php b/LibreNMS/Modules/Xdsl.php index 4bc3f317d1..cdf1e7ab14 100644 --- a/LibreNMS/Modules/Xdsl.php +++ b/LibreNMS/Modules/Xdsl.php @@ -136,7 +136,7 @@ class Xdsl implements Module // trim SnmpAdminStrings foreach ($this->trimAdminString as $oid) { - $portAdsl->$oid = rtrim($portAdsl->$oid, '.'); + $portAdsl->$oid = rtrim($portAdsl->$oid ?? '', '.'); } $portAdsl->port_id = $os->ifIndexToId($ifIndex); diff --git a/LibreNMS/OS/Airos.php b/LibreNMS/OS/Airos.php index ccfbca7979..8499b8a2f9 100644 --- a/LibreNMS/OS/Airos.php +++ b/LibreNMS/OS/Airos.php @@ -75,8 +75,8 @@ class Airos extends OS implements // fix having an extra - in the middle after the decimal point $regex = '/(-?\d+)\.-?(\d+)/'; - $location->lng = (float) preg_replace($regex, '$1.$2', $location->getAttributes()['lng']); - $location->lat = (float) preg_replace($regex, '$1.$2', $location->getAttributes()['lat']); + $location->lng = (float) preg_replace($regex, '$1.$2', $location->getAttributes()['lng'] ?? ''); + $location->lat = (float) preg_replace($regex, '$1.$2', $location->getAttributes()['lat'] ?? ''); return $location; } @@ -242,7 +242,7 @@ class Airos extends OS implements 'airos', $index, 'RSSI: Chain ' . str_replace('1.', '', $index), - $entry['ubntRadioRssi.1'] + $entry['ubntRadioRssi'] ); } diff --git a/LibreNMS/OS/AirosAfLtu.php b/LibreNMS/OS/AirosAfLtu.php index 7595a1b7f4..047a87003a 100644 --- a/LibreNMS/OS/AirosAfLtu.php +++ b/LibreNMS/OS/AirosAfLtu.php @@ -97,8 +97,8 @@ class AirosAfLtu extends OS implements $oids = snmpwalk_cache_oid($this->getDeviceArray(), 'afLTUStaRxPowerLevel1', $oids, 'UBNT-AFLTU-MIB', null, '-OteQUsb'); foreach ($oids as $index => $entry) { - $sensors[] = new WirelessSensor('quality', $this->getDeviceId(), '.1.3.6.1.4.1.41112.1.10.1.4.1.9.' . $index, 'airos-af-ltu-level-rx-chain-0', 1, 'Signal Level Chain 0', $entry['afLTUStaRxPower0']); //UBNT-AFLTU-MIB::afLTUStaRxPowerLevel0 - $sensors[] = new WirelessSensor('quality', $this->getDeviceId(), '.1.3.6.1.4.1.41112.1.10.1.4.1.10.' . $index, 'airos-af-ltu-level-rx-chain-1', 1, 'Signal Level Chain 1', $entry['afLTUStaRxPower1']); //UBNT-AFLTU-MIB::afLTUStaRxPowerLevel1 + $sensors[] = new WirelessSensor('quality', $this->getDeviceId(), '.1.3.6.1.4.1.41112.1.10.1.4.1.9.' . $index, 'airos-af-ltu-level-rx-chain-0', 1, 'Signal Level Chain 0', $entry['afLTUStaRxPowerLevel0']); //UBNT-AFLTU-MIB::afLTUStaRxPowerLevel0 + $sensors[] = new WirelessSensor('quality', $this->getDeviceId(), '.1.3.6.1.4.1.41112.1.10.1.4.1.10.' . $index, 'airos-af-ltu-level-rx-chain-1', 1, 'Signal Level Chain 1', $entry['afLTUStaRxPowerLevel1']); //UBNT-AFLTU-MIB::afLTUStaRxPowerLevel1 break; } diff --git a/LibreNMS/OS/Allied.php b/LibreNMS/OS/Allied.php index f124973d5c..6ba0a8a574 100644 --- a/LibreNMS/OS/Allied.php +++ b/LibreNMS/OS/Allied.php @@ -101,9 +101,9 @@ class Allied extends OS implements OSDiscovery $hardware = $e; } - $device->version = str_replace(['"', ','], '', $version ?? null); - $device->features = str_replace('"', '', $features ?? null); - $device->hardware = str_replace('"', '', $hardware ?? null); + $device->version = isset($version) ? str_replace(['"', ','], '', $version) : null; + $device->features = isset($features) ? str_replace('"', '', $features) : null; + $device->hardware = isset($hardware) ? str_replace('"', '', $hardware) : null; $device->serial = $serial ?? null; } } diff --git a/LibreNMS/OS/ArubaInstant.php b/LibreNMS/OS/ArubaInstant.php index 19168727d6..4499612cff 100644 --- a/LibreNMS/OS/ArubaInstant.php +++ b/LibreNMS/OS/ArubaInstant.php @@ -262,9 +262,9 @@ class ArubaInstant extends OS implements return $sensors; } - protected function decodeChannel($channel) + protected function decodeChannel($channel): int { - return $channel & 255; // mask off the channel width information + return cast_number($channel) & 255; // mask off the channel width information } /** @@ -303,7 +303,7 @@ class ArubaInstant extends OS implements $snmp_data = snmp_get_multi_oid($this->getDeviceArray(), $oids); foreach ($oids as $id => $oid) { - $data[$id] = $snmp_data[$oid]; + $data[$id] = $snmp_data[$oid] ?? null; } } else { // version is lower than 8.4.0.0 diff --git a/LibreNMS/OS/Shared/Cisco.php b/LibreNMS/OS/Shared/Cisco.php index 9d57744cb1..c1ac8fdc4a 100755 --- a/LibreNMS/OS/Shared/Cisco.php +++ b/LibreNMS/OS/Shared/Cisco.php @@ -237,14 +237,14 @@ class Cisco extends OS implements } if (isset($entry['cpmCPUTotalPhysicalIndex'])) { - $descr = $this->getCacheByIndex('entPhysicalName', 'ENTITY-MIB')[$entry['cpmCPUTotalPhysicalIndex']]; + $descr = $this->getCacheByIndex('entPhysicalName', 'ENTITY-MIB')[$entry['cpmCPUTotalPhysicalIndex']] ?? null; } if (empty($descr)) { $descr = "Processor $index"; } - if (is_array($entry['cpmCore5min'])) { + if (isset($entry['cpmCore5min']) && is_array($entry['cpmCore5min'])) { // This CPU has data per individual core foreach ($entry['cpmCore5min'] as $core_index => $core_usage) { $processors[] = Processor::discover( diff --git a/LibreNMS/OS/Traits/BridgeMib.php b/LibreNMS/OS/Traits/BridgeMib.php index 599075c312..d742dd5b95 100644 --- a/LibreNMS/OS/Traits/BridgeMib.php +++ b/LibreNMS/OS/Traits/BridgeMib.php @@ -67,9 +67,10 @@ trait BridgeMib return new Collection; } - \Log::debug('VLAN: ' . ($vlan ?: 1) . " Bridge: {$stp['BRIDGE-MIB::dot1dBaseBridgeAddress.0']} DR: {$stp['BRIDGE-MIB::dot1dStpDesignatedRoot.0']}"); $bridge = Rewrite::macToHex($stp['BRIDGE-MIB::dot1dBaseBridgeAddress.0'] ?? ''); $drBridge = Rewrite::macToHex($stp['BRIDGE-MIB::dot1dStpDesignatedRoot.0'] ?? ''); + \Log::debug('VLAN: ' . ($vlan ?: 1) . " Bridge: {$bridge} DR: {$drBridge}"); + $instance = new \App\Models\Stp([ 'vlan' => $vlan, 'rootBridge' => $bridge == $drBridge ? 1 : 0, diff --git a/LibreNMS/OS/Traits/HostResources.php b/LibreNMS/OS/Traits/HostResources.php index 12f2112aba..e3ecb898a4 100644 --- a/LibreNMS/OS/Traits/HostResources.php +++ b/LibreNMS/OS/Traits/HostResources.php @@ -87,7 +87,7 @@ trait HostResources foreach ($hrProcessorLoad as $index => $usage) { $usage_oid = '.1.3.6.1.2.1.25.3.3.1.2.' . $index; - $descr = $hrDeviceDescr[$index]; + $descr = $hrDeviceDescr[$index] ?? null; if (! is_numeric($usage)) { continue; diff --git a/LibreNMS/Util/Number.php b/LibreNMS/Util/Number.php index 04065aed80..40cf74c0f0 100644 --- a/LibreNMS/Util/Number.php +++ b/LibreNMS/Util/Number.php @@ -90,14 +90,14 @@ class Number * Cast string to int or float. * Returns 0 if string is not numeric * - * @param string $number + * @param mixed $number * @return float|int */ public static function cast($number) { if (! is_numeric($number)) { // match pre-PHP8 behavior - if (! preg_match('/^-?\d+(\.\d+)?/', $number, $matches)) { + if (! preg_match('/^-?\d+(\.\d+)?/', $number ?? '', $matches)) { return 0; } $number = $matches[0]; diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index c6e4e2787e..02ec1cb78d 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -861,6 +861,11 @@ function discovery_process(&$valid, $os, $sensor_class, $pre_cache) foreach ($discovery[$sensor_class]['data'] as $data) { $tmp_name = $data['oid']; + + if (! isset($pre_cache[$tmp_name])) { + continue; + } + $raw_data = (array) $pre_cache[$tmp_name]; d_echo("Data $tmp_name: "); diff --git a/includes/discovery/route.inc.php b/includes/discovery/route.inc.php index c427825b9b..25784c391e 100644 --- a/includes/discovery/route.inc.php +++ b/includes/discovery/route.inc.php @@ -39,6 +39,8 @@ $create_row = []; $update_row = []; $delete_row = []; +$mixed = []; + //store timestamp so all update / creation will be synced on same timestamp $update_timestamp = dbFetchRows('select now() as now')[0]['now']; @@ -175,42 +177,43 @@ if (isset($ipForwardNb['0']['inetCidrRouteNumber']) && $ipForwardNb['0']['inetCi // IP-FORWARD-MIB with ipCidrRouteTable in case ipCidrRouteTable has more entries than inetCidrRouteTable (Some older routers) -if (isset($ipForwardNb['0']['ipCidrRouteNumber']) && $ipForwardNb['0']['ipCidrRouteNumber'] > $ipForwardNb['0']['inetCidrRouteNumber'] && $ipForwardNb['0']['ipCidrRouteNumber'] < $max_routes) { - //device uses only ipCidrRoute and not inetCidrRoute - d_echo('IP FORWARD MIB (without inetCidr support)'); - $ipCidrTable = SnmpQuery::walk('IP-FORWARD-MIB::ipCidrRouteTable')->table(6); - echo 'ipCidrRouteTable '; - // we need to translate the values to inetCidr structure; - //d_echo($ipCidrTable); - foreach ($ipCidrTable as $inetCidrRouteDest => $next1) { - foreach ($next1 as $ipCidrRouteMask => $next2) { - foreach ($next2 as $ipCidrRouteTos => $next3) { - foreach ($next3 as $inetCidrRouteNextHop => $entry) { - unset($entryClean); - $entryClean['inetCidrRouteDestType'] = 'ipv4'; - $entryClean['inetCidrRouteDest'] = $inetCidrRouteDest; - $inetCidrRoutePfxLen = IPv4::netmask2cidr($entry['IP-FORWARD-MIB::ipCidrRouteMask']); //CONVERT - $entryClean['inetCidrRoutePfxLen'] = $inetCidrRoutePfxLen; - $entryClean['inetCidrRoutePolicy'] = $entry['IP-FORWARD-MIB::ipCidrRouteInfo']; - $entryClean['inetCidrRouteNextHopType'] = 'ipv4'; - $entryClean['inetCidrRouteNextHop'] = $inetCidrRouteNextHop; - $entryClean['inetCidrRouteMetric1'] = $entry['IP-FORWARD-MIB::ipCidrRouteMetric1']; - $entryClean['inetCidrRouteProto'] = $entry['IP-FORWARD-MIB::ipCidrRouteProto']; - $entryClean['inetCidrRouteType'] = $entry['IP-FORWARD-MIB::ipCidrRouteType']; - $entryClean['inetCidrRouteIfIndex'] = $entry['IP-FORWARD-MIB::ipCidrRouteIfIndex']; - $entryClean['inetCidrRouteNextHopAS'] = $entry['IP-FORWARD-MIB::ipCidrRouteNextHopAS']; - $entryClean['context_name'] = ''; - $entryClean['device_id'] = $device['device_id']; - $entryClean['port_id'] = Device::find($device['device_id'])->ports()->where('ifIndex', '=', $entryClean['inetCidrRouteIfIndex'])->first()->port_id; - $entryClean['updated_at'] = $update_timestamp; - $current = $mixed['']['ipv4'][$inetCidrRouteDest][$inetCidrRoutePfxLen][$entryClean['inetCidrRoutePolicy']]['ipv4'][$inetCidrRouteNextHop]; - if (isset($current) && isset($current['db']) && count($current['db']) > 0 && $delete_row[$current['db']['route_id']] != 1) { - //we already have a row in DB - $entryClean['route_id'] = $current['db']['route_id']; - $update_row[] = $entryClean; - } else { - $entryClean['created_at'] = ['NOW()']; - $create_row[] = $entryClean; +if (isset($ipForwardNb['0']['ipCidrRouteNumber']) && $ipForwardNb['0']['ipCidrRouteNumber'] < $max_routes) { + if (! isset($ipForwardNb['0']['inetCidrRouteNumber']) || $ipForwardNb['0']['ipCidrRouteNumber'] > $ipForwardNb['0']['inetCidrRouteNumber']) { + //device uses only ipCidrRoute and not inetCidrRoute + d_echo('IP FORWARD MIB (without inetCidr support)'); + $ipCidrTable = SnmpQuery::walk('IP-FORWARD-MIB::ipCidrRouteTable')->table(6); + echo 'ipCidrRouteTable '; + // we need to translate the values to inetCidr structure; + //d_echo($ipCidrTable); + foreach ($ipCidrTable as $inetCidrRouteDest => $next1) { + foreach ($next1 as $ipCidrRouteMask => $next2) { + foreach ($next2 as $ipCidrRouteTos => $next3) { + foreach ($next3 as $inetCidrRouteNextHop => $entry) { + unset($entryClean); + $entryClean['inetCidrRouteDestType'] = 'ipv4'; + $entryClean['inetCidrRouteDest'] = $inetCidrRouteDest; + $entryClean['inetCidrRoutePfxLen'] = $inetCidrRoutePfxLen = IPv4::netmask2cidr($entry['IP-FORWARD-MIB::ipCidrRouteMask']); //CONVERT + $entryClean['inetCidrRoutePolicy'] = $entry['IP-FORWARD-MIB::ipCidrRouteInfo']; + $entryClean['inetCidrRouteNextHopType'] = 'ipv4'; + $entryClean['inetCidrRouteNextHop'] = $inetCidrRouteNextHop; + $entryClean['inetCidrRouteMetric1'] = $entry['IP-FORWARD-MIB::ipCidrRouteMetric1']; + $entryClean['inetCidrRouteProto'] = $entry['IP-FORWARD-MIB::ipCidrRouteProto']; + $entryClean['inetCidrRouteType'] = $entry['IP-FORWARD-MIB::ipCidrRouteType']; + $entryClean['inetCidrRouteIfIndex'] = $entry['IP-FORWARD-MIB::ipCidrRouteIfIndex']; + $entryClean['inetCidrRouteNextHopAS'] = $entry['IP-FORWARD-MIB::ipCidrRouteNextHopAS']; + $entryClean['context_name'] = ''; + $entryClean['device_id'] = $device['device_id']; + $entryClean['port_id'] = Device::find($device['device_id'])->ports()->where('ifIndex', '=', $entryClean['inetCidrRouteIfIndex'])->first()->port_id; + $entryClean['updated_at'] = $update_timestamp; + $current = $mixed['']['ipv4'][$inetCidrRouteDest][$inetCidrRoutePfxLen][$entryClean['inetCidrRoutePolicy']]['ipv4'][$inetCidrRouteNextHop] ?? null; + if (isset($current) && isset($current['db']) && count($current['db']) > 0 && $delete_row[$current['db']['route_id']] != 1) { + //we already have a row in DB + $entryClean['route_id'] = $current['db']['route_id']; + $update_row[] = $entryClean; + } else { + $entryClean['created_at'] = ['NOW()']; + $create_row[] = $entryClean; + } } } } @@ -225,15 +228,17 @@ if (isset($ipForwardNb['0']['ipCidrRouteNumber']) && $ipForwardNb['0']['ipCidrRo $mib = 'MPLS-L3VPN-STD-MIB'; $oid = 'mplsL3VpnVrfPerfCurrNumRoutes'; $mpls_vpn_route_nb = snmpwalk_group($device, $oid, $mib, 6, []); +$mpls_skip = false; foreach ($mpls_vpn_route_nb as $vpnId => $route_nb) { if ($route_nb['mplsL3VpnVrfPerfCurrNumRoutes'] > $max_routes) { echo "Skipping all MPLS routes because vpn instance $vpnId has more than $max_routes routes."; - $mpls_skip = 1; + $mpls_skip = true; + break; } } -if ($mpls_skip != 1) { +if ($mpls_skip == false) { echo 'mplsL3VpnVrfRteTable '; // We can discover the routes; $oid = 'mplsL3VpnVrfRteTable'; diff --git a/includes/discovery/sensors/airflow/apc.inc.php b/includes/discovery/sensors/airflow/apc.inc.php index 8637845abd..ad19a1cc6e 100644 --- a/includes/discovery/sensors/airflow/apc.inc.php +++ b/includes/discovery/sensors/airflow/apc.inc.php @@ -25,8 +25,8 @@ foreach ($pre_cache['cooling_unit_analog'] as $index => $data) { $cur_oid = '.1.3.6.1.4.1.318.1.1.27.1.4.1.2.1.3.' . $index; $descr = $data['coolingUnitStatusAnalogDescription']; - $scale = $data['coolingUnitStatusAnalogScale']; - $value = $data['coolingUnitStatusAnalogValue']; + $scale = $data['coolingUnitStatusAnalogScale'] ?? null; + $value = $data['coolingUnitStatusAnalogValue'] ?? null; if (preg_match('/Airflow/', $descr) && $data['coolingUnitStatusAnalogUnits'] == 'CFM' && $value >= 0) { discover_sensor($valid['sensor'], 'airflow', $device, $cur_oid, $cur_oid, 'apc', $descr, $scale, 1, null, null, null, null, $value); } diff --git a/includes/discovery/sensors/current/adva_fsp150.inc.php b/includes/discovery/sensors/current/adva_fsp150.inc.php index 6d34598282..c05bcc2c4a 100644 --- a/includes/discovery/sensors/current/adva_fsp150.inc.php +++ b/includes/discovery/sensors/current/adva_fsp150.inc.php @@ -34,7 +34,7 @@ $divisor = 1000; foreach (array_keys($pre_cache['adva_fsp150']) as $index) { foreach ($sensors_adva as $entry) { $sensor_name = $entry['sensor_name']; - if ($pre_cache['adva_fsp150'][$index][$sensor_name]) { + if (isset($pre_cache['adva_fsp150'][$index][$sensor_name])) { $oid = $entry['sensor_oid'] . '.' . $index; $descr = $pre_cache['adva_fsp150'][$index]['slotCardUnitName'] . ' [#' . $pre_cache['adva_fsp150'][$index]['slotIndex'] . ']'; $current = $pre_cache['adva_fsp150'][$index][$entry['sensor_name']] / $divisor; @@ -64,7 +64,7 @@ unset($sensors_adva, $entry); // FSP150 Pro Series SFP Current foreach ($pre_cache['adva_fsp150_ports'] as $index => $entry) { - if ($entry['cmEthernetNetPortMediaType'] == 'fiber' && $entry['cmEthernetNetPortOperationalState'] == 'normal') { + if (isset($entry['cmEthernetNetPortMediaType']) && $entry['cmEthernetNetPortMediaType'] == 'fiber' && $entry['cmEthernetNetPortOperationalState'] == 'normal') { $oid = '.1.3.6.1.4.1.2544.1.12.5.1.5.1.32.' . $index . '.3'; $current = $pre_cache['adva_fsp150_perfs'][$index . '.3']['cmEthernetNetPortStatsLBC']; if ($current != 0) { @@ -94,7 +94,7 @@ foreach ($pre_cache['adva_fsp150_ports'] as $index => $entry) { } } - if ($entry['cmEthernetAccPortMediaType'] && $entry['cmEthernetAccPortMediaType'] == 'fiber' && $entry['cmEthernetAccPortOperationalState'] == 'normal') { + if (isset($entry['cmEthernetAccPortMediaType']) && $entry['cmEthernetAccPortMediaType'] == 'fiber' && $entry['cmEthernetAccPortOperationalState'] == 'normal') { $oid = '.1.3.6.1.4.1.2544.1.12.5.1.1.1.32.' . $index . '.3'; $current = $pre_cache['adva_fsp150_perfs'][$index . '.3']['cmEthernetAccPortStatsLBC']; if ($current != 0) { @@ -123,7 +123,7 @@ foreach ($pre_cache['adva_fsp150_ports'] as $index => $entry) { } } - if ($entry['cmEthernetTrafficPortMediaType'] == 'fiber' && $entry['cmEthernetTrafficPortOperationalState'] == 'normal') { + if (isset($entry['cmEthernetTrafficPortMediaType']) && $entry['cmEthernetTrafficPortMediaType'] == 'fiber' && $entry['cmEthernetTrafficPortOperationalState'] == 'normal') { $oid = '.1.3.6.1.4.1.2544.1.12.5.1.21.1.32.' . $index . '.3'; $current = $pre_cache['adva_fsp150_perfs'][$index . '.3']['cmEthernetTrafficPortStatsLBC']; if ($current != 0) { diff --git a/includes/discovery/sensors/current/apc.inc.php b/includes/discovery/sensors/current/apc.inc.php index 677bd16b98..01d27c7207 100644 --- a/includes/discovery/sensors/current/apc.inc.php +++ b/includes/discovery/sensors/current/apc.inc.php @@ -2,7 +2,7 @@ // PDU - Phase $oids = snmp_walk($device, 'rPDUStatusPhaseIndex', '-OsqnU', 'PowerNet-MIB'); -if ($oids) { +if (isset($oids) && $oids) { d_echo($oids . "\n"); $oids = trim($oids); if ($oids) { @@ -45,7 +45,7 @@ if ($oids) { } unset($oids); $oids = snmp_walk($device, 'rPDULoadStatusPhaseNumber', '-OsqnU', 'PowerNet-MIB'); -if ($oids) { +if (isset($oids) && $oids) { d_echo($oids . "\n"); $oids = trim($oids); if ($oids) { @@ -97,7 +97,7 @@ if ($bank_count > 0) { $oids = snmp_walk($device, 'rPDULoadStatusBankNumber', '-OsqnU', 'PowerNet-MIB'); } // should work with firmware v2 and v3 -if ($oids) { +if (isset($oids) && $oids) { echo 'APC PowerNet-MIB Banks '; d_echo($oids . "\n"); $oids = trim($oids); @@ -139,7 +139,7 @@ if ($oids) { unset($oids); // Per Outlet Power Bar $oids = snmp_walk($device, '.1.3.6.1.4.1.318.1.1.26.9.4.3.1.1', '-t 30 -OsqnU', 'PowerNet-MIB'); -if ($oids) { +if (isset($oids) && $oids) { echo 'APC PowerNet-MIB Outlets '; d_echo($oids . "\n"); $oids = trim($oids); @@ -176,7 +176,7 @@ if ($oids) { unset($oids); // ATS $oids = snmp_walk($device, 'atsConfigPhaseTableIndex', '-OsqnU', 'PowerNet-MIB'); -if ($oids) { +if (isset($oids) && $oids) { $type = 'apc'; d_echo($oids . "\n"); $oids = trim($oids); @@ -206,12 +206,12 @@ unset($oids); // UPS - $phasecount = $phasecount = $pre_cache['apcups_phase_count']; +$phasecount = $pre_cache['apcups_phase_count']; if ($phasecount > 1) { - $oids = snmpwalk_cache_oid($device, 'upsPhaseOutputCurrent', $oids, 'PowerNet-MIB'); + $oids = snmpwalk_cache_oid($device, 'upsPhaseOutputCurrent', [], 'PowerNet-MIB'); $in_oids = snmpwalk_cache_oid($device, 'upsPhaseInputCurrent', $in_oids, 'PowerNet-MIB'); } else { - $oids = snmpwalk_cache_oid($device, 'upsHighPrecOutputCurrent', $oids, 'PowerNet-MIB'); + $oids = snmpwalk_cache_oid($device, 'upsHighPrecOutputCurrent', [], 'PowerNet-MIB'); } if (isset($in_oids)) { foreach ($in_oids as $index => $data) { diff --git a/includes/discovery/sensors/entity-sensor.inc.php b/includes/discovery/sensors/entity-sensor.inc.php index 169effcee2..f20537d965 100644 --- a/includes/discovery/sensors/entity-sensor.inc.php +++ b/includes/discovery/sensors/entity-sensor.inc.php @@ -53,7 +53,7 @@ if (! empty($entity_oids)) { if ($entry['entPhySensorType'] == 'other' && Str::contains($entity_array[$index]['entPhysicalName'], ['Rx Power Sensor', 'Tx Power Sensor'])) { $entitysensor['other'] = 'dbm'; } - if ($entitysensor[$entry['entPhySensorType']] && is_numeric($entry['entPhySensorValue']) && is_numeric($index)) { + if (isset($entitysensor[$entry['entPhySensorType']]) && is_numeric($entry['entPhySensorValue']) && is_numeric($index)) { $entPhysicalIndex = $index; $oid = '.1.3.6.1.2.1.99.1.1.1.4.' . $index; $current = $entry['entPhySensorValue']; @@ -144,11 +144,11 @@ if (! empty($entity_oids)) { $valid_sensor = false; } } - if ($current == '-127' || ($device['os'] == 'asa' && Str::endsWith($device['hardware'], 'sc'))) { + if ($current == '-127' || ($device['os'] == 'asa' && is_string($device['hardware']) && Str::endsWith($device['hardware'], 'sc'))) { $valid_sensor = false; } // Check for valid sensors - if ($entry['entPhySensorOperStatus'] === 'unavailable') { + if (isset($entry['entPhySensorOperStatus']) && $entry['entPhySensorOperStatus'] === 'unavailable') { $valid_sensor = false; } if ($valid_sensor && dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE device_id = ? AND `sensor_class` = ? AND `sensor_type` = 'cisco-entity-sensor' AND `sensor_index` = ?", [$device['device_id'], $type, $index]) == '0') { diff --git a/includes/discovery/sensors/pre-cache/avtech.inc.php b/includes/discovery/sensors/pre-cache/avtech.inc.php index 43ad60427d..b59ae44ecc 100644 --- a/includes/discovery/sensors/pre-cache/avtech.inc.php +++ b/includes/discovery/sensors/pre-cache/avtech.inc.php @@ -32,9 +32,10 @@ $virtual_tables = [ 'ra32-wish-temp' => '/\.1\.3\.6\.1\.4\.1\.20916\.1\.8\.1\.4\.((\d+)\.4\.1\.2\.0)/', ]; -$data = snmp_walk($device, '.1.3.6.1.4.1.20916.1', '-OQn'); +$data = trim(snmp_walk($device, '.1.3.6.1.4.1.20916.1', '-OQn')); foreach (explode(PHP_EOL, $data) as $line) { - [$oid, $value] = explode(' = ', $line); + [$oid, $value] = explode(' =', $line); + $value = trim($value); $processed = false; foreach ($virtual_tables as $vt_name => $vt_regex) { diff --git a/includes/discovery/sensors/state/cisco.inc.php b/includes/discovery/sensors/state/cisco.inc.php index 5fa5eaa5b0..f864a6a045 100644 --- a/includes/discovery/sensors/state/cisco.inc.php +++ b/includes/discovery/sensors/state/cisco.inc.php @@ -43,7 +43,7 @@ foreach ($tables as $tablevalue) { $cur_oid = $tablevalue['num_oid']; if (is_array($temp)) { - if ($temp[0][$tablevalue['state_name']] == 'nonRedundant' || $temp[0]['cswMaxSwitchNum'] == '1') { + if (isset($temp[0]) && $temp[0][$tablevalue['state_name']] == 'nonRedundant' || $temp[0]['cswMaxSwitchNum'] == '1') { break; } diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 083f85773e..7773cc91de 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -591,8 +591,8 @@ foreach ($ports as $port) { // rewrite the ifPhysAddress if (strpos($this_port['ifPhysAddress'] ?? '', ':')) { - [$a_a, $a_b, $a_c, $a_d, $a_e, $a_f] = explode(':', $this_port['ifPhysAddress']); - $this_port['ifPhysAddress'] = zeropad($a_a) . zeropad($a_b) . zeropad($a_c) . zeropad($a_d) . zeropad($a_e) . zeropad($a_f); + $mac_split = explode(':', $this_port['ifPhysAddress']); + $this_port['ifPhysAddress'] = zeropad($mac_split[0]) . zeropad($mac_split[1]) . zeropad($mac_split[2]) . zeropad($mac_split[3]) . zeropad($mac_split[4] ?? '') . zeropad($mac_split[5] ?? ''); } // use HC values if they are available diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 07141a8183..8d71e20979 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3640,11 +3640,6 @@ parameters: count: 2 path: LibreNMS/OS/ArrisDsr4410md.php - - - message: "#^Method LibreNMS\\\\OS\\\\ArubaInstant\\:\\:decodeChannel\\(\\) has no return type specified\\.$#" - count: 1 - path: LibreNMS/OS/ArubaInstant.php - - message: "#^Method LibreNMS\\\\OS\\\\ArubaInstant\\:\\:decodeChannel\\(\\) has parameter \\$channel with no type specified\\.$#" count: 1