discoverying and polling VRF

This commit is contained in:
HenocKA
2016-01-20 15:13:53 +01:00
parent ea5d2c66e6
commit 0ac8f584b2
11 changed files with 957 additions and 682 deletions

View File

@@ -306,6 +306,16 @@ function device_by_id_cache($device_id, $refresh = '0') {
}
else {
$device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id));
//order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time
$vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id));
$device['vrf_lite_cisco'] = array();
if(!empty($vrfs_lite_cisco)){
foreach ($vrfs_lite_cisco as $vrf){
$device['vrf_lite_cisco'][$vrf['context_name']] = $vrf;
}
}
$cache['devices']['id'][$device_id] = $device;
}
return $device;

View File

@@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1;
// Enable Pseudowires
$config['enable_vrfs'] = 1;
// Enable VRFs
$config['enable_vrf_lite_cisco'] = 1;
// Enable VRF lite cisco
$config['enable_printers'] = 0;
// Enable Printer support
$config['enable_sla'] = 0;
@@ -734,6 +736,7 @@ $config['discovery_modules']['vlans'] = 1;
$config['discovery_modules']['cisco-mac-accounting'] = 1;
$config['discovery_modules']['cisco-pw'] = 1;
$config['discovery_modules']['cisco-vrf'] = 1;
$config['discovery_modules']['cisco-vrf-lite'] = 1;
// $config['discovery_modules']['cisco-cef'] = 1;
$config['discovery_modules']['cisco-sla'] = 1;
$config['discovery_modules']['vmware-vminfo'] = 1;

View File

@@ -4,78 +4,90 @@ unset($mac_table);
echo 'ARP Table : ';
$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));
foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";
$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) {
// Commented below, no longer needed but leaving for reference.
// $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id']));
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
}
dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
echo '.';
}
else if (isset($interface['port_id'])) {
echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
'port_id' => $interface['port_id'],
'mac_address' => $clean_mac,
'ipv4_address' => $ip,
);
dbInsert($insert_data, 'ipv4_mac');
}//end if
}//end if
}//end foreach
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'";
foreach (dbFetchRows($sql) as $entry) {
$entry_mac = $entry['mac_address'];
$entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac]) {
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
echo '-';
}
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));
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name']=$vrf['context_name'];
$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB');
$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data));
$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data));
echo "\n";
unset($mac);
foreach (explode("\n", $ipNetToMedia_data) as $data) {
list($oid, $mac) = explode(' ', $data);
list($if, $first, $second, $third, $fourth) = explode('.', $oid);
$ip = $first.'.'.$second.'.'.$third.'.'.$fourth;
if ($ip != '...') {
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac);
$m_a = zeropad($m_a);
$m_b = zeropad($m_b);
$m_c = zeropad($m_c);
$m_d = zeropad($m_d);
$m_e = zeropad($m_e);
$m_f = zeropad($m_f);
$md_a = hexdec($m_a);
$md_b = hexdec($m_b);
$md_c = hexdec($m_c);
$md_d = hexdec($m_d);
$md_e = hexdec($m_e);
$md_f = hexdec($m_f);
$mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f";
$mac_table[$if][$mac]['ip'] = $ip;
$mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f";
$clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f;
$mac_table[$if][$mac]['cleanmac'] = $clean_mac;
$port_id = $interface['port_id'];
$mac_table[$port_id][$clean_mac] = 1;
if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) {
// Commented below, no longer needed but leaving for reference.
// $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'";
$old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']);
if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n");
log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
}
dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']));
echo '.';
}
else if (isset($interface['port_id'])) {
echo '+';
// echo("Add MAC $mac\n");
$insert_data = array(
'port_id' => $interface['port_id'],
'mac_address' => $clean_mac,
'ipv4_address' => $ip,
'context_name' => $device['context_name'],
);
dbInsert($insert_data, 'ipv4_mac');
}//end if
}//end if
}//end foreach
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'";
foreach (dbFetchRows($sql) as $entry) {
$entry_mac = $entry['mac_address'];
$entry_if = $entry['port_id'];
if (!$mac_table[$entry_if][$entry_mac]) {
dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name']));
d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']);
echo '-';
}
}
echo "\n";
unset($mac);
unset($device['context_name']);
}
unset($vrfs_c);

View File

@@ -3,232 +3,246 @@
if ($config['enable_bgp']) {
// Discover BGP peers
echo 'BGP Sessions : ';
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));
}
$bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir']));
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name'] = $vrf['context_name'];
if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs ";
if (is_numeric($bgpLocalAs)) {
echo "AS$bgpLocalAs ";
if ($bgpLocalAs != $device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
echo 'Updated AS ';
}
$peer2 = false;
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
if (empty($peers_data)) {
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
}
else {
$peer2 = true;
}
d_echo("Peers : $peers_data \n");
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
foreach (explode("\n", $peers) as $peer) {
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
if ($bgpLocalAs != $device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id']));
echo 'Updated AS ';
}
list($peer_ip, $peer_as) = explode(' ', $peer);
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
$peer2 = false;
$peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']);
if (empty($peers_data)) {
$peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']);
}
else {
$peer2 = true;
}
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
d_echo("Peers : $peers_data \n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
$peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data));
$peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers));
if ($device['os'] == 'junos') {
// Juniper BGP4-V2 MIB
// FIXME: needs a big cleanup! also see below.
// FIXME: is .0.ipv6 the only possible value here?
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result));
foreach (explode("\n", $peers) as $peer) {
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
if ($peer2 === true) {
list($ver, $peer) = explode('.', $peer, 2);
}
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
list($peer_ip, $peer_as) = explode(' ', $peer);
if (strstr($peer_ip, ':')) {
$peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip);
$peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp);
$peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip));
}
if ($peer) {
if ($peer && $peer_ip != '0.0.0.0') {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
'ip' => $peer_ip,
'as' => $peer_as,
'ver' => $ver,
);
}
}
}
}
else {
echo 'No BGP on host';
if ($device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id']));
echo ' (Removed ASN) ';
}
}
// Process disovered peers
if (isset($peerlist)) {
foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']);
if ($device['os'] == 'junos') {
// Juniper BGP4-V2 MIB
// FIXME: needs a big cleanup! also see below.
// FIXME: is .0.ipv6 the only possible value here?
$result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
$peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result));
foreach (explode("\n", $peers) as $peer) {
list($peer_ip_snmp, $peer_as) = explode(' ', $peer);
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') {
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
$remote_device_id = discover_new_device($name, $device, 'BGP');
// Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs.
$peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16)))));
if ($peer) {
d_echo("Found peer $peer_ip (AS$peer_as)\n");
$peerlist[] = array(
'ip' => $peer_ip,
'as' => $peer_as,
);
}
}
}
}
else {
echo 'No BGP on host';
if ($device['bgpLocalAs']) {
dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id']));
echo ' (Removed ASN) ';
}
}
// Process disovered peers
if (isset($peerlist)) {
foreach ($peerlist as $peer) {
$astext = get_astext($peer['as']);
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') {
$add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers');
if ($config['autodiscovery']['bgp'] === true) {
$name = gethostbyaddr($peer['ip']);
$remote_device_id = discover_new_device($name, $device, 'BGP');
}
echo '+';
}
else {
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
echo '+';
}
else {
$update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip']));
echo '.';
}
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
if ($device['os_group'] == 'cisco') {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') {
if ($device['os_group'] == 'cisco') {
// Get afi/safi and populate cbgp on cisco ios (xe/xr)
unset($af_list);
if ($peer2 === true) {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
else {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
d_echo('afi data :: ');
d_echo($af_data);
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
list(,$k) = explode('.', $k, 2);
$af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
else {
$af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']);
}
d_echo("AFISAFI = $k\n");
d_echo('afi data :: ');
d_echo($af_data);
$afisafi_tmp = explode('.', $k);
$safi = array_pop($afisafi_tmp);
$afi = array_pop($afisafi_tmp);
$bgp_ip = str_replace(".$afi.$safi", '', $k);
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
if ($afi && $safi && $bgp_ip == $peer['ip']) {
$af_list[$bgp_ip][$afi][$safi] = 1;
foreach ($af_data as $k => $v) {
if ($peer2 === true) {
list(,$k) = explode('.', $k, 2);
}
d_echo("AFISAFI = $k\n");
$afisafi_tmp = explode('.', $k);
$safi = array_pop($afisafi_tmp);
$afi = array_pop($afisafi_tmp);
$bgp_ip = str_replace(".$afi.$safi", '', $k);
$bgp_ip = preg_replace('/:/', ' ', $bgp_ip);
$bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip);
$bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip));
if ($afi && $safi && $bgp_ip == $peer['ip']) {
$af_list[$bgp_ip][$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp');
}
}
}
}
if ($device['os'] == 'junos') {
$safis[1] = 'unicast';
$safis[2] = 'multicast';
if (!isset($j_peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
}
}
if (!isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
$safi = $safis[$safi];
$af_list[$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
}
}
}
}
if ($device['os'] == 'junos') {
$safis[1] = 'unicast';
$safis[2] = 'multicast';
if (!isset($j_peerIndexes)) {
$j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach ($j_bgp as $index => $entry) {
switch ($entry['jnxBgpM2PeerRemoteAddrType']) {
case 'ipv4':
$ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr']));
d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex'];
break;
case 'ipv6':
$ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"');
$ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4);
$ip6 = Net_IPv6::compress($ip6);
d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n");
$j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex'];
break;
default:
echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n";
break;
}
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'";
foreach (dbFetchRows($af_query) as $entry) {
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name']));
}
}
if (!isset($j_afisafi)) {
$j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos');
foreach (array_keys($j_prefixes) as $key) {
list($index,$afisafi) = explode('.', $key, 2);
$j_afisafi[$index][] = $afisafi;
}
}
foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) {
list ($afi,$safi) = explode('.', $afisafi);
$safi = $safis[$safi];
$af_list[$afi][$safi] = 1;
if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) {
dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp');
}
}
}
$af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'";
foreach (dbFetchRows($af_query) as $entry) {
$afi = $entry['afi'];
$safi = $entry['safi'];
if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
}
}
}
unset($j_afisafi);
unset($j_prefixes);
unset($j_bgp);
unset($j_peerIndexes);
}
unset($j_afisafi);
unset($j_prefixes);
unset($j_bgp);
unset($j_peerIndexes);
}
// Delete removed peers
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'";
// Delete removed peers
$sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
foreach (dbFetchRows($sql) as $entry) {
unset($exists);
$i = 0;
foreach (dbFetchRows($sql) as $entry) {
unset($exists);
$i = 0;
while ($i < count($peerlist) && !isset($exists)) {
if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) {
$exists = 1;
}
while ($i < count($peerlist) && !isset($exists)) {
if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) {
$exists = 1;
$i++;
}
$i++;
if (!isset($exists)) {
dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
echo '-';
}
}
if (!isset($exists)) {
dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
echo '-';
}
unset($peerlist);
echo "\n";
unset($device['context_name']);
}
unset($peerlist);
echo "\n";
unset($device['context_name']);
unset($vrfs_c);
}

View File

@@ -0,0 +1,142 @@
<?php
/* Copyright (C) 2014 Nicolas Armando <nicearma@yahoo.com> and Mathieu Millet <htam-net@github.net>
* 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/>. */
global $debug;
// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco
if ($config['enable_vrf_lite_cisco']) {
$ids = array();
// For the moment only will be cisco and the version 3
if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') {
echo ("VRF lite cisco : \n");
$mib = "SNMP-COMMUNITY-MIB";
$mib = "CISCO-CONTEXT-MAPPING-MIB";
//-Osq because if i put the n the oid from the first command is not the same of this one
$listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL);
$listVrf = str_replace("cContextMappingVrfName.", "", $listVrf);
$listVrf = str_replace('"', "", $listVrf);
$listVrf = trim($listVrf);
if ($debug) {
echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n");
echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n");
}
$tableVrf;
foreach (explode("\n", $listVrf) as $lineVrf) {
$tmpVrf = explode(" ", $lineVrf, 2);
//the $tmpVrf[0] will be the context
if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) {
$tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1];
}
}
unset($listVrf);
$listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL);
$listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance);
$listIntance = str_replace('"', "", $listIntance);
$listIntance = trim($listIntance);
if ($debug) {
echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n");
echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n");
}
foreach (explode("\n", $listIntance) as $lineIntance) {
$tmpIntance = explode(" ", $lineIntance, 2);
//the $tmpIntance[0] will be the context and $tmpIntance[1] the intance
if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) {
$tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1];
}
}
unset($listIntance);
foreach ($tableVrf as $context => $vrf) {
if ($debug) {
echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n");
}
$tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array(
$device ['device_id'],
$context
));
if (!empty($tmpVrf)) {
$ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id'];
$vrfUpdate=array();
foreach ($vrfUpdate as $key => $value) {
if($vrf[$key]!=$value){
$vrfUpdate[$key]=$value;
}
}
if (!empty($vrfUpdate)) {
dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array(
$tmp['vrf_lite_cisco_id']
));
}
} else {
$id = dbInsert(array(
'device_id' => $device ['device_id'],
'context_name' => $context,
'intance_name' => $vrf['intance_name'],
'vrf_name' => $vrf['vrf_name']
), 'vrf_lite_cisco');
$ids[$id] = $id;
}
}
unset($tableVrf);
}
//get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work
$tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array(
$device ['device_id']));
$device['vrf_lite_cisco'] = $tmpVrfC;
//Delete all vrf that chaged
foreach ($tmpVrfC as $vrfC) {
unset($ids[$vrfC['vrf_lite_cisco_id']]);
}
if (!empty($ids)) {
foreach ($ids as $id) {
dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array(
$id));
}
}
unset($ids);
unset($tmpVrfC);
} // enable_vrf_lite_cisco
?>

View File

@@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity
}//end discover_toner()
function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) {
function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') {
global $device,$config;
$ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen;
@@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') {
$port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks');
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') {
dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
echo 'N';
}
// Below looks like a duplicate of the above FIXME
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') {
dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks');
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') {
dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks');
echo 'N';
}
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network));
$ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses');
if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') {
dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses');
echo '+';
}
else {

View File

@@ -1,58 +1,68 @@
<?php
echo 'IPv4 Addresses : ';
$oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB'));
$oids = str_replace('ipAdEntIfIndex.', '', $oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$ifIndex) = explode(' ', $data);
$mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB'));
$addr = Net_IPv4::parseAddress("$oid/$mask");
$network = $addr->network.'/'.$addr->bitmask;
$cidr = $addr->bitmask;
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') {
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') {
dbInsert(array('ipv4_network' => $network), 'ipv4_networks');
// echo("Create Subnet $network\n");
echo 'S';
}
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') {
dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses');
// echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
echo '+';
}
else {
echo '.';
}
$full_address = "$oid/$cidr|$ifIndex";
$valid_v4[$full_address] = 1;
}
else {
echo '!';
}//end if
}//end foreach
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
foreach (dbFetchRows($sql) as $row) {
$full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex'];
if (!$valid_v4[$full_address]) {
echo '-';
$query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) {
$query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id']));
}
}
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));
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name']=$vrf['context_name'];
echo "\n";
$oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB'));
$oids = str_replace('ipAdEntIfIndex.', '', $oids);
foreach (explode("\n", $oids) as $data) {
$data = trim($data);
list($oid,$ifIndex) = explode(' ', $data);
$mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB'));
$addr = Net_IPv4::parseAddress("$oid/$mask");
$network = $addr->network.'/'.$addr->bitmask;
$cidr = $addr->bitmask;
unset($valid_v4);
if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') {
$port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') {
dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks');
// echo("Create Subnet $network\n");
echo 'S';
}
$ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name']));
if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') {
dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses');
// echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
echo '+';
}
else {
echo '.';
}
$full_address = "$oid/$cidr|$ifIndex";
$valid_v4[$full_address] = 1;
}
else {
echo '!';
}//end if
}//end foreach
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'";
foreach (dbFetchRows($sql) as $row) {
$full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex'];
if (!$valid_v4[$full_address]) {
echo '-';
$query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) {
$query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id']));
}
}
}
echo "\n";
unset($device['context_name']);
unset($valid_v4);
}
unset($vrfs_c);

View File

@@ -1,78 +1,89 @@
<?php
echo 'IPv6 Addresses : ';
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));
}
foreach ($vrfs_lite_cisco as $vrf) {
$device['context_name']=$vrf['context_name'];
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB');
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
$oids = str_replace('"', '', $oids);
$oids = str_replace('IP-MIB::', '', $oids);
$oids = trim($oids);
foreach (explode("\n", $oids) as $data) {
if ($data) {
$data = trim($data);
list($ipv6addr,$ifIndex) = explode(' ', $data);
$oid = '';
$sep = '';
$adsep = '';
unset($ipv6_address);
$do = '0';
foreach (explode(':', $ipv6addr) as $part) {
$n = hexdec($part);
$oid = "$oid"."$sep"."$n";
$sep = '.';
$ipv6_address = $ipv6_address."$adsep".$part;
$do++;
if ($do == 2) {
$adsep = ':';
$do = '0';
}
else {
$adsep = '';
}
}
$ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB');
$ipv6_prefixlen = explode('.', $ipv6_prefixlen);
$ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen));
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB');
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin);
} //end if
} //end foreach
if (!$oids) {
$oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB');
$oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids);
$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB');
$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids);
$oids = str_replace('"', '', $oids);
$oids = str_replace('IP-MIB::', '', $oids);
$oids = trim($oids);
foreach (explode("\n", $oids) as $data) {
if ($data) {
$data = trim($data);
list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data);
list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2);
$ipv6_address = snmp2ipv6($ipv6addr);
$ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB');
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin);
$data = trim($data);
list($ipv6addr,$ifIndex) = explode(' ', $data);
$oid = '';
$sep = '';
$adsep = '';
unset($ipv6_address);
$do = '0';
foreach (explode(':', $ipv6addr) as $part) {
$n = hexdec($part);
$oid = "$oid"."$sep"."$n";
$sep = '.';
$ipv6_address = $ipv6_address."$adsep".$part;
$do++;
if ($do == 2) {
$adsep = ':';
$do = '0';
}
else {
$adsep = '';
}
}
$ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB');
$ipv6_prefixlen = explode('.', $ipv6_prefixlen);
$ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen));
$ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB');
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
} //end if
} //end foreach
} //end if
$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id";
if (!$oids) {
$oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB');
$oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids);
$oids = str_replace('"', '', $oids);
$oids = trim($oids);
foreach (dbFetchRows($sql) as $row) {
$full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen'];
$port_id = $row['port_id'];
$valid_address = $full_address.'-'.$port_id;
if (!$valid['ipv6'][$valid_address]) {
echo '-';
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) {
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id']));
foreach (explode("\n", $oids) as $data) {
if ($data) {
$data = trim($data);
list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data);
list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2);
$ipv6_address = snmp2ipv6($ipv6addr);
$ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB');
discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']);
} //end if
} //end foreach
} //end if
$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'";
foreach (dbFetchRows($sql) as $row) {
$full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen'];
$port_id = $row['port_id'];
$valid_address = $full_address.'-'.$port_id;
if (!$valid['ipv6'][$valid_address]) {
echo '-';
$query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id']));
if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) {
$query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id']));
}
}
}
}
echo "\n";
echo "\n";
unset($device['context_name']);
}
unset($vrfs_c);

View File

@@ -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

View File

@@ -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');

View File

@@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) {
$cmd = '';
if ($device['snmpver'] === 'v3') {
$cmd = " -v3 -n '' -l '".$device['authlevel']."'";
//add context if exist context
if(key_exists('context_name', $device)){
$cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'";
}
if ($device['authlevel'] === 'noAuthNoPriv') {
// We have to provide a username anyway (see Net-SNMP doc)
// FIXME: There are two other places this is set - why are they ignored here?