2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// Build SNMP Cache Array
|
2021-08-24 20:28:18 +02:00
|
|
|
use App\Models\PortGroup;
|
2017-09-11 15:26:41 -05:00
|
|
|
use LibreNMS\Config;
|
2021-09-21 08:47:44 -05:00
|
|
|
use LibreNMS\Util\StringHelpers;
|
2017-09-11 15:26:41 -05:00
|
|
|
|
2021-10-28 20:05:43 +02:00
|
|
|
$descrSnmpFlags = '-OQUs';
|
|
|
|
$typeSnmpFlags = '-OQUs';
|
|
|
|
$operStatusSnmpFlags = '-OQUs';
|
|
|
|
if ($device['os'] == 'bintec-beip-plus') {
|
|
|
|
$descrSnmpFlags = ['-OQUs', '-Cc'];
|
|
|
|
$typeSnmpFlags = ['-OQUs', '-Cc'];
|
|
|
|
$operStatusSnmpFlags = ['-OQUs', '-Cc'];
|
|
|
|
}
|
|
|
|
|
2019-01-19 18:48:30 +01:00
|
|
|
$port_stats = [];
|
2021-10-28 20:05:43 +02:00
|
|
|
$port_stats = snmpwalk_cache_oid($device, 'ifDescr', $port_stats, 'IF-MIB', null, $descrSnmpFlags);
|
2015-07-13 20:10:26 +02:00
|
|
|
$port_stats = snmpwalk_cache_oid($device, 'ifName', $port_stats, 'IF-MIB');
|
2017-02-14 23:26:07 +00:00
|
|
|
$port_stats = snmpwalk_cache_oid($device, 'ifAlias', $port_stats, 'IF-MIB');
|
2021-10-28 20:05:43 +02:00
|
|
|
$port_stats = snmpwalk_cache_oid($device, 'ifType', $port_stats, 'IF-MIB', null, $typeSnmpFlags);
|
|
|
|
$port_stats = snmpwalk_cache_oid($device, 'ifOperStatus', $port_stats, 'IF-MIB', null, $operStatusSnmpFlags);
|
2012-05-11 18:08:48 +00:00
|
|
|
|
2020-09-16 22:48:32 +02:00
|
|
|
// Get correct eth0 port status for AirFiber 5XHD devices
|
|
|
|
if ($device['os'] == 'airos-af-ltu') {
|
2020-09-21 15:40:17 +02:00
|
|
|
require 'ports/airos-af-ltu.inc.php';
|
2020-09-16 22:48:32 +02:00
|
|
|
}
|
|
|
|
|
2022-01-08 18:17:08 +01:00
|
|
|
//Teleste Luminato ifOperStatus
|
|
|
|
if ($device['os'] == 'luminato') {
|
|
|
|
require base_path('includes/discovery/ports/luminato.inc.php');
|
|
|
|
}
|
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// End Building SNMP Cache Array
|
2015-08-20 15:59:43 +02:00
|
|
|
d_echo($port_stats);
|
2012-05-11 18:08:48 +00:00
|
|
|
|
2016-01-26 13:49:30 +01:00
|
|
|
// By default libreNMS uses the ifIndex to associate ports on devices with ports discoverd/polled
|
|
|
|
// before and stored in the database. On Linux boxes this is a problem as ifIndexes may be
|
|
|
|
// unstable between reboots or (re)configuration of tunnel interfaces (think: GRE/OpenVPN/Tinc/...)
|
|
|
|
// The port association configuration allows to choose between association via ifIndex, ifName,
|
|
|
|
// or maybe other means in the future. The default port association mode still is ifIndex for
|
|
|
|
// compatibility reasons.
|
2017-09-11 15:26:41 -05:00
|
|
|
$port_association_mode = Config::get('default_port_association_mode');
|
2016-08-28 12:32:58 -05:00
|
|
|
if ($device['port_association_mode']) {
|
|
|
|
$port_association_mode = get_port_assoc_mode_name($device['port_association_mode']);
|
|
|
|
}
|
2016-01-26 13:49:30 +01:00
|
|
|
|
|
|
|
// Build array of ports in the database and an ifIndex/ifName -> port_id map
|
2016-08-28 12:32:58 -05:00
|
|
|
$ports_mapped = get_ports_mapped($device['device_id']);
|
2016-01-26 13:49:30 +01:00
|
|
|
$ports_db = $ports_mapped['ports'];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Rename any old RRD files still named after the previous ifIndex based naming schema.
|
|
|
|
foreach ($ports_mapped['maps']['ifIndex'] as $ifIndex => $port_id) {
|
2019-01-19 18:48:30 +01:00
|
|
|
foreach (['', '-adsl', '-dot3'] as $suffix) {
|
2016-07-07 01:33:43 -05:00
|
|
|
$old_rrd_name = "port-$ifIndex$suffix.rrd";
|
2021-03-28 17:25:30 -05:00
|
|
|
$new_rrd_name = \Rrd::portName($port_id, ltrim($suffix, '-'));
|
2016-01-26 13:49:30 +01:00
|
|
|
|
2021-03-28 17:25:30 -05:00
|
|
|
\Rrd::renameFile($device, $old_rrd_name, $new_rrd_name);
|
2016-01-26 13:49:30 +01:00
|
|
|
}
|
2012-05-11 18:08:48 +00:00
|
|
|
}
|
2008-03-22 23:09:35 +00:00
|
|
|
|
2019-11-13 15:29:30 +01:00
|
|
|
// Fill ifAlias for fibrechannel ports
|
|
|
|
if ($device['os'] == 'fabos') {
|
2021-10-21 01:51:49 +02:00
|
|
|
require base_path('includes/discovery/ports/brocade.inc.php');
|
2019-11-13 15:29:30 +01:00
|
|
|
}
|
2016-01-26 13:49:30 +01:00
|
|
|
|
2020-09-23 11:23:57 -05:00
|
|
|
//Shorten Ekinops Interfaces
|
|
|
|
if ($device['os'] == 'ekinops') {
|
2021-10-21 01:51:49 +02:00
|
|
|
require base_path('includes/discovery/ports/ekinops.inc.php');
|
2020-09-23 11:23:57 -05:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:28:18 +02:00
|
|
|
$default_port_group = Config::get('default_port_group');
|
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// New interface detection
|
2019-01-19 18:48:30 +01:00
|
|
|
foreach ($port_stats as $ifIndex => $snmp_data) {
|
|
|
|
$snmp_data['ifIndex'] = $ifIndex; // Store ifIndex in port entry
|
2021-09-21 08:47:44 -05:00
|
|
|
$snmp_data['ifAlias'] = StringHelpers::inferEncoding($snmp_data['ifAlias']);
|
2016-01-26 13:49:30 +01:00
|
|
|
|
|
|
|
// Get port_id according to port_association_mode used for this device
|
2019-01-19 18:48:30 +01:00
|
|
|
$port_id = get_port_id($ports_mapped, $snmp_data, $port_association_mode);
|
|
|
|
|
|
|
|
if (is_port_valid($snmp_data, $device)) {
|
|
|
|
port_fill_missing($snmp_data, $device);
|
|
|
|
|
2016-01-26 13:49:30 +01:00
|
|
|
// Port newly discovered?
|
2020-09-21 15:40:17 +02:00
|
|
|
if (! is_array($ports_db[$port_id])) {
|
2019-01-19 18:48:30 +01:00
|
|
|
$snmp_data['device_id'] = $device['device_id'];
|
|
|
|
$port_id = dbInsert($snmp_data, 'ports');
|
2021-08-24 20:28:18 +02:00
|
|
|
|
|
|
|
//default Port Group for new Ports defined?
|
|
|
|
if (! empty($default_port_group)) {
|
|
|
|
$port_group = PortGroup::find($default_port_group);
|
|
|
|
if (isset($port_group)) {
|
|
|
|
$port_group->ports()->attach([$port_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 18:48:30 +01:00
|
|
|
$ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', [$device['device_id'], $port_id]);
|
|
|
|
echo 'Adding: ' . $snmp_data['ifName'] . '(' . $ifIndex . ')(' . $port_id . ')';
|
|
|
|
} elseif ($ports_db[$port_id]['deleted'] == 1) {
|
|
|
|
// Port re-discovered after previous deletion?
|
|
|
|
$snmp_data['deleted'] = 0;
|
|
|
|
dbUpdate($snmp_data, 'ports', '`port_id` = ?', [$port_id]);
|
|
|
|
$ports_db[$port_id]['deleted'] = 0;
|
2015-07-13 20:10:26 +02:00
|
|
|
echo 'U';
|
2018-12-12 04:07:56 +01:00
|
|
|
} else { // port is existing, let's update it with some data we have collected here
|
2019-01-19 18:48:30 +01:00
|
|
|
dbUpdate($snmp_data, 'ports', '`port_id` = ?', [$port_id]);
|
2015-07-13 20:10:26 +02:00
|
|
|
echo '.';
|
|
|
|
}
|
2017-05-17 16:25:47 -05:00
|
|
|
} else {
|
|
|
|
// Port vanished (mark as deleted)
|
2016-01-26 13:49:30 +01:00
|
|
|
if (is_array($ports_db[$port_id])) {
|
2019-01-19 18:48:30 +01:00
|
|
|
if ($ports_db[$port_id]['deleted'] != 1) {
|
|
|
|
dbUpdate(['deleted' => 1], 'ports', '`port_id` = ?', [$port_id]);
|
|
|
|
$ports_db[$port_id]['deleted'] = 1;
|
2015-07-13 20:10:26 +02:00
|
|
|
echo '-';
|
|
|
|
}
|
|
|
|
}
|
2008-04-03 21:52:59 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
echo 'X';
|
|
|
|
}//end if
|
|
|
|
}//end foreach
|
|
|
|
|
2017-02-08 04:54:30 +00:00
|
|
|
unset(
|
|
|
|
$ports_mapped,
|
|
|
|
$port
|
|
|
|
);
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
echo "\n";
|
2012-05-11 18:08:48 +00:00
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// Clear Variables Here
|
2012-05-11 18:08:48 +00:00
|
|
|
unset($port_stats);
|
2012-05-16 13:25:50 +00:00
|
|
|
unset($ports_db);
|