mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-01 00:24:21 +02:00
discoverying and polling VRF
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
if ($config['enable_bgp']) {
|
||||
foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) {
|
||||
//add context if exist
|
||||
$device['context_name']= $peer['context_name'];
|
||||
|
||||
// Poll BGP Peer
|
||||
$peer2 = false;
|
||||
echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' ';
|
||||
@@ -62,14 +65,28 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
$peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' ';
|
||||
$peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' ';
|
||||
$peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' ';
|
||||
$peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].'';
|
||||
$peer_data = trim(`$peer_cmd`);
|
||||
// $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' ';
|
||||
$oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " ";
|
||||
$oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " ";
|
||||
$oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . "";
|
||||
$peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB');
|
||||
$peer_data= array_pop($peer_data);
|
||||
if($debug){
|
||||
var_dump($peer_data);
|
||||
}
|
||||
}//end if
|
||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
$bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:'';
|
||||
$bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:'';
|
||||
$bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:'';
|
||||
$bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:'';
|
||||
$bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:'';
|
||||
$bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:'';
|
||||
$bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:'';
|
||||
$bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:'';
|
||||
$bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:'';
|
||||
//list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
$bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr));
|
||||
unset($peer_data);
|
||||
}
|
||||
else if ($device['os'] == 'junos') {
|
||||
// v6 for JunOS via Juniper MIB
|
||||
@@ -78,9 +95,9 @@ if ($config['enable_bgp']) {
|
||||
if (!isset($junos_v6)) {
|
||||
echo "\nCaching Oids...";
|
||||
// FIXME - needs moved to function
|
||||
$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'];
|
||||
$peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6';
|
||||
foreach (explode("\n", trim(`$peer_cmd`)) as $oid) {
|
||||
//$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'];
|
||||
|
||||
foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){
|
||||
list($peer_oid) = explode(' ', $oid);
|
||||
$peer_id = explode('.', $peer_oid);
|
||||
$junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18));
|
||||
@@ -88,25 +105,34 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
|
||||
// FIXME - move to function (and clean up, wtf?)
|
||||
$peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device);
|
||||
$peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"';
|
||||
$peer_cmd .= ' '.$device['hostname'].':'.$device['port'];
|
||||
$peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
// Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented?
|
||||
$peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip];
|
||||
$peer_cmd .= '|grep -v "No Such Instance"';
|
||||
d_echo("\n$peer_cmd\n");
|
||||
|
||||
$peer_data = trim(`$peer_cmd`);
|
||||
list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data);
|
||||
|
||||
$oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented?
|
||||
$oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip];
|
||||
$oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip];
|
||||
//$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln??
|
||||
$peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos");
|
||||
$peer_data= array_pop($peer_data);
|
||||
if($debug){
|
||||
var_dump($peer_data);
|
||||
}
|
||||
$bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:'';
|
||||
$bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:'';
|
||||
$bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:'';
|
||||
$bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:'';
|
||||
$bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:'';
|
||||
$bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:'';
|
||||
$bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:'';
|
||||
$bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:'';
|
||||
$bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:'';
|
||||
|
||||
unset($peer_data);
|
||||
|
||||
d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n");
|
||||
|
||||
$bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr));
|
||||
@@ -235,23 +261,37 @@ if ($config['enable_bgp']) {
|
||||
}
|
||||
else {
|
||||
// FIXME - move to function
|
||||
$cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'];
|
||||
$cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
$cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi";
|
||||
|
||||
d_echo("$cbgp_cmd\n");
|
||||
|
||||
$cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`));
|
||||
$cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data);
|
||||
|
||||
|
||||
$oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
$oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi";
|
||||
|
||||
d_echo("$oids\n");
|
||||
|
||||
$cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB');
|
||||
$cbgp_data= array_pop($cbgp_data);
|
||||
|
||||
d_echo("$cbgp_data\n");
|
||||
|
||||
|
||||
}//end if
|
||||
list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data);
|
||||
|
||||
$cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:'';
|
||||
$cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:'';
|
||||
$cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:'';
|
||||
$cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:'';
|
||||
$cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:'';
|
||||
$cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:'';
|
||||
$cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:'';
|
||||
$cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:'';
|
||||
|
||||
unset($cbgp_data);
|
||||
}//end if
|
||||
|
||||
if ($device['os'] == 'junos') {
|
||||
@@ -331,5 +371,6 @@ if ($config['enable_bgp']) {
|
||||
} //end foreach
|
||||
} //end if
|
||||
echo "\n";
|
||||
unset($device['context_name']);
|
||||
} //end foreach
|
||||
} //end if
|
||||
|
||||
+287
-261
@@ -8,6 +8,7 @@ $ospf_port_count = 0;
|
||||
$ospf_area_count = 0;
|
||||
$ospf_neighbour_count = 0;
|
||||
|
||||
|
||||
$ospf_oids_db = array(
|
||||
'ospfRouterId',
|
||||
'ospfAdminStat',
|
||||
@@ -25,64 +26,6 @@ $ospf_oids_db = array(
|
||||
'ospfDemandExtensions',
|
||||
);
|
||||
|
||||
// Build array of existing entries
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) {
|
||||
$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) {
|
||||
// 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])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances');
|
||||
echo '+';
|
||||
$ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id));
|
||||
$ospf_instances_db[$entry['ospf_instance_id']] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_instances_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_instances_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// Loop array of entries and update
|
||||
if (is_array($ospf_instances_db)) {
|
||||
foreach ($ospf_instances_db as $ospf_instance_db) {
|
||||
$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]) {
|
||||
// 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` = ?', array($device['device_id'], $ospf_instance_id));
|
||||
echo 'U';
|
||||
unset($ospf_instance_update);
|
||||
}
|
||||
else {
|
||||
echo '.';
|
||||
}
|
||||
|
||||
unset($ospf_instance_poll);
|
||||
unset($ospf_instance_db);
|
||||
$ospf_instance_count++;
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
unset($ospf_instances_poll);
|
||||
unset($ospf_instances_db);
|
||||
|
||||
echo ' Areas: ';
|
||||
|
||||
$ospf_area_oids = array(
|
||||
'ospfAuthType',
|
||||
'ospfImportAsExtern',
|
||||
@@ -95,72 +38,6 @@ $ospf_area_oids = array(
|
||||
'ospfAreaStatus',
|
||||
);
|
||||
|
||||
// Build array of existing entries
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) {
|
||||
$ospf_areas_db[$entry['ospfAreaId']] = $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 (!isset($ospf_areas_db[$ospf_area_id])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas');
|
||||
echo '+';
|
||||
$entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id));
|
||||
$ospf_areas_db[$entry['ospf_area_id']] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_areas_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_areas_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// Loop array of entries and update
|
||||
if (is_array($ospf_areas_db)) {
|
||||
foreach ($ospf_areas_db as $ospf_area_db) {
|
||||
if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) {
|
||||
$ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']];
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if ($ospf_area_update) {
|
||||
dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id));
|
||||
echo 'U';
|
||||
unset($ospf_area_update);
|
||||
}
|
||||
else {
|
||||
echo '.';
|
||||
}
|
||||
|
||||
unset($ospf_area_poll);
|
||||
unset($ospf_area_db);
|
||||
$ospf_area_count++;
|
||||
}
|
||||
else {
|
||||
dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId']));
|
||||
}//end if
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
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: ';
|
||||
|
||||
$ospf_port_oids = array(
|
||||
'ospfIfIpAddress',
|
||||
'port_id',
|
||||
@@ -171,7 +48,7 @@ $ospf_port_oids = array(
|
||||
'ospfIfRtrPriority',
|
||||
'ospfIfTransitDelay',
|
||||
'ospfIfRetransInterval',
|
||||
'ospfIfHelloInterval',
|
||||
'ospfIfHelloInterval',
|
||||
'ospfIfRtrDeadInterval',
|
||||
'ospfIfPollInterval',
|
||||
'ospfIfState',
|
||||
@@ -185,87 +62,6 @@ $ospf_port_oids = array(
|
||||
'ospfIfAuthType',
|
||||
);
|
||||
|
||||
// Build array of existing entries
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) {
|
||||
$ospf_ports_db[$entry['ospf_port_id']] = $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 (!isset($ospf_ports_db[$ospf_port_id])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports');
|
||||
echo '+';
|
||||
$ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id));
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_ports_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_ports_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// 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_poll[$ospf_port_db['ospf_port_id']])) {
|
||||
$ospf_port_poll = $ospf_ports_poll[$ospf_port_db['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']));
|
||||
}
|
||||
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 = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_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
|
||||
}
|
||||
}
|
||||
|
||||
if ($ospf_port_update) {
|
||||
dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id));
|
||||
echo 'U';
|
||||
unset($ospf_port_update);
|
||||
}
|
||||
else {
|
||||
echo '.';
|
||||
}
|
||||
|
||||
unset($ospf_port_poll);
|
||||
unset($ospf_port_db);
|
||||
$ospf_port_count++;
|
||||
}
|
||||
else {
|
||||
dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id']));
|
||||
// "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
|
||||
|
||||
// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98
|
||||
// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0
|
||||
// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128
|
||||
// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2
|
||||
// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0
|
||||
// OSPF-MIB::ospfNbrState.172.22.203.98.0 full
|
||||
// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6
|
||||
// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1
|
||||
// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active
|
||||
// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic
|
||||
// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false
|
||||
echo ' Neighbours: ';
|
||||
|
||||
$ospf_nbr_oids_db = array(
|
||||
'ospfNbrIpAddr',
|
||||
'ospfNbrAddressLessIndex',
|
||||
@@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array(
|
||||
'ospfNbmaNbrPermanence',
|
||||
'ospfNbrHelloSuppressed',
|
||||
);
|
||||
$ospf_nbr_oids_rrd = array();
|
||||
$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
|
||||
|
||||
// Build array of existing entries
|
||||
foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) {
|
||||
$ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry;
|
||||
|
||||
|
||||
if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) {
|
||||
$vrfs_lite_cisco = $device['vrf_lite_cisco'];
|
||||
} else {
|
||||
$vrfs_lite_cisco = array(array('context_name' => null));
|
||||
}
|
||||
|
||||
// Pull data from device
|
||||
$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB');
|
||||
foreach ($vrfs_lite_cisco as $vrf_lite) {
|
||||
|
||||
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])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs');
|
||||
echo '+';
|
||||
$entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id));
|
||||
$ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry;
|
||||
$device['context_name'] = $vrf_lite['context_name'];
|
||||
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_nbrs_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_nbrs_db);
|
||||
echo "\n";
|
||||
}
|
||||
// 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) {
|
||||
// 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']])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances');
|
||||
echo '+';
|
||||
$ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = 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[$entry['ospf_instance_id']][$entry['context_name']] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
// 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_poll[$ospf_nbr_db['ospf_nbr_id']])) {
|
||||
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']];
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_instances_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_instances_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id']));
|
||||
// Loop array of entries and update
|
||||
if (is_array($ospf_instances_db)) {
|
||||
foreach ($ospf_instances_db as $ospf_instance_id => $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[$device['context_name']][$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_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) {
|
||||
if ($ospf_nbr_poll['port_id']) {
|
||||
$ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']);
|
||||
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 {
|
||||
$ospf_nbr_update = array('port_id' => array('NULL'));
|
||||
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);
|
||||
|
||||
foreach ($ospf_nbr_oids as $oid) {
|
||||
// Loop the OIDs
|
||||
d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n");
|
||||
|
||||
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
|
||||
|
||||
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 (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_areas_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_areas_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// Loop array of entries and update
|
||||
if (is_array($ospf_areas_db)) {
|
||||
foreach ($ospf_areas_db as $$ospf_area_id => $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[$entry['context_name']][$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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ospf_nbr_update) {
|
||||
dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id));
|
||||
echo 'U';
|
||||
unset($ospf_nbr_update);
|
||||
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 '.';
|
||||
}
|
||||
|
||||
unset($ospf_area_poll);
|
||||
unset($ospf_area_db);
|
||||
$ospf_area_count++;
|
||||
}
|
||||
else {
|
||||
echo '.';
|
||||
}
|
||||
dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name']));
|
||||
}//end if
|
||||
}//end foreach
|
||||
}//end if
|
||||
|
||||
unset($ospf_nbr_poll);
|
||||
unset($ospf_nbr_db);
|
||||
$ospf_nbr_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 (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports');
|
||||
echo '+';
|
||||
$ospf_ports_db[$entry['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']));
|
||||
}
|
||||
else {
|
||||
dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id']));
|
||||
echo '-';
|
||||
}//end if
|
||||
}//end foreach
|
||||
}//end if
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_ports_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_ports_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// 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_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']));
|
||||
}
|
||||
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']));
|
||||
}
|
||||
|
||||
foreach ($ospf_port_oids as $oid) {
|
||||
// Loop the OIDs
|
||||
if ($ospf_port_db[$device['context_name']][$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
|
||||
}
|
||||
}
|
||||
|
||||
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 '.';
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98
|
||||
// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0
|
||||
// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128
|
||||
// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2
|
||||
// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0
|
||||
// OSPF-MIB::ospfNbrState.172.22.203.98.0 full
|
||||
// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6
|
||||
// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1
|
||||
// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active
|
||||
// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic
|
||||
// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false
|
||||
echo ' Neighbours: ';
|
||||
|
||||
$ospf_nbr_oids_rrd = array();
|
||||
$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd);
|
||||
|
||||
// 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']])) {
|
||||
dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
echo "\nPolled: ";
|
||||
print_r($ospf_nbrs_poll);
|
||||
echo 'Database: ';
|
||||
print_r($ospf_nbrs_db);
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
// 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_poll[$ospf_nbr_db['ospf_nbr_id']])) {
|
||||
$ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']];
|
||||
|
||||
$ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, 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']));
|
||||
|
||||
if ($ospf_nbr_db[$device['context_name']]['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'));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($ospf_nbr_oids as $oid) {
|
||||
// Loop the OIDs
|
||||
d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n");
|
||||
|
||||
if ($ospf_nbr_db[$device['context_name']][$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);
|
||||
}
|
||||
unset($device['context_name']);
|
||||
unset($vrfs_lite_cisco);
|
||||
// Create device-wide statistics RRD
|
||||
$filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user