Commit version 24.12.13800
This commit is contained in:
@ -4,16 +4,16 @@
|
||||
*
|
||||
* This file is part of Observium.
|
||||
*
|
||||
* @package observium
|
||||
* @subpackage poller
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2022 Observium Limited
|
||||
* @package observium
|
||||
* @subpackage poller
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
// CLEANME. Remove after CE 23.xx
|
||||
if (get_db_version() < 477) {
|
||||
print_warning("DB schema not updated. OSPFV3-MIB not polled until update.");
|
||||
return;
|
||||
print_warning("DB schema not updated. OSPFV3-MIB not polled until update.");
|
||||
return;
|
||||
}
|
||||
|
||||
print_cli_data_field($mib . ' Processes', 2);
|
||||
@ -36,85 +36,99 @@ OSPFV3-MIB::ospfv3DemandExtensions.0 = INTEGER: 0
|
||||
|
||||
// Pull data from device
|
||||
if ($ospf_instance_poll = snmpwalk_cache_oid($device, 'ospfv3GeneralGroup', [], 'OSPFV3-MIB')) {
|
||||
$ospf_instance_poll = $ospf_instance_poll[0];
|
||||
$ospf_instance_poll = $ospf_instance_poll[0];
|
||||
|
||||
// Don't bother polling everything if we have no enabled or non-defaulted router ids.
|
||||
if ($ospf_instance_poll['ospfv3RouterId'] !== '0' ||
|
||||
$ospf_instance_poll['ospfv3AdminStatus'] === 'enabled') {
|
||||
$ospf_enabled = TRUE;
|
||||
}
|
||||
// Don't bother polling everything if we have no enabled or non-defaulted router ids.
|
||||
if ($ospf_instance_poll['ospfv3RouterId'] !== '0' ||
|
||||
$ospf_instance_poll['ospfv3AdminStatus'] === 'enabled') {
|
||||
$ospf_enabled = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Build array of existing entries
|
||||
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [ $device['device_id'], 'version3' ]);
|
||||
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [$device['device_id'], 'version3']);
|
||||
|
||||
if ($ospf_enabled && empty($ospf_instance_db)) {
|
||||
$ospf_instance_id = dbInsert([ 'device_id' => $device['device_id'], 'ospfVersionNumber' => 'version3' ], 'ospf_instances');
|
||||
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `ospf_instance_id` = ?', [ $ospf_instance_id ]);
|
||||
echo('+');
|
||||
$ospf_instance_id = dbInsert(['device_id' => $device['device_id'], 'ospfVersionNumber' => 'version3'], 'ospf_instances');
|
||||
$ospf_instance_db = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `ospf_instance_id` = ?', [$ospf_instance_id]);
|
||||
echo('+');
|
||||
} elseif (!$ospf_enabled && !empty($ospf_instance_db)) {
|
||||
dbDelete('ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_db['instance_id'] ]);
|
||||
echo('-');
|
||||
dbDelete('ospf_instances', '`ospf_instance_id` = ?', [$ospf_instance_db['instance_id']]);
|
||||
echo('-');
|
||||
}
|
||||
|
||||
if (!$ospf_enabled) {
|
||||
// OSPF instance not enabled
|
||||
return;
|
||||
// OSPF instance not enabled
|
||||
return;
|
||||
} elseif (OBS_DEBUG) {
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_instance_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_instance_db);
|
||||
echo("\n");
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_instance_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_instance_db);
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
$ospf_oids_db = [ 'ospfRouterId' => 'ospfv3RouterId', 'ospfAdminStat' => 'ospfv3AdminStatus',
|
||||
'ospfVersionNumber' => 'ospfv3VersionNumber', 'ospfAreaBdrRtrStatus' => 'ospfv3AreaBdrRtrStatus',
|
||||
'ospfASBdrRtrStatus' => 'ospfv3ASBdrRtrStatus', 'ospfExternLsaCount' => 'ospfv3ExtLsaCount',
|
||||
'ospfExternLsaCksumSum' => '', 'ospfTOSSupport' => '',
|
||||
'ospfOriginateNewLsas' => 'ospfv3OriginateNewLsas', 'ospfRxNewLsas' => 'ospfv3RxNewLsas',
|
||||
'ospfExtLsdbLimit' => 'ospfv3ExtAreaLsdbLimit', 'ospfMulticastExtensions' => '',
|
||||
'ospfExitOverflowInterval' => 'ospfv3ExitOverflowInterval', 'ospfDemandExtensions' => 'ospfv3DemandExtensions' ];
|
||||
$ospf_stats = [
|
||||
'instances' => 0,
|
||||
'ports' => 0,
|
||||
'areas' => 0,
|
||||
'neighbours' => 0
|
||||
];
|
||||
|
||||
$ospf_oids_db = ['ospfRouterId' => 'ospfv3RouterId',
|
||||
'ospfAdminStat' => 'ospfv3AdminStatus',
|
||||
'ospfVersionNumber' => 'ospfv3VersionNumber',
|
||||
'ospfAreaBdrRtrStatus' => 'ospfv3AreaBdrRtrStatus',
|
||||
'ospfASBdrRtrStatus' => 'ospfv3ASBdrRtrStatus',
|
||||
'ospfExternLsaCount' => 'ospfv3ExtLsaCount',
|
||||
'ospfExternLsaCksumSum' => '',
|
||||
'ospfTOSSupport' => '',
|
||||
'ospfOriginateNewLsas' => 'ospfv3OriginateNewLsas',
|
||||
'ospfRxNewLsas' => 'ospfv3RxNewLsas',
|
||||
'ospfExtLsdbLimit' => 'ospfv3ExtAreaLsdbLimit',
|
||||
'ospfMulticastExtensions' => '',
|
||||
'ospfExitOverflowInterval' => 'ospfv3ExitOverflowInterval',
|
||||
'ospfDemandExtensions' => 'ospfv3DemandExtensions'];
|
||||
|
||||
// Loop array of entries and update
|
||||
$ospf_instance_id = $ospf_instance_db['ospf_instance_id'];
|
||||
$ospf_instance_id = $ospf_instance_db['ospf_instance_id'];
|
||||
|
||||
if ($ospf_instance_poll['ospfv3AdminStatus'] !== 'enabled') {
|
||||
$ospf_instance_poll['ospfv3AdminStatus'] = 'disabled';
|
||||
$ospf_instance_poll['ospfv3AdminStatus'] = 'disabled';
|
||||
}
|
||||
if ($ospf_instance_poll['ospfv3VersionNumber'] !== 'version3') {
|
||||
$ospf_instance_poll['ospfv3VersionNumber'] = 'version3';
|
||||
$ospf_instance_poll['ospfv3VersionNumber'] = 'version3';
|
||||
}
|
||||
// Not exist in version3:
|
||||
$ospf_instance_poll['ospfExternLsaCksumSum'] = '0';
|
||||
$ospf_instance_poll['ospfTOSSupport'] = 'false';
|
||||
$ospf_instance_poll['ospfExternLsaCksumSum'] = '0';
|
||||
$ospf_instance_poll['ospfTOSSupport'] = 'false';
|
||||
$ospf_instance_poll['ospfMulticastExtensions'] = '0';
|
||||
|
||||
$ospf_instance_update = [];
|
||||
foreach ($ospf_oids_db as $field => $oid) {
|
||||
if (in_array($field, [ 'ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus', 'ospfDemandExtensions' ]) &&
|
||||
!in_array($ospf_instance_poll[$oid], [ 'true', 'false' ])) {
|
||||
// FIX invalid values
|
||||
$ospf_instance_poll[$oid] = 'false';
|
||||
}
|
||||
// Loop the OIDs
|
||||
if (empty($oid)) {
|
||||
// not exist oids in version3
|
||||
if ($ospf_instance_db[$field] != $ospf_instance_poll[$field]) {
|
||||
$ospf_instance_update[$field] = $ospf_instance_poll[$field];
|
||||
if (in_array($field, ['ospfAreaBdrRtrStatus', 'ospfASBdrRtrStatus', 'ospfDemandExtensions']) &&
|
||||
!in_array($ospf_instance_poll[$oid], ['true', 'false'])) {
|
||||
// FIX invalid values
|
||||
$ospf_instance_poll[$oid] = 'false';
|
||||
}
|
||||
// Loop the OIDs
|
||||
if (empty($oid)) {
|
||||
// not exist oids in version3
|
||||
if ($ospf_instance_db[$field] != $ospf_instance_poll[$field]) {
|
||||
$ospf_instance_update[$field] = $ospf_instance_poll[$field];
|
||||
}
|
||||
} elseif ($ospf_instance_db[$field] != $ospf_instance_poll[$oid]) {
|
||||
// If data has changed, build a query
|
||||
$ospf_instance_update[$field] = $ospf_instance_poll[$oid];
|
||||
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
|
||||
}
|
||||
} elseif ($ospf_instance_db[$field] != $ospf_instance_poll[$oid]) {
|
||||
// If data has changed, build a query
|
||||
$ospf_instance_update[$field] = $ospf_instance_poll[$oid];
|
||||
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
if ($ospf_instance_update) {
|
||||
dbUpdate($ospf_instance_update, 'ospf_instances', '`ospf_instance_id` = ?', [ $ospf_instance_id ]);
|
||||
echo('U');
|
||||
dbUpdate($ospf_instance_update, 'ospf_instances', '`ospf_instance_id` = ?', [$ospf_instance_id]);
|
||||
echo('U');
|
||||
} else {
|
||||
echo('.');
|
||||
echo('.');
|
||||
}
|
||||
$ospf_stats['instances']++; // Really in OSPF-MIB always only 1 instance (process)
|
||||
|
||||
@ -122,7 +136,7 @@ unset($ospf_instance_poll, $ospf_instance_db, $ospf_instance_update);
|
||||
|
||||
echo(PHP_EOL);
|
||||
|
||||
print_cli_data_field($mib.' Areas', 2);
|
||||
print_cli_data_field($mib . ' Areas', 2);
|
||||
|
||||
/*
|
||||
OSPFV3-MIB::ospfv3AreaImportAsExtern.0 = INTEGER: importExternal(1)
|
||||
@ -136,64 +150,68 @@ OSPFV3-MIB::ospfv3AreaRowStatus.0 = INTEGER: active(1)
|
||||
*/
|
||||
$ospf_areas_poll = snmpwalk_cache_oid($device, 'ospfv3AreaEntry', [], 'OSPFV3-MIB');
|
||||
|
||||
$ospf_area_oids = [ /* 'ospfAuthType' => '', */ 'ospfImportAsExtern' => 'ospfv3AreaImportAsExtern',
|
||||
'ospfSpfRuns' => 'ospfv3AreaSpfRuns', 'ospfAreaBdrRtrCount' => 'ospfv3AreaBdrRtrCount',
|
||||
'ospfAsBdrRtrCount' => 'ospfv3AreaAsBdrRtrCount', 'ospfAreaLsaCount' => 'ospfv3AreaScopeLsaCount',
|
||||
'ospfAreaLsaCksumSum' => 'ospfv3AreaScopeLsaCksumSum', 'ospfAreaSummary' => 'ospfv3AreaSummary',
|
||||
'ospfAreaStatus' => 'ospfv3AreaRowStatus' ];
|
||||
$ospf_area_oids = [ /* 'ospfAuthType' => '', */
|
||||
'ospfImportAsExtern' => 'ospfv3AreaImportAsExtern',
|
||||
'ospfSpfRuns' => 'ospfv3AreaSpfRuns',
|
||||
'ospfAreaBdrRtrCount' => 'ospfv3AreaBdrRtrCount',
|
||||
'ospfAsBdrRtrCount' => 'ospfv3AreaAsBdrRtrCount',
|
||||
'ospfAreaLsaCount' => 'ospfv3AreaScopeLsaCount',
|
||||
'ospfAreaLsaCksumSum' => 'ospfv3AreaScopeLsaCksumSum',
|
||||
'ospfAreaSummary' => 'ospfv3AreaSummary',
|
||||
'ospfAreaStatus' => 'ospfv3AreaRowStatus'];
|
||||
|
||||
// Build array of existing entries
|
||||
$ospf_areas_db = [];
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [ $device['device_id'], 'version3' ]) as $entry) {
|
||||
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfVersionNumber` = ?', [$device['device_id'], 'version3']) as $entry) {
|
||||
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
|
||||
}
|
||||
|
||||
if (OBS_DEBUG) {
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_areas_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_areas_db);
|
||||
echo("\n");
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_areas_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_areas_db);
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
foreach ($ospf_areas_poll as $ospf_area_index => $ospf_area_poll) {
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
$insert = [];
|
||||
if (!isset($ospf_areas_db[$ospf_area_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospfAreaId'] = $ospf_area_index;
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
$insert = [];
|
||||
if (!isset($ospf_areas_db[$ospf_area_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospfAreaId'] = $ospf_area_index;
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
|
||||
foreach ($ospf_area_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_area_poll[$oid];
|
||||
}
|
||||
foreach ($ospf_area_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_area_poll[$oid];
|
||||
}
|
||||
|
||||
dbInsertRowMulti($insert, 'ospf_areas');
|
||||
echo('+');
|
||||
} else {
|
||||
$ospf_area_db = $ospf_areas_db[$ospf_area_index];
|
||||
$db_update = FALSE;
|
||||
|
||||
$insert['ospf_area_id'] = $ospf_area_db['ospf_area_id'];
|
||||
foreach ($ospf_area_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_area_poll[$oid];
|
||||
if ($ospf_area_db[$field] != $ospf_area_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($db_update) {
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
dbUpdateRowMulti($insert, 'ospf_areas', 'ospf_area_id');
|
||||
echo('U');
|
||||
dbInsertRowMulti($insert, 'ospf_areas');
|
||||
echo('+');
|
||||
} else {
|
||||
echo('.');
|
||||
$ospf_area_db = $ospf_areas_db[$ospf_area_index];
|
||||
$db_update = FALSE;
|
||||
|
||||
$insert['ospf_area_id'] = $ospf_area_db['ospf_area_id'];
|
||||
foreach ($ospf_area_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_area_poll[$oid];
|
||||
if ($ospf_area_db[$field] != $ospf_area_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($db_update) {
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
dbUpdateRowMulti($insert, 'ospf_areas', 'ospf_area_id');
|
||||
echo('U');
|
||||
} else {
|
||||
echo('.');
|
||||
}
|
||||
unset($ospf_areas_db[$ospf_area_index]);
|
||||
}
|
||||
unset($ospf_areas_db[$ospf_area_index]);
|
||||
}
|
||||
$ospf_stats['areas']++;
|
||||
unset($insert);
|
||||
$ospf_stats['areas']++;
|
||||
unset($insert);
|
||||
}
|
||||
|
||||
// Multi Insert/Update
|
||||
@ -202,19 +220,19 @@ dbProcessMulti('ospf_areas');
|
||||
// Clean
|
||||
$db_delete = [];
|
||||
foreach ($ospf_areas_db as $ospf_area_db) {
|
||||
$db_delete[] = $ospf_area_db['ospf_area_id'];
|
||||
echo '-';
|
||||
$db_delete[] = $ospf_area_db['ospf_area_id'];
|
||||
echo '-';
|
||||
}
|
||||
// Multi Delete
|
||||
if (!safe_empty($db_delete)) {
|
||||
dbDelete('ospf_areas', generate_query_values_ng($db_delete, 'ospf_area_id'));
|
||||
dbDelete('ospf_areas', generate_query_values($db_delete, 'ospf_area_id'));
|
||||
}
|
||||
|
||||
unset($ospf_areas_db, $ospf_areas_poll, $db_delete);
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
print_cli_data_field($mib .' Ports', 2);
|
||||
print_cli_data_field($mib . ' Ports', 2);
|
||||
|
||||
/*
|
||||
OSPFV3-MIB::ospfv3IfAreaId.6.0 = Gauge32: 0
|
||||
@ -237,83 +255,101 @@ OSPFV3-MIB::ospfv3IfLinkLsaCksumSum.6.0 = Gauge32: 40843
|
||||
*/
|
||||
$ospf_ports_poll = snmpwalk_cache_oid($device, 'ospfv3IfEntry', [], 'OSPFV3-MIB');
|
||||
|
||||
$ospf_port_oids = [ 'ospfIfIpAddress' => 'ospfIfIpAddress', 'ospfAddressLessIf' => 'ospfAddressLessIf', // not really exist
|
||||
'ospfIfAreaId' => 'ospfv3IfAreaId', 'ospfIfType' => 'ospfv3IfType',
|
||||
'ospfIfAdminStat' => 'ospfv3IfAdminStatus', 'ospfIfRtrPriority' => 'ospfv3IfRtrPriority',
|
||||
'ospfIfTransitDelay' => 'ospfv3IfTransitDelay', 'ospfIfRetransInterval' => 'ospfv3IfRetransInterval',
|
||||
'ospfIfHelloInterval' => 'ospfv3IfHelloInterval', 'ospfIfRtrDeadInterval' => 'ospfv3IfRtrDeadInterval',
|
||||
'ospfIfState' => 'ospfv3IfState', 'ospfIfDesignatedRouter' => 'ospfv3IfDesignatedRouter',
|
||||
'ospfIfBackupDesignatedRouter' => 'ospfv3IfBackupDesignatedRouter', 'ospfIfEvents' => 'ospfv3IfEvents',
|
||||
'ospfIfStatus' => 'ospfv3IfRowStatus', 'ospfIfDemand' => 'ospfv3IfDemand',
|
||||
/* 'ospfIfPollInterval', 'ospfIfAuthKey', 'ospfIfMulticastForwarding', 'ospfIfAuthType' */ ];
|
||||
$ospf_port_oids = ['ospfIfIpAddress' => 'ospfIfIpAddress',
|
||||
'ospfAddressLessIf' => 'ospfAddressLessIf', // not really exist
|
||||
'ospfIfAreaId' => 'ospfv3IfAreaId',
|
||||
'ospfIfType' => 'ospfv3IfType',
|
||||
'ospfIfAdminStat' => 'ospfv3IfAdminStatus',
|
||||
'ospfIfRtrPriority' => 'ospfv3IfRtrPriority',
|
||||
'ospfIfTransitDelay' => 'ospfv3IfTransitDelay',
|
||||
'ospfIfRetransInterval' => 'ospfv3IfRetransInterval',
|
||||
'ospfIfHelloInterval' => 'ospfv3IfHelloInterval',
|
||||
'ospfIfRtrDeadInterval' => 'ospfv3IfRtrDeadInterval',
|
||||
'ospfIfState' => 'ospfv3IfState',
|
||||
'ospfIfDesignatedRouter' => 'ospfv3IfDesignatedRouter',
|
||||
'ospfIfBackupDesignatedRouter' => 'ospfv3IfBackupDesignatedRouter',
|
||||
'ospfIfEvents' => 'ospfv3IfEvents',
|
||||
'ospfIfStatus' => 'ospfv3IfRowStatus',
|
||||
'ospfIfDemand' => 'ospfv3IfDemand',
|
||||
/* 'ospfIfPollInterval', 'ospfIfAuthKey', 'ospfIfMulticastForwarding', 'ospfIfAuthType' */];
|
||||
|
||||
// Build array of existing entries
|
||||
// V3 always have 2 part index, ie: 6.0
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` REGEXP ?',
|
||||
[ $device['device_id'], '^[[:digit:]]+\.[[:digit:]]+$' ]) as $entry) {
|
||||
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
|
||||
if (get_db_version() < 493) {
|
||||
// CLEANME. Remove after CE 24.xx
|
||||
// V3 always have 2 part index, ie: 6.0
|
||||
$sql = 'SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` REGEXP ?';
|
||||
$params = [ $device['device_id'], '^[[:digit:]]+\.[[:digit:]]+$' ];
|
||||
} else {
|
||||
$sql = 'SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospfVersionNumber` = ?';
|
||||
$params = [ $device['device_id'], 'version3' ];
|
||||
}
|
||||
$ospf_ports_db = [];
|
||||
foreach (dbFetchRows($sql, $params) as $entry) {
|
||||
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
|
||||
}
|
||||
|
||||
if (OBS_DEBUG) {
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_ports_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_ports_db);
|
||||
echo("\n");
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_ports_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_ports_db);
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
foreach ($ospf_ports_poll as $ospf_port_index => $ospf_port_poll) {
|
||||
$insert = [];
|
||||
$insert = [];
|
||||
|
||||
// Get associated port
|
||||
list($ospf_ifIndex, $ospf_inst) = explode('.', $ospf_port_index);
|
||||
$ospf_port_poll['ospfAddressLessIf'] = $ospf_ifIndex;
|
||||
$ospf_port_poll['ospfIfIpAddress'] = '::';
|
||||
$insert['port_id'] = 0; // Unknown
|
||||
if ($ospf_port_poll['ospfAddressLessIf'] &&
|
||||
$port = get_port_by_index_cache($device, $ospf_port_poll['ospfAddressLessIf'])) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
// Get associated port
|
||||
[$ospf_ifIndex, $ospf_inst] = explode('.', $ospf_port_index);
|
||||
$ospf_port_poll['ospfAddressLessIf'] = $ospf_ifIndex;
|
||||
$ospf_port_poll['ospfIfIpAddress'] = '::';
|
||||
$insert['port_id'] = 0; // Unknown
|
||||
if ($ospf_port_poll['ospfAddressLessIf'] &&
|
||||
$port = get_port_by_index_cache($device, $ospf_port_poll['ospfAddressLessIf'])) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
|
||||
// Get IPv6 address when possible
|
||||
if ($ospf_ip = dbFetchCell('SELECT `ipv6_address` FROM `ipv6_addresses` WHERE `port_id` = ?', [ $port['port_id'] ])) {
|
||||
$ospf_port_poll['ospfIfIpAddress'] = $ospf_ip;
|
||||
}
|
||||
}
|
||||
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
if (!isset($ospf_ports_db[$ospf_port_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospf_port_id'] = $ospf_port_index;
|
||||
|
||||
foreach ($ospf_port_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_port_poll[$oid];
|
||||
// Get IPv6 address when possible
|
||||
if ($ospf_ip = dbFetchCell('SELECT `ipv6_address` FROM `ipv6_addresses` WHERE `port_id` = ?', [$port['port_id']])) {
|
||||
$ospf_port_poll['ospfIfIpAddress'] = $ospf_ip;
|
||||
}
|
||||
}
|
||||
|
||||
dbInsertRowMulti($insert, 'ospf_ports');
|
||||
echo('+');
|
||||
} else {
|
||||
$ospf_port_db = $ospf_ports_db[$ospf_port_index];
|
||||
$db_update = FALSE;
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
if (!isset($ospf_ports_db[$ospf_port_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospf_port_id'] = $ospf_port_index;
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
|
||||
$insert['ospf_ports_id'] = $ospf_port_db['ospf_ports_id'];
|
||||
foreach ($ospf_port_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_port_poll[$oid];
|
||||
if ($ospf_port_db[$field] != $ospf_port_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($db_update) {
|
||||
dbUpdateRowMulti($insert, 'ospf_ports', 'ospf_ports_id');
|
||||
echo('U');
|
||||
foreach ($ospf_port_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_port_poll[$oid];
|
||||
}
|
||||
|
||||
dbInsertRowMulti($insert, 'ospf_ports');
|
||||
echo('+');
|
||||
} else {
|
||||
echo('.');
|
||||
$ospf_port_db = $ospf_ports_db[$ospf_port_index];
|
||||
$db_update = FALSE;
|
||||
|
||||
$insert['ospf_ports_id'] = $ospf_port_db['ospf_ports_id'];
|
||||
foreach ($ospf_port_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_port_poll[$oid];
|
||||
if ($ospf_port_db[$field] != $ospf_port_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($db_update) {
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
dbUpdateRowMulti($insert, 'ospf_ports', 'ospf_ports_id');
|
||||
echo('U');
|
||||
} else {
|
||||
echo('.');
|
||||
}
|
||||
unset($ospf_ports_db[$ospf_port_index]);
|
||||
}
|
||||
unset($ospf_ports_db[$ospf_port_index]);
|
||||
}
|
||||
$ospf_stats['ports']++;
|
||||
unset($insert);
|
||||
$ospf_stats['ports']++;
|
||||
unset($insert);
|
||||
}
|
||||
|
||||
// Multi Insert/Update
|
||||
@ -322,12 +358,12 @@ dbProcessMulti('ospf_ports');
|
||||
// Clean
|
||||
$db_delete = [];
|
||||
foreach ($ospf_ports_db as $ospf_port_db) {
|
||||
$db_delete[] = $ospf_port_db['ospf_ports_id'];
|
||||
echo '-';
|
||||
$db_delete[] = $ospf_port_db['ospf_ports_id'];
|
||||
echo '-';
|
||||
}
|
||||
// Multi Delete
|
||||
if (!safe_empty($db_delete)) {
|
||||
dbDelete('ospf_ports', generate_query_values_ng($db_delete, 'ospf_ports_id'));
|
||||
dbDelete('ospf_ports', generate_query_values($db_delete, 'ospf_ports_id'));
|
||||
}
|
||||
|
||||
unset($ospf_ports_db, $ospf_ports_poll, $db_delete);
|
||||
@ -349,96 +385,108 @@ OSPFV3-MIB::ospfv3NbrIfId.4.0.1602414725 = INTEGER: 4
|
||||
*/
|
||||
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'ospfv3NbrEntry', [], 'OSPFV3-MIB');
|
||||
|
||||
$ospf_nbr_oids = [ 'ospfNbrIpAddr' => 'ospfv3NbrAddress', 'ospfNbrAddressLessIndex' => 'ospfv3NbrIfId',
|
||||
'ospfNbrRtrId' => 'ospfv3NbrRtrId',
|
||||
'ospfNbrOptions' => 'ospfv3NbrOptions', 'ospfNbrPriority' => 'ospfv3NbrPriority',
|
||||
'ospfNbrState' => 'ospfv3NbrState', 'ospfNbrEvents' => 'ospfv3NbrEvents',
|
||||
'ospfNbrLsRetransQLen' => 'ospfv3NbrLsRetransQLen',
|
||||
/* 'ospfNbmaNbrStatus', 'ospfNbmaNbrPermanence', */
|
||||
'ospfNbrHelloSuppressed' => 'ospfv3NbrHelloSuppressed' ];
|
||||
$ospf_nbr_oids = ['ospfNbrIpAddr' => 'ospfv3NbrAddress',
|
||||
'ospfNbrAddressLessIndex' => 'ospfv3NbrIfId',
|
||||
'ospfNbrRtrId' => 'ospfv3NbrRtrId',
|
||||
'ospfNbrOptions' => 'ospfv3NbrOptions',
|
||||
'ospfNbrPriority' => 'ospfv3NbrPriority',
|
||||
'ospfNbrState' => 'ospfv3NbrState',
|
||||
'ospfNbrEvents' => 'ospfv3NbrEvents',
|
||||
'ospfNbrLsRetransQLen' => 'ospfv3NbrLsRetransQLen',
|
||||
/* 'ospfNbmaNbrStatus', 'ospfNbmaNbrPermanence', */
|
||||
'ospfNbrHelloSuppressed' => 'ospfv3NbrHelloSuppressed'];
|
||||
|
||||
// Build array of existing entries
|
||||
// V3 always have 3 part index, ie: .4.0.1602414725
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?',
|
||||
[ $device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){2}$' ]) as $entry) {
|
||||
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
|
||||
if (get_db_version() < 493) {
|
||||
// CLEANME. Remove after CE 24.xx
|
||||
// V3 always have 3 part index, ie: .4.0.1602414725
|
||||
$sql = 'SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` REGEXP ?';
|
||||
$params = [ $device['device_id'], '^[[:digit:]]+(\.[[:digit:]]+){2}$' ];
|
||||
} else {
|
||||
$sql = 'SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospfVersionNumber` = ?';
|
||||
$params = [ $device['device_id'], 'version3' ];
|
||||
}
|
||||
foreach (dbFetchRows($sql, $params) as $entry) {
|
||||
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
|
||||
}
|
||||
|
||||
if (OBS_DEBUG) {
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_nbrs_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_nbrs_db);
|
||||
echo("\n");
|
||||
echo("\nPolled: ");
|
||||
print_vars($ospf_nbrs_poll);
|
||||
echo('Database: ');
|
||||
print_vars($ospf_nbrs_db);
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
foreach ($ospf_nbrs_poll as $ospf_nbr_index => $ospf_nbr_poll) {
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
$insert = [];
|
||||
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
|
||||
$insert = [];
|
||||
|
||||
// Get associated port
|
||||
list($ospf_ifIndex, $ospf_inst, $ospf_rtr) = explode('.', $ospf_nbr_index);
|
||||
$ospf_nbr_poll['ospfv3NbrRtrId'] = $ospf_rtr;
|
||||
$ospf_nbr_poll['ospfv3NbrAddress'] = hex2ip($ospf_nbr_poll['ospfv3NbrAddress']);
|
||||
// Get associated port
|
||||
[$ospf_ifIndex, $ospf_inst, $ospf_rtr] = explode('.', $ospf_nbr_index);
|
||||
$ospf_nbr_poll['ospfv3NbrRtrId'] = $ospf_rtr;
|
||||
$ospf_nbr_poll['ospfv3NbrAddress'] = hex2ip($ospf_nbr_poll['ospfv3NbrAddress']);
|
||||
|
||||
$insert['port_id'] = NULL; // Unknown
|
||||
if ($ospf_nbr_poll['ospfv3NbrIfId']) {
|
||||
if ($port = get_port_by_index_cache($device, $ospf_nbr_poll['ospfv3NbrIfId'])) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
}
|
||||
} elseif ($ospf_ifIndex) {
|
||||
if ($port = get_port_by_index_cache($device, $ospf_ifIndex)) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
}
|
||||
} else {
|
||||
$ids = get_entity_ids_ip_by_network('port', $ospf_nbr_poll['ospfv3NbrAddress'], generate_query_values_and($device['device_id'], 'device_id'));
|
||||
if (safe_count($ids)) {
|
||||
$insert['port_id'] = current($ids);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($ospf_nbrs_db[$ospf_nbr_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospf_nbr_id'] = $ospf_nbr_index;
|
||||
|
||||
if (is_null($insert['port_id'])) {
|
||||
$insert['port_id'] = [ 'NULL' ];
|
||||
}
|
||||
foreach ($ospf_nbr_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_nbr_poll[$oid];
|
||||
}
|
||||
|
||||
dbInsertRowMulti($insert, 'ospf_nbrs');
|
||||
echo('+');
|
||||
} else {
|
||||
$ospf_nbr_db = $ospf_nbrs_db[$ospf_nbr_index];
|
||||
$db_update = FALSE;
|
||||
|
||||
$insert['ospf_nbrs_id'] = $ospf_nbr_db['ospf_nbrs_id'];
|
||||
foreach ($ospf_nbr_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_nbr_poll[$oid];
|
||||
if ($ospf_nbr_db[$field] != $ospf_nbr_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($ospf_nbr_db['port_id'] != $insert['port_id']) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
if ($db_update) {
|
||||
if (is_null($insert['port_id'])) {
|
||||
$insert['port_id'] = [ 'NULL' ];
|
||||
}
|
||||
dbUpdateRowMulti($insert, 'ospf_nbrs', 'ospf_nbrs_id');
|
||||
echo('U');
|
||||
$insert['port_id'] = NULL; // Unknown
|
||||
if ($ospf_nbr_poll['ospfv3NbrIfId']) {
|
||||
if ($port = get_port_by_index_cache($device, $ospf_nbr_poll['ospfv3NbrIfId'])) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
}
|
||||
} elseif ($ospf_ifIndex) {
|
||||
if ($port = get_port_by_index_cache($device, $ospf_ifIndex)) {
|
||||
$insert['port_id'] = $port['port_id'];
|
||||
}
|
||||
} else {
|
||||
echo('.');
|
||||
$ids = get_entity_ids_ip_by_network('port', $ospf_nbr_poll['ospfv3NbrAddress'], generate_query_values_and($device['device_id'], 'device_id'));
|
||||
if (safe_count($ids)) {
|
||||
$insert['port_id'] = current($ids);
|
||||
}
|
||||
}
|
||||
unset($ospf_nbrs_db[$ospf_nbr_index]);
|
||||
}
|
||||
$ospf_stats['neighbours']++;
|
||||
unset($insert);
|
||||
|
||||
if (!isset($ospf_nbrs_db[$ospf_nbr_index])) {
|
||||
$insert['device_id'] = $device['device_id'];
|
||||
$insert['ospf_nbr_id'] = $ospf_nbr_index;
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
|
||||
if (is_null($insert['port_id'])) {
|
||||
$insert['port_id'] = 0; // keep compat with old db
|
||||
}
|
||||
foreach ($ospf_nbr_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_nbr_poll[$oid];
|
||||
}
|
||||
|
||||
dbInsertRowMulti($insert, 'ospf_nbrs');
|
||||
echo('+');
|
||||
} else {
|
||||
$ospf_nbr_db = $ospf_nbrs_db[$ospf_nbr_index];
|
||||
$db_update = FALSE;
|
||||
|
||||
$insert['ospf_nbrs_id'] = $ospf_nbr_db['ospf_nbrs_id'];
|
||||
foreach ($ospf_nbr_oids as $field => $oid) {
|
||||
// Loop the OIDs
|
||||
$insert[$field] = $ospf_nbr_poll[$oid];
|
||||
if ($ospf_nbr_db[$field] != $ospf_nbr_poll[$oid]) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
}
|
||||
if ($ospf_nbr_db['port_id'] != $insert['port_id']) {
|
||||
$db_update = TRUE;
|
||||
}
|
||||
if ($db_update) {
|
||||
$insert['ospfVersionNumber'] = 'version3';
|
||||
if (is_null($insert['port_id'])) {
|
||||
$insert['port_id'] = ['NULL'];
|
||||
}
|
||||
dbUpdateRowMulti($insert, 'ospf_nbrs', 'ospf_nbrs_id');
|
||||
echo('U');
|
||||
} else {
|
||||
echo('.');
|
||||
}
|
||||
unset($ospf_nbrs_db[$ospf_nbr_index]);
|
||||
}
|
||||
$ospf_stats['neighbours']++;
|
||||
unset($insert);
|
||||
}
|
||||
|
||||
// Multi Insert/Update
|
||||
@ -447,16 +495,28 @@ dbProcessMulti('ospf_nbrs');
|
||||
// Clean
|
||||
$db_delete = [];
|
||||
foreach ($ospf_nbrs_db as $ospf_nbr_db) {
|
||||
$db_delete[] = $ospf_nbr_db['ospf_nbrs_id'];
|
||||
echo '-';
|
||||
$db_delete[] = $ospf_nbr_db['ospf_nbrs_id'];
|
||||
echo '-';
|
||||
}
|
||||
// Multi Delete
|
||||
if (!safe_empty($db_delete)) {
|
||||
dbDelete('ospf_nbrs', generate_query_values_ng($db_delete, 'ospf_nbrs_id'));
|
||||
dbDelete('ospf_nbrs', generate_query_values($db_delete, 'ospf_nbrs_id'));
|
||||
}
|
||||
|
||||
unset($ospf_nbrs_db, $ospf_nbrs_poll, $db_delete);
|
||||
|
||||
// Create device-wide statistics RRD
|
||||
rrdtool_update_ng($device, 'ospfv3-statistics', [
|
||||
'instances' => $ospf_stats['instances'],
|
||||
'areas' => $ospf_stats['areas'],
|
||||
'ports' => $ospf_stats['ports'],
|
||||
'neighbours' => $ospf_stats['neighbours'],
|
||||
]);
|
||||
|
||||
$graphs['ospfv3_neighbours'] = TRUE;
|
||||
$graphs['ospfv3_areas'] = TRUE;
|
||||
$graphs['ospfv3_ports'] = TRUE;
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
// EOF
|
||||
|
Reference in New Issue
Block a user