mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* AuthSSOTest: clear roles cache * PollingJob: When a poller module doesn't exist, return null instead of false. Skip all other checks and disable polling in that case. * Sensors: Guess high and low limits separately as needed * Sensors: drac test psu current data was wrong, referencing the snmprec, 8 / 10 and 0 / 10 should be the values NOTE: drac is messed up and runs a billion snmp queriess for no reason * please phpstan * Sensors: limits reference old code move to "creating" * Fix gw-eydfa accidental assignment * Fix ies5000 test data now that the bad state is removed * Fix ies5000 test data part 2 * Move sensor discovery reset into discover_device() * infinera remove duplicate sensor (also a lot of trailing whitespace apparently) * Fix innovaphone bad yaml discovery * module tests should be using null when test data doesn't exist, not an empty array * When discovery or polling is not supported, dump null instead of an array. Account for nulls in testing * update ISE serial * Janitza was seemingly wrong before * Remove some private data * bgp-peers requires ipv4-addresses and ipv6-addresses for bgpPeerIface * fix polycomLens broken state sensor discovery * Raritan pdu and pdu2 test data was combined in one test file, split it out * scs-ks duplicate temperature sensor indexes * sentry3 someone tried to avoid breaking stuff but just broke things more * smartos-dcp-m fix incorrect numeric oids * ssu2000 apparently test data was wrong, must have fixed a bug in the code. * timos remove duplicate dbm sensor definitions * bgpPeerIface is working in tests now * Fix moxa-etherdevice when mibs are a bit different * xw_to_dbm negative values should return null * Update cisco test data due previous fixes/changes * One more bgpPeerIface * Add orderBy to ospf module db dumps * Remove links test data for now * Improve handling of bad data in ipv6-addresses module
76 lines
3.4 KiB
PHP
76 lines
3.4 KiB
PHP
<?php
|
|
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Exceptions\InvalidIpException;
|
|
use LibreNMS\Util\IPv6;
|
|
|
|
$valid ??= []; // may not be instantiated. I think this is the last place that uses this global.
|
|
|
|
foreach (DeviceCache::getPrimary()->getVrfContexts() as $context_name) {
|
|
$device['context_name'] = $context_name;
|
|
|
|
if (file_exists(Config::get('install_dir') . "/includes/discovery/ipv6-addresses/{$device['os']}.inc.php")) {
|
|
include Config::get('install_dir') . "/includes/discovery/ipv6-addresses/{$device['os']}.inc.php";
|
|
} else {
|
|
$oids = SnmpQuery::enumStrings()->abortOnFailure()
|
|
->walk(['IP-MIB::ipAddressIfIndex.ipv6', 'IP-MIB::ipAddressOrigin.ipv6', 'IP-MIB::ipAddressPrefix.ipv6'])
|
|
->table(4);
|
|
foreach ($oids['ipv6'] ?? [] as $address => $data) {
|
|
if (! is_array($data)) {
|
|
\Illuminate\Support\Facades\Log::debug('IPv6 data invalid');
|
|
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
$ifIndex = $data['IP-MIB::ipAddressIfIndex'];
|
|
$ipv6_address = IPv6::fromHexString($address)->uncompressed();
|
|
$ipv6_origin = $data['IP-MIB::ipAddressOrigin'];
|
|
preg_match('/(\d{1,3})]$/', $data['IP-MIB::ipAddressPrefix'], $prefix_match);
|
|
$ipv6_prefixlen = $prefix_match[1] ?? 0;
|
|
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
|
|
} catch (InvalidIpException $e) {
|
|
d_echo("Failed to decode ipv6: $address");
|
|
}
|
|
}
|
|
}
|
|
|
|
if (empty($oids) || empty($valid)) {
|
|
$oids = snmp_walk($device, 'ipv6AddrPfxLength', ['-OsqnU', '-Ln'], 'IPV6-MIB');
|
|
$oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids);
|
|
$oids = str_replace('"', '', $oids);
|
|
$oids = trim($oids);
|
|
|
|
foreach (explode("\n", $oids) as $data) {
|
|
if ($data) {
|
|
$data = trim($data);
|
|
[$if_ipv6addr,$ipv6_prefixlen] = explode(' ', $data);
|
|
[$ifIndex,$ipv6addr] = explode('.', $if_ipv6addr, 2);
|
|
$ipv6_address = snmp2ipv6($ipv6addr);
|
|
$ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB');
|
|
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
|
|
} //end if
|
|
} //end foreach
|
|
} //end if
|
|
|
|
$sql = 'SELECT `ipv6_addresses`.*, `ports`.`device_id`, `ports`.`ifIndex` FROM `ipv6_addresses`';
|
|
$sql .= ' LEFT JOIN `ports` ON `ipv6_addresses`.`port_id` = `ports`.`port_id`';
|
|
$sql .= ' WHERE `ports`.device_id = ? OR `ports`.`device_id` IS NULL';
|
|
foreach (dbFetchRows($sql, [$device['device_id']]) as $row) {
|
|
$full_address = $row['ipv6_address'] . '/' . $row['ipv6_prefixlen'];
|
|
$port_id = $row['port_id'];
|
|
$valid_address = $full_address . '-' . $port_id;
|
|
if (! $valid['ipv6'][$valid_address]) {
|
|
echo '-';
|
|
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', [$row['ipv6_address_id']]);
|
|
if (! dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', [$row['ipv6_network_id']])) {
|
|
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', [$row['ipv6_network_id']]);
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "\n";
|
|
unset($device['context_name']);
|
|
}
|
|
unset($vrfs_c);
|