mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
ospf fixes from Bill Fenner, plus some cleanup
git-svn-id: http://www.observium.org/svn/observer/trunk@2217 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -14,17 +14,17 @@ $ospf_oids_db = array('ospfRouterId', 'ospfAdminStat', 'ospfVersionNumber', 'osp
|
||||
|
||||
### Build array of existing entries
|
||||
$query = mysql_query("SELECT * FROM `ospf_instances` WHERE `device_id` = '".$device['device_id']."'");
|
||||
while($entry = mysql_fetch_assoc($query))
|
||||
while ($entry = mysql_fetch_assoc($query))
|
||||
{
|
||||
$ospf_instances_db[$entry['ospf_instance_id']] = $entry;
|
||||
}
|
||||
|
||||
### Pull data from device
|
||||
$ospf_instances_poll = snmpwalk_cache_oid($device, "OSPF-MIB::ospfGeneralGroup", array(), "OSPF-MIB");
|
||||
foreach($ospf_instances_poll as $ospf_instance_id => $ospf_entry)
|
||||
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(!isset($ospf_instances_db[$ospf_instance_id]))
|
||||
if (!isset($ospf_instances_db[$ospf_instance_id]))
|
||||
{
|
||||
$query = "INSERT INTO `ospf_instances` (`device_id`, `ospf_instance_id`) VALUES ('".$device['device_id']."','".$ospf_instance_id."')";
|
||||
echo($query);
|
||||
@@ -36,7 +36,7 @@ foreach($ospf_instances_poll as $ospf_instance_id => $ospf_entry)
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
if ($debug) {
|
||||
echo("\nPolled: ");
|
||||
print_r($ospf_instances_poll);
|
||||
echo("Database: ");
|
||||
@@ -47,9 +47,9 @@ if($debug) {
|
||||
### Loop array of entries and update
|
||||
if (is_array($ospf_instances_db))
|
||||
{
|
||||
foreach($ospf_instances_db as $ospf_instance_db)
|
||||
foreach ($ospf_instances_db as $ospf_instance_db)
|
||||
{
|
||||
$ospf_instance_poll = $ospf_instances_poll[$ospf_db['ospf_instance_id']];
|
||||
$ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']];
|
||||
foreach ($ospf_oids_db as $oid)
|
||||
{ // Loop the OIDs
|
||||
if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid])
|
||||
@@ -58,12 +58,12 @@ if (is_array($ospf_instances_db))
|
||||
#log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['interface_id']); ## FIXME
|
||||
}
|
||||
}
|
||||
if($update)
|
||||
if ($ospf_instance_update)
|
||||
{
|
||||
$query = "UPDATE `ospf_instances` SET `ospf_instance_id` = '".$ospf_instance_db['ospf_instance_id']."'".$ospf_instance_update." WHERE `device_id` = '".$device['device_id']."' AND `ospf_instance_id` = '".$ospf_instance_id."'";
|
||||
if($debug) {echo($query);} ## Debug
|
||||
if ($debug) {echo($query);} ## Debug
|
||||
mysql_query($query);
|
||||
if($debug) {echo(mysql_error());} ## Debug
|
||||
if ($debug) {echo(mysql_error());} ## Debug
|
||||
echo("U");
|
||||
unset($ospf_instance_update);
|
||||
} else {
|
||||
@@ -84,7 +84,7 @@ $ospf_area_oids = array('ospfAuthType','ospfImportAsExtern','ospfSpfRuns','ospfA
|
||||
|
||||
### Build array of existing entries
|
||||
$query = mysql_query("SELECT * FROM `ospf_areas` WHERE `device_id` = '".$device['device_id']."'");
|
||||
while($entry = mysql_fetch_assoc($query))
|
||||
while ($entry = mysql_fetch_assoc($query))
|
||||
{
|
||||
$ospf_areas_db[$entry['ospfAreaId']] = $entry;
|
||||
}
|
||||
@@ -92,10 +92,10 @@ while($entry = mysql_fetch_assoc($query))
|
||||
### 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)
|
||||
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(!isset($ospf_areas_db[$ospf_area_id]))
|
||||
if (!isset($ospf_areas_db[$ospf_area_id]))
|
||||
{
|
||||
mysql_query("INSERT INTO `ospf_areas` (`device_id`, `ospfAreaId`) VALUES ('".$device['device_id']."','".$ospf_area_id."') ");
|
||||
echo("+");
|
||||
@@ -104,7 +104,7 @@ foreach($ospf_areas_poll as $ospf_area_id => $ospf_area)
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
if ($debug) {
|
||||
echo("\nPolled: ");
|
||||
print_r($ospf_areas_poll);
|
||||
echo("Database: ");
|
||||
@@ -116,7 +116,7 @@ if($debug) {
|
||||
### Loop array of entries and update
|
||||
if (is_array($ospf_areas_db))
|
||||
{
|
||||
foreach($ospf_areas_db as $ospf_area_db)
|
||||
foreach ($ospf_areas_db as $ospf_area_db)
|
||||
{
|
||||
$ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']];
|
||||
foreach ($ospf_area_oids as $oid)
|
||||
@@ -127,10 +127,11 @@ if (is_array($ospf_areas_db))
|
||||
#log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['interface_id']); ## FIXME
|
||||
}
|
||||
}
|
||||
if($update)
|
||||
if ($ospf_area_update)
|
||||
{
|
||||
mysql_query("UPDATE `ospf_areas` SET `ospfAreaId` = '".$ospf_area_db['ospfAreaId']."'".$ospf_area_update." WHERE `device_id` = '".$device['device_id']."' AND `ospfAreaId` = '".$ospf_area_id."'");
|
||||
if($debug) { echo("UPDATE `ospf_instances` SET `ospfAreaId` = '".$ospf_area_db['ospfAreaId']."'".$ospf_area_update." WHERE `device_id` = '".$device['device_id']."' AND `ospfAreaId` = '".$ospf_area_id."'");}
|
||||
$sql = "UPDATE `ospf_areas` SET `ospfAreaId` = '".$ospf_area_db['ospfAreaId']."'".$ospf_area_update." WHERE `device_id` = '".$device['device_id']."' AND `ospfAreaId` = '".$ospf_area_id."'";
|
||||
mysql_query($sql);
|
||||
if ($debug) { echo("$sql\n"); }
|
||||
echo("U");
|
||||
unset($ospf_area_update);
|
||||
} else {
|
||||
@@ -155,7 +156,7 @@ $ospf_port_oids = array('ospfIfIpAddress','interface_id','ospfAddressLessIf','os
|
||||
|
||||
### Build array of existing entries
|
||||
$query = mysql_query("SELECT * FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."'");
|
||||
while($entry = mysql_fetch_assoc($query))
|
||||
while ($entry = mysql_fetch_assoc($query))
|
||||
{
|
||||
$ospf_ports_db[$entry['ospf_port_id']] = $entry;
|
||||
}
|
||||
@@ -163,10 +164,10 @@ while($entry = mysql_fetch_assoc($query))
|
||||
### 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)
|
||||
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(!isset($ospf_ports_db[$ospf_port_id]))
|
||||
if (!isset($ospf_ports_db[$ospf_port_id]))
|
||||
{
|
||||
mysql_query("INSERT INTO `ospf_ports` (`device_id`, `ospf_port_id`) VALUES ('".$device['device_id']."','".$ospf_port_id."') ");
|
||||
echo("+");
|
||||
@@ -175,7 +176,8 @@ foreach($ospf_ports_poll as $ospf_port_id => $ospf_port)
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
if ($debug)
|
||||
{
|
||||
echo("\nPolled: ");
|
||||
print_r($ospf_ports_poll);
|
||||
echo("Database: ");
|
||||
@@ -184,13 +186,15 @@ if($debug) {
|
||||
}
|
||||
|
||||
### Loop array of entries and update
|
||||
if (is_array($ospf_ports_db)){
|
||||
foreach($ospf_ports_db as $ospf_port_id => $ospf_port_db)
|
||||
if (is_array($ospf_ports_db))
|
||||
{
|
||||
foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db)
|
||||
{
|
||||
if(is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) {
|
||||
if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']]))
|
||||
{
|
||||
$ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']];
|
||||
|
||||
if($ospf_port_poll['ospfAddressLessIf'])
|
||||
if ($ospf_port_poll['ospfAddressLessIf'])
|
||||
{
|
||||
$ospf_port_poll['interface_id'] = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$ospf_port_poll['ospfAddressLessIf']."'"),0);
|
||||
} else {
|
||||
@@ -205,11 +209,11 @@ if (is_array($ospf_ports_db)){
|
||||
#log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['interface_id']); ## FIXME
|
||||
}
|
||||
}
|
||||
if($ospf_port_update)
|
||||
if ($ospf_port_update)
|
||||
{
|
||||
$query = "UPDATE `ospf_ports` SET `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'".$ospf_port_update." WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_id."'";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query"); }
|
||||
if ($debug) { echo("$query"); }
|
||||
echo("U");
|
||||
unset($ospf_port_update);
|
||||
} else {
|
||||
@@ -245,7 +249,7 @@ $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
|
||||
|
||||
### Build array of existing entries
|
||||
$nbr_query = mysql_query("SELECT * FROM `ospf_nbrs` WHERE `device_id` = '".$device['device_id']."'");
|
||||
while($nbr_entry = mysql_fetch_assoc($nbr_query))
|
||||
while ($nbr_entry = mysql_fetch_assoc($nbr_query))
|
||||
{
|
||||
$ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry;
|
||||
}
|
||||
@@ -253,10 +257,10 @@ while($nbr_entry = mysql_fetch_assoc($nbr_query))
|
||||
### 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)
|
||||
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]))
|
||||
if (!isset($ospf_nbrs_db[$ospf_nbr_id]))
|
||||
{
|
||||
mysql_query("INSERT INTO `ospf_nbrs` (`device_id`, `ospf_nbr_id`) VALUES ('".$device['device_id']."','".$ospf_nbr_id."') ");
|
||||
echo("+");
|
||||
@@ -265,7 +269,8 @@ foreach($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr)
|
||||
}
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
if ($debug)
|
||||
{
|
||||
echo("\nPolled: ");
|
||||
print_r($ospf_nbrs_poll);
|
||||
echo("Database: ");
|
||||
@@ -274,10 +279,12 @@ if($debug) {
|
||||
}
|
||||
|
||||
### Loop array of entries and update
|
||||
if (is_array($ospf_nbrs_db)){
|
||||
foreach($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db)
|
||||
if (is_array($ospf_nbrs_db))
|
||||
{
|
||||
foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db)
|
||||
{
|
||||
if(is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) {
|
||||
if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]))
|
||||
{
|
||||
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']];
|
||||
|
||||
$ospf_nbr_poll['interface_id'] = @mysql_result(mysql_query("SELECT A.`interface_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = '".$ospf_nbr_poll['ospfNbrIpAddr']."' AND I.interface_id = A.interface_id AND I.device_id = '".$device['device_id']."'"),0);
|
||||
@@ -296,16 +303,17 @@ if (is_array($ospf_nbrs_db)){
|
||||
#log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['interface_id']); ## FIXME
|
||||
}
|
||||
}
|
||||
if($ospf_nbr_update)
|
||||
if ($ospf_nbr_update)
|
||||
{
|
||||
$query = "UPDATE `ospf_nbrs` SET `interface_id` = '".$ospf_nbr_poll['interface_id']."'".$ospf_nbr_update." WHERE `device_id` = '".$device['device_id']."' AND `ospf_nbr_id` = '".$ospf_nbr_id."'";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query"); }
|
||||
if ($debug) { echo("$query"); }
|
||||
echo("U");
|
||||
unset($ospf_nbr_update);
|
||||
} else {
|
||||
echo(".");
|
||||
}
|
||||
|
||||
unset($ospf_nbr_poll);
|
||||
unset($ospf_nbr_db);
|
||||
$ospf_nbr_count++;
|
||||
@@ -322,7 +330,7 @@ $filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("osp
|
||||
|
||||
if (!is_file($filename))
|
||||
{
|
||||
rrdtool_create($filename, "--step 300 \
|
||||
rrdtool_create($filename, "--step 300 \
|
||||
DS:instances:GAUGE:600:0:1000000 \
|
||||
DS:areas:GAUGE:600:0:1000000 \
|
||||
DS:ports:GAUGE:600:0:1000000 \
|
||||
|
||||
Reference in New Issue
Block a user