$peer['update']['bgpPeerState'] = $bgpPeerState; $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; $peer['update']['bgpPeerFsmEstablishedTime'] = $bgpPeerFsmEstablishedTime; $peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); foreach ($peer_afis as $peer_afi) { $afi = $peer_afi['afi']; $safi = $peer_afi['safi']; d_echo("{$afi} {$safi}\n"); if ($device['os_group'] == 'cisco') { $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); if (strstr($peer['bgpPeerIdentifier'], ':')) { $ip_type = 2; $ip_len = 16; $ip_ver = 'ipv6'; } else { $ip_type = 1; $ip_len = 4; $ip_ver = 'ipv4'; } $ip_cast = 1; if ($peer_afi['safi'] == 'multicast') { $ip_cast = 2; } else { if ($peer_afi['safi'] == 'unicastAndMulticast') { $ip_cast = 3;
$peers = mysql_query($query); while ($peer = mysql_fetch_array($peers)) { ### Poll BGP Peer echo "Checking " . $peer['bgpPeerIdentifier'] . " "; if (!strstr($peer['bgpPeerIdentifier'], ':')) { # v4 BGP4 MIB $peer_cmd = $config['snmpget'] . " -m BGP4-MIB -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $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}`); list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); } else { if ($device['os'] == "junos") { # v6 for JunOS via Juniper MIB $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); if (!isset($junos_v6)) { echo "\nCaching Oids..."; $peer_cmd = $config['snmpwalk'] . " -m BGP4-V2-MIB-JUNIPER -Onq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $device['hostname'] . ":" . $device['port']; $peer_cmd .= " jnxBgpM2PeerStatus.0.ipv6"; foreach (explode("\n", trim(`{$peer_cmd}`)) as $oid) { list($peer_oid) = split(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); } } $peer_cmd = $config['snmpget'] . " -m BGP4-V2-MIB-JUNIPER -Ovq -" . $device['snmpver'] . " -c" . $device['community'] . " " . $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];