Fixed OSPF duplicate DB entries (#9051)

Re-write ospf polling using Eloquent

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
Tony Murray
2018-08-21 08:06:49 -05:00
committed by Neil Lathwood
parent 29d51f4727
commit 4158615f85
7 changed files with 346 additions and 346 deletions

59
app/Models/OspfArea.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
/**
* OspfArea.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 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Models;
class OspfArea extends BaseModel
{
public $timestamps = false;
protected $fillable = [
'device_id',
'context_name',
'ospfAreaId',
'ospfAuthType',
'ospfImportAsExtern',
'ospfSpfRuns',
'ospfAreaBdrRtrCount',
'ospfAsBdrRtrCount',
'ospfAreaLsaCount',
'ospfAreaLsaCksumSum',
'ospfAreaSummary',
'ospfAreaStatus',
];
// ---- Query Scopes ----
public function scopeHasAccess($query, User $user)
{
return $this->hasDeviceAccess($query, $user);
}
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id');
}
}

View File

@@ -28,7 +28,25 @@ namespace App\Models;
class OspfInstance extends BaseModel
{
public $timestamps = false;
protected $primaryKey = 'ospf_instance_id';
protected $fillable = [
'device_id',
'ospf_instance_id',
'context_name',
'ospfRouterId',
'ospfAdminStat',
'ospfVersionNumber',
'ospfAreaBdrRtrStatus',
'ospfASBdrRtrStatus',
'ospfExternLsaCount',
'ospfExternLsaCksumSum',
'ospfTOSSupport',
'ospfOriginateNewLsas',
'ospfRxNewLsas',
'ospfExtLsdbLimit',
'ospfMulticastExtensions',
'ospfExitOverflowInterval',
'ospfDemandExtensions',
];
// ---- Query Scopes ----

62
app/Models/OspfNbr.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
/**
* OspfNbr.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 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Models;
class OspfNbr extends BaseModel
{
public $timestamps = false;
protected $fillable = [
'device_id',
'port_id',
'ospf_nbr_id',
'context_name',
'ospfNbrIpAddr',
'ospfNbrAddressLessIndex',
'ospfNbrRtrId',
'ospfNbrOptions',
'ospfNbrPriority',
'ospfNbrState',
'ospfNbrEvents',
'ospfNbrLsRetransQLen',
'ospfNbmaNbrStatus',
'ospfNbmaNbrPermanence',
'ospfNbrHelloSuppressed',
];
// ---- Query Scopes ----
public function scopeHasAccess($query, User $user)
{
return $this->hasDeviceAccess($query, $user);
}
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id');
}
}

71
app/Models/OspfPort.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
/**
* OspfPort.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 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Models;
class OspfPort extends BaseModel
{
public $timestamps = false;
protected $fillable = [
'device_id',
'port_id',
'ospf_port_id',
'context_name',
'ospfIfIpAddress',
'ospfAddressLessIf',
'ospfIfAreaId',
'ospfIfType',
'ospfIfAdminStat',
'ospfIfRtrPriority',
'ospfIfTransitDelay',
'ospfIfRetransInterval',
'ospfIfHelloInterval',
'ospfIfRtrDeadInterval',
'ospfIfPollInterval',
'ospfIfState',
'ospfIfDesignatedRouter',
'ospfIfBackupDesignatedRouter',
'ospfIfEvents',
'ospfIfAuthKey',
'ospfIfStatus',
'ospfIfMulticastForwarding',
'ospfIfDemand',
'ospfIfAuthType',
];
// ---- Query Scopes ----
public function scopeHasAccess($query, User $user)
{
return $this->hasDeviceAccess($query, $user);
}
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id');
}
}

View File

@@ -1,81 +1,14 @@
<?php
use App\Models\Device;
use App\Models\Ipv4Address;
use App\Models\OspfArea;
use App\Models\OspfInstance;
use App\Models\OspfNbr;
use App\Models\OspfPort;
use LibreNMS\RRD\RrdDefinition;
$ospf_instance_count = 0;
$ospf_port_count = 0;
$ospf_area_count = 0;
$ospf_neighbour_count = 0;
$ospf_oids_db = array(
'ospfRouterId',
'ospfAdminStat',
'ospfVersionNumber',
'ospfAreaBdrRtrStatus',
'ospfASBdrRtrStatus',
'ospfExternLsaCount',
'ospfExternLsaCksumSum',
'ospfTOSSupport',
'ospfOriginateNewLsas',
'ospfRxNewLsas',
'ospfExtLsdbLimit',
'ospfMulticastExtensions',
'ospfExitOverflowInterval',
'ospfDemandExtensions',
);
$ospf_area_oids = array(
'ospfAuthType',
'ospfImportAsExtern',
'ospfSpfRuns',
'ospfAreaBdrRtrCount',
'ospfAsBdrRtrCount',
'ospfAreaLsaCount',
'ospfAreaLsaCksumSum',
'ospfAreaSummary',
'ospfAreaStatus',
);
$ospf_port_oids = array(
'ospfIfIpAddress',
'port_id',
'ospfAddressLessIf',
'ospfIfAreaId',
'ospfIfType',
'ospfIfAdminStat',
'ospfIfRtrPriority',
'ospfIfTransitDelay',
'ospfIfRetransInterval',
'ospfIfHelloInterval',
'ospfIfRtrDeadInterval',
'ospfIfPollInterval',
'ospfIfState',
'ospfIfDesignatedRouter',
'ospfIfBackupDesignatedRouter',
'ospfIfEvents',
'ospfIfAuthKey',
'ospfIfStatus',
'ospfIfMulticastForwarding',
'ospfIfDemand',
'ospfIfAuthType',
);
$ospf_nbr_oids_db = array(
'ospfNbrIpAddr',
'ospfNbrAddressLessIndex',
'ospfNbrRtrId',
'ospfNbrOptions',
'ospfNbrPriority',
'ospfNbrState',
'ospfNbrEvents',
'ospfNbrLsRetransQLen',
'ospfNbmaNbrStatus',
'ospfNbmaNbrPermanence',
'ospfNbrHelloSuppressed',
);
$ospf_nbr_oids_rrd = array();
$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
$device_model = Device::find($device['device_id']);
if (key_exists('vrf_lite_cisco', $device) && ($device['vrf_lite_cisco'] != '')) {
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
@@ -86,294 +19,124 @@ if (key_exists('vrf_lite_cisco', $device) && ($device['vrf_lite_cisco'] != ''))
foreach ($vrfs_lite_cisco as $vrf_lite) {
$device['context_name'] = $vrf_lite['context_name'];
echo 'Processes: ';
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) {
$ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry;
}
echo ' Processes: ';
// Pull data from device
$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB');
d_echo($ospf_instances_poll);
$ospf_instances = collect();
foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) {
$tmp_insert = array(
// TODO add model listener from wireless polling PR #8607 for improved output
$instance = OspfInstance::updateOrCreate([
'device_id' => $device['device_id'],
'ospf_instance_id' => $ospf_instance_id,
'context_name' => $device['context_name'],
);
foreach ($ospf_oids_db as $oid_db) {
$tmp_insert[$oid_db] = $ospf_entry[$oid_db];
}
dbInsert($tmp_insert, 'ospf_instances');
unset($tmp_insert);
echo '+';
$entry = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name']));
$ospf_instances_db[$ospf_instance_id][$device['context_name']] = $entry;
}
], $ospf_entry);
$ospf_instances->push($instance);
}
d_echo("\nPolled: ");
d_echo($ospf_instances_poll);
d_echo('Database: ');
d_echo($ospf_instances_db);
// cleanup
OspfInstance::query()
->where(['device_id' => $device['device_id'], 'context_name' => $device['context_name']])
->whereNotIn('id', $ospf_instances->pluck('id'))->delete();
// Loop array of entries and update
if (is_array($ospf_instances_db)) {
foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) {
$ospf_instance_db = array_shift($ospf_instance_db);
if (is_array($ospf_instances_poll[$ospf_instance_id])) {
$ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id];
foreach ($ospf_oids_db as $oid) {
// Loop the OIDs
if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) {
// If data has changed, build a query
$ospf_instance_update[$oid] = $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', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_instance_id, $device['context_name']));
echo 'U';
unset($ospf_instance_update);
} else {
echo '.';
}
unset($ospf_instance_poll);
unset($ospf_instance_db);
$ospf_instance_count++;
} else {
dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name']));
}
}//end foreach
}//end if
unset($ospf_instances_poll);
unset($ospf_instances_db);
echo $ospf_instances->count();
echo ' Areas: ';
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`= ?', array($device['device_id'], $device['context_name'])) as $entry) {
$ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry;
}
// Pull data from device
$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB');
foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (empty($ospf_areas_db[$ospf_area_id][$device['context_name']])) {
$tmp_insert = array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']);
foreach ($ospf_area_oids as $oid_db) {
$tmp_insert[$oid_db] = $ospf_area[$oid_db];
}
dbInsert($tmp_insert, 'ospf_areas');
unset($tmp_insert);
echo '+';
$entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name']));
$ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry;
}
}
d_echo("\nPolled: ");
d_echo($ospf_areas_poll);
d_echo('Database: ');
d_echo($ospf_areas_db);
// Loop array of entries and update
if (is_array($ospf_areas_db)) {
foreach ($ospf_areas_db as $ospf_area_id => $ospf_area_db) {
$ospf_area_db = array_shift($ospf_area_db);
if (is_array($ospf_areas_poll[$ospf_area_id])) {
$ospf_area_poll = $ospf_areas_poll[$ospf_area_id];
foreach ($ospf_area_oids as $oid) {
// Loop the OIDs
if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) {
// If data has changed, build a query
$ospf_area_update[$oid] = $ospf_area_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME
}
$ospf_areas = collect();
foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) {
$area = OspfArea::updateOrCreate([
'device_id' => $device['device_id'],
'ospfAreaId' => $ospf_area_id,
'context_name' => $device['context_name'],
], $ospf_area);
$ospf_areas->push($area);
}
if ($ospf_area_update) {
dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name']));
echo 'U';
unset($ospf_area_update);
} else {
echo '.';
}
// cleanup
OspfArea::query()
->where(['device_id' => $device['device_id'], 'context_name' => $device['context_name']])
->whereNotIn('id', $ospf_areas->pluck('id'))->delete();
unset($ospf_area_poll);
unset($ospf_area_db);
$ospf_area_count++;
} else {
dbDelete('ospf_ports', '`device_id` = ? AND `ospfIfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name']));
}//end if
}//end foreach
}//end if
echo $ospf_areas->count();
unset($ospf_areas_db);
unset($ospf_areas_poll);
// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB");
// print_r($ospf_ports);
echo ' Ports: ';
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) {
$ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry;
}
// Pull data from device
$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB');
foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (empty($ospf_ports_db[$ospf_port_id][$device['context_name']])) {
$tmp_insert = array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']);
foreach ($ospf_port_oids as $oid_db) {
$tmp_insert[$oid_db] = $ospf_port[$oid_db];
}
// Set port_id temporarily for mysql strict mode
$tmp_insert['port_id'] = 0;
dbInsert($tmp_insert, 'ospf_ports');
unset($tmp_insert);
echo '+';
$ospf_ports_db[$ospf_port_id][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name']));
}
}
d_echo("\nPolled: ");
d_echo($ospf_ports_poll);
d_echo('Database: ');
d_echo($ospf_ports_db);
// Loop array of entries and update
if (is_array($ospf_ports_db)) {
foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) {
$ospf_port_db = array_shift($ospf_port_db);
if (is_array($ospf_ports_poll[$ospf_port_id])) {
$ospf_port_poll = $ospf_ports_poll[$ospf_port_id];
if ($ospf_port_poll['ospfAddressLessIf']) {
$ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf']));
$ospf_ports = collect();
foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) {
// find port_id
if ($ospf_port['ospfAddressLessIf']) {
$ospf_port['port_id'] = $device_model->ports()->where('ifIndex', $ospf_port['ospfAddressLessIf'])->value('port_id');
} else {
$ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name']));
// FIXME force same device ?
$ospf_port['port_id'] = Ipv4Address::query()
->where('ipv4_address', $ospf_port['ospfIfIpAddress'])
->where('context_name', $device['context_name'])
->value('port_id');
}
foreach ($ospf_port_oids as $oid) {
// Loop the OIDs
if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) {
// If data has changed, build a query
$ospf_port_update[$oid] = $ospf_port_poll[$oid];
// log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME
}
$port = OspfPort::updateOrCreate([
'device_id' => $device['device_id'],
'ospf_port_id' => $ospf_port_id,
'context_name' => $device['context_name'],
], $ospf_port);
$ospf_ports->push($port);
}
if ($ospf_port_update) {
dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name']));
echo 'U';
unset($ospf_port_update);
} else {
echo '.';
}
// cleanup
OspfPort::query()
->where(['device_id' => $device['device_id'], 'context_name' => $device['context_name']])
->whereNotIn('id', $ospf_ports->pluck('id'))->delete();
unset($ospf_port_poll);
unset($ospf_port_db);
$ospf_port_count++;
} else {
dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name']));
// ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'");
echo '-';
}//end if
}//end foreach
}//end if
unset($ospf_ports_poll);
echo $ospf_ports->count();
echo ' Neighbours: ';
// Build array of existing entries
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) {
$ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry;
}
// Pull data from device
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB');
foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) {
// If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array
if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) {
$tmp_insert = array('device_id' => $device['device_id'], 'port_id' => 0, 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']);
foreach ($ospf_nbr_oids_db as $oid_db) {
$tmp_insert[$oid_db] = $ospf_nbr[$oid_db];
}
dbInsert($tmp_insert, 'ospf_nbrs');
unset($tmp_insert);
echo '+';
$entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name']));
$ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry;
}
}
d_echo("\nPolled: ");
d_echo($ospf_nbrs_poll);
d_echo('Database: ');
d_echo($ospf_nbrs_db);
// Loop array of entries and update
if (is_array($ospf_nbrs_db)) {
foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) {
$ospf_nbr_db = array_shift($ospf_nbr_db);
if (is_array($ospf_nbrs_poll[$ospf_nbr_id])) {
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_id];
$ospf_neighbours = collect();
foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) {
// get neighbor port_id
$ospf_nbr['port_id'] = Ipv4Address::query()
->where('ipv4_address', $ospf_nbr['ospfNbrIpAddr'])
->where('context_name', $device['context_name'])
->value('port_id');
$ospf_nbr['ospf_nbr_id'] = $ospf_nbr_id;
$ospf_nbr_poll['port_id'] = (int)dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ospf_nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name']));
$neighbour = OspfNbr::updateOrCreate([
'device_id' => $device['device_id'],
'ospf_nbr_id' => $ospf_nbr_id,
'context_name' => $device['context_name'],
], $ospf_nbr);
if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) {
if (!empty($ospf_nbr_poll['port_id'])) {
$ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']);
} else {
$ospf_nbr_update = array('port_id' => array('NULL'));
}
$ospf_neighbours->push($neighbour);
}
foreach ($ospf_nbr_oids as $oid) {
// Loop the OIDs
d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n");
// cleanup
OspfNbr::query()
->where(['device_id' => $device['device_id'], 'context_name' => $device['context_name']])
->whereNotIn('id', $ospf_neighbours->pluck('id'))->delete();
if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) {
// If data has changed, build a query
$ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid];
// log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME
}
}
if ($ospf_nbr_update) {
dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name']));
echo 'U';
unset($ospf_nbr_update);
} else {
echo '.';
}
unset($ospf_nbr_poll);
unset($ospf_nbr_db);
$ospf_nbr_count++;
} else {
dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name']));
echo '-';
}//end if
}//end foreach
}//end if
unset($ospf_nbrs_db);
unset($ospf_nbrs_poll);
echo "\n";
echo $ospf_neighbours->count();
}
unset($device['context_name'], $vrfs_lite_cisco, $vrf_lite);
// Create device-wide statistics RRD
$rrd_def = RrdDefinition::make()
->addDataset('instances', 'GAUGE', 0, 1000000)
@@ -381,29 +144,39 @@ $rrd_def = RrdDefinition::make()
->addDataset('ports', 'GAUGE', 0, 1000000)
->addDataset('neighbours', 'GAUGE', 0, 1000000);
$fields = array(
'instances' => $ospf_instance_count,
'areas' => $ospf_area_count,
'ports' => $ospf_port_count,
'neighbours' => $ospf_neighbour_count,
);
$fields = [
'instances' => $ospf_instances->count(),
'areas' => $ospf_areas->count(),
'ports' => $ospf_ports->count(),
'neighbours' => $ospf_neighbours->count(),
];
$tags = compact('rrd_def');
data_update($device, 'ospf-statistics', $tags, $fields);
echo "\n";
echo PHP_EOL;
unset(
$ospf_instance_count,
$ospf_port_count,
$ospf_area_count,
$ospf_neighbour_count,
$ospf_oids_db,
$ospf_area_oids,
$ospf_port_oids,
$ospf_nbr_oids_db,
$ospf_nbr_oids_rrd,
$ospf_nbr_oids,
$ospf_instances,
$ospf_areas,
$ospf_ports,
$ospf_neighbours,
$ospf_instances_poll,
$ospf_areas_poll,
$ospf_ports_poll,
$ospf_nbrs_poll,
$ospf_entry,
$instance,
$ospf_instance_id,
$ospf_area,
$area,
$ospf_area_id,
$ospf_port,
$port,
$ospf_port_id,
$ospf_nbr,
$neighbour,
$ospf_nbr_id,
$rrd_def,
$fields,
$tags

View File

@@ -168,8 +168,8 @@ application_metrics:
Columns:
- { Field: app_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: metric, Type: varchar(32), 'Null': false, Extra: '' }
- { Field: value, Type: 'double', 'Null': true, Extra: '' }
- { Field: value_prev, Type: 'double', 'Null': true, Extra: '' }
- { Field: value, Type: double, 'Null': true, Extra: '' }
- { Field: value_prev, Type: double, 'Null': true, Extra: '' }
Indexes:
application_metrics_app_id_metric_uindex: { Name: application_metrics_app_id_metric_uindex, Columns: [app_id, metric], Unique: true, Type: BTREE }
authlog:
@@ -938,6 +938,7 @@ notifications_attribs:
PRIMARY: { Name: PRIMARY, Columns: [attrib_id], Unique: true, Type: BTREE }
ospf_areas:
Columns:
- { Field: id, Type: int(11), 'Null': false, Extra: auto_increment }
- { Field: device_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: ospfAreaId, Type: varchar(32), 'Null': false, Extra: '' }
- { Field: ospfAuthType, Type: varchar(64), 'Null': false, Extra: '' }
@@ -951,9 +952,11 @@ ospf_areas:
- { Field: ospfAreaStatus, Type: varchar(64), 'Null': false, Extra: '' }
- { Field: context_name, Type: varchar(128), 'Null': true, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
device_area: { Name: device_area, Columns: [device_id, ospfAreaId, context_name], Unique: true, Type: BTREE }
ospf_instances:
Columns:
- { Field: id, Type: int(11), 'Null': false, Extra: auto_increment }
- { Field: device_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: ospf_instance_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: ospfRouterId, Type: varchar(32), 'Null': false, Extra: '' }
@@ -972,11 +975,13 @@ ospf_instances:
- { Field: ospfDemandExtensions, Type: varchar(32), 'Null': true, Extra: '' }
- { Field: context_name, Type: varchar(128), 'Null': true, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
device_id: { Name: device_id, Columns: [device_id, ospf_instance_id, context_name], Unique: true, Type: BTREE }
ospf_nbrs:
Columns:
- { Field: id, Type: int(11), 'Null': false, Extra: auto_increment }
- { Field: device_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: port_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: port_id, Type: int(11), 'Null': true, Extra: '' }
- { Field: ospf_nbr_id, Type: varchar(32), 'Null': false, Extra: '' }
- { Field: ospfNbrIpAddr, Type: varchar(32), 'Null': false, Extra: '' }
- { Field: ospfNbrAddressLessIndex, Type: int(11), 'Null': false, Extra: '' }
@@ -991,9 +996,11 @@ ospf_nbrs:
- { Field: ospfNbrHelloSuppressed, Type: varchar(32), 'Null': false, Extra: '' }
- { Field: context_name, Type: varchar(128), 'Null': true, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
device_id: { Name: device_id, Columns: [device_id, ospf_nbr_id, context_name], Unique: true, Type: BTREE }
ospf_ports:
Columns:
- { Field: id, Type: int(11), 'Null': false, Extra: auto_increment }
- { Field: device_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: port_id, Type: int(11), 'Null': false, Extra: '' }
- { Field: ospf_port_id, Type: varchar(32), 'Null': false, Extra: '' }
@@ -1019,6 +1026,7 @@ ospf_ports:
- { Field: ospfIfAuthType, Type: varchar(32), 'Null': true, Extra: '' }
- { Field: context_name, Type: varchar(128), 'Null': true, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
device_id: { Name: device_id, Columns: [device_id, ospf_port_id, context_name], Unique: true, Type: BTREE }
packages:
Columns:

9
sql-schema/260.sql Normal file
View File

@@ -0,0 +1,9 @@
DELETE FROM ospf_instances WHERE context_name = '';
DELETE FROM ospf_areas WHERE context_name = '';
DELETE FROM ospf_ports WHERE context_name = '';
DELETE FROM ospf_nbrs WHERE context_name = '';
ALTER TABLE ospf_instances ADD id int auto_increment NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE ospf_areas ADD id int auto_increment NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE ospf_ports ADD id int auto_increment NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE ospf_nbrs ADD id int auto_increment NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE ospf_nbrs MODIFY port_id int(11);