if ($debug) { echo "Found peer {$peer_ip} (AS{$peer_as})\n"; } $peerlist[] = array('ip' => $peer_ip, 'as' => $peer_as, 'ver' => $ver); } } 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); // 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) { if ($debug) { 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) '; } }
* This file is part of Observium. * * @package observium * @subpackage discovery * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $ip_version = 'ipv6'; if ($check_ipv6_mib || !count($ip_data[$ip_version])) { // Get IP addresses from IPV6-MIB //ipv6AddrPfxLength.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = 64 //ipv6AddrPfxLength.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = 126 //ipv6AddrType.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = stateful //ipv6AddrType.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = stateful //ipv6AddrAnycastFlag.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = false //ipv6AddrAnycastFlag.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = false //ipv6AddrStatus.20.254.192.0.0.0.0.0.0.0.10.0.0.0.0.0.4 = preferred //ipv6AddrStatus.573.42.1.183.64.0.1.130.32.0.0.0.0.0.0.0.2 = preferred //Types: stateless(1), stateful(2), unknown(3) $oid_data = snmpwalk_cache_twopart_oid($device, 'ipv6AddrEntry', array(), 'IPV6-MIB', NULL, OBS_SNMP_ALL_NUMERIC_INDEX); //print_vars($oid_data); // Rewrite IPV6-MIB array foreach ($oid_data as $ifIndex => $entry1) { foreach ($entry1 as $ip_snmp => $entry) { $ip_address = snmp2ipv6($ip_snmp); $ip_data[$ip_version][$ifIndex][$ip_address] = array('ifIndex' => $ifIndex, 'ip' => $ip_address, 'prefix' => $entry['ipv6AddrPfxLength'], 'origin' => $entry['ipv6AddrType']); } } } unset($ifIndex, $ip_address, $ip_snmp, $entry1, $oid_data); // EOF
/** * Convert BGP peer index to vendor MIB specific entries * * @param array $peer Array with walked peer oids * @param string $index Peer index * @param string $mib MIB name */ function parse_bgp_peer_index(&$peer, $index, $mib = 'BGP4V2-MIB') { $address_types = $GLOBALS['config']['mibs']['INET-ADDRESS-MIB']['rewrite']['InetAddressType']; $index_parts = explode('.', $index); switch ($mib) { case 'BGP4-MIB': // bgpPeerRemoteAddr if (get_ip_version($index)) { $peer['bgpPeerRemoteAddr'] = $index; } break; case 'ARISTA-BGP4V2-MIB': // 1. aristaBgp4V2PeerInstance $peer['aristaBgp4V2PeerInstance'] = array_shift($index_parts); // 2. aristaBgp4V2PeerRemoteAddrType. $peer_addr_type = array_shift($index_parts); if (strlen($peer['aristaBgp4V2PeerRemoteAddrType']) == 0) { $peer['aristaBgp4V2PeerRemoteAddrType'] = $peer_addr_type; } if (isset($address_types[$peer['aristaBgp4V2PeerRemoteAddrType']])) { $peer['aristaBgp4V2PeerRemoteAddrType'] = $address_types[$peer['aristaBgp4V2PeerRemoteAddrType']]; } // 3. length of the IP address $ip_len = array_shift($index_parts); // 4. IP address $ip_parts = array_slice($index_parts, 0, $ip_len); // 5. aristaBgp4V2PeerRemoteAddr $peer_ip = implode('.', $ip_parts); if ($ip_len == 16) { $peer_ip = snmp2ipv6($peer_ip); } if ($peer_addr_type = get_ip_version($peer_ip)) { $peer['aristaBgp4V2PeerRemoteAddr'] = $peer_ip; $peer['aristaBgp4V2PeerRemoteAddrType'] = 'ipv' . $peer_addr_type; // FIXME. not sure, but seems as Arista use only ipv4/ipv6 for afi } break; case 'BGP4-V2-MIB-JUNIPER': // 1. jnxBgpM2PeerRoutingInstance $peer['jnxBgpM2PeerRoutingInstance'] = array_shift($index_parts); // 2. jnxBgpM2PeerLocalAddrType $local_addr_type = array_shift($index_parts); if (strlen($peer['jnxBgpM2PeerLocalAddrType']) == 0) { $peer['jnxBgpM2PeerLocalAddrType'] = $local_addr_type; } if (isset($address_types[$peer['jnxBgpM2PeerLocalAddrType']])) { $peer['jnxBgpM2PeerLocalAddrType'] = $address_types[$peer['jnxBgpM2PeerLocalAddrType']]; } // 3. length of the local IP address $ip_len = strstr($peer['jnxBgpM2PeerLocalAddrType'], 'ipv6') ? 16 : 4; // 4. IP address $ip_parts = array_slice($index_parts, 0, $ip_len); // 5. jnxBgpM2PeerLocalAddr $local_ip = implode('.', $ip_parts); if ($ip_len == 16) { $local_ip = snmp2ipv6($local_ip); } if (get_ip_version($local_ip)) { $peer['jnxBgpM2PeerLocalAddr'] = $local_ip; } // Get second part of index $index_parts = array_slice($index_parts, $ip_len); // 6. jnxBgpM2PeerRemoteAddrType $peer_addr_type = array_shift($index_parts); if (strlen($peer['jnxBgpM2PeerRemoteAddrType']) == 0) { $peer['jnxBgpM2PeerRemoteAddrType'] = $peer_addr_type; } if (isset($address_types[$peer['jnxBgpM2PeerRemoteAddrType']])) { $peer['jnxBgpM2PeerRemoteAddrType'] = $address_types[$peer['jnxBgpM2PeerRemoteAddrType']]; } // 7. length of the remote IP address $ip_len = strstr($peer['jnxBgpM2PeerRemoteAddrType'], 'ipv6') ? 16 : 4; // 8. IP address $ip_parts = array_slice($index_parts, 0, $ip_len); // 9. jnxBgpM2PeerRemoteAddr $peer_ip = implode('.', $ip_parts); if ($ip_len == 16) { $peer_ip = snmp2ipv6($peer_ip); } if (get_ip_version($peer_ip)) { $peer['jnxBgpM2PeerRemoteAddr'] = $peer_ip; } break; case 'FORCE10-BGP4-V2-MIB': // 1. f10BgpM2PeerInstance $peer['f10BgpM2PeerInstance'] = array_shift($index_parts); // 2. f10BgpM2PeerLocalAddrType $local_addr_type = array_shift($index_parts); if (strlen($peer['f10BgpM2PeerLocalAddrType']) == 0) { $peer['f10BgpM2PeerLocalAddrType'] = $local_addr_type; } if (isset($address_types[$peer['f10BgpM2PeerLocalAddrType']])) { $peer['f10BgpM2PeerLocalAddrType'] = $address_types[$peer['f10BgpM2PeerLocalAddrType']]; } // 3. length of the local IP address $ip_len = strstr($peer['f10BgpM2PeerLocalAddrType'], 'ipv6') ? 16 : 4; // 4. IP address $ip_parts = array_slice($index_parts, 0, $ip_len); // 5. f10BgpM2PeerLocalAddr $local_ip = implode('.', $ip_parts); if ($ip_len == 16) { $local_ip = snmp2ipv6($local_ip); } if (get_ip_version($local_ip)) { $peer['f10BgpM2PeerLocalAddr'] = $local_ip; } // Get second part of index $index_parts = array_slice($index_parts, $ip_len); // 6. f10BgpM2PeerRemoteAddrType $peer_addr_type = array_shift($index_parts); if (strlen($peer['f10BgpM2PeerRemoteAddrType']) == 0) { $peer['f10BgpM2PeerRemoteAddrType'] = $peer_addr_type; } if (isset($address_types[$peer['f10BgpM2PeerRemoteAddrType']])) { $peer['f10BgpM2PeerRemoteAddrType'] = $address_types[$peer['f10BgpM2PeerRemoteAddrType']]; } // 7. length of the remote IP address $ip_len = strstr($peer['f10BgpM2PeerRemoteAddrType'], 'ipv6') ? 16 : 4; // 8. IP address $ip_parts = array_slice($index_parts, 0, $ip_len); // 9. f10BgpM2PeerRemoteAddr $peer_ip = implode('.', $ip_parts); if ($ip_len == 16) { $peer_ip = snmp2ipv6($peer_ip); } if (get_ip_version($peer_ip)) { $peer['f10BgpM2PeerRemoteAddr'] = $peer_ip; } break; } }
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 = str_replace('"', '', $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); } //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"; 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 '-';
} } if (!count($ip_data)) { // Get IP addresses from IPV6-MIB $oids_ipv6 = array('ipv6AddrPfxLength', 'ipv6AddrType'); //.1.3.6.1.2.1.55.1.8.1.2.6105.16.254.128.0.0.0.0.0.0.2.26.169.255.254.23.134.97 = 64 //.1.3.6.1.2.1.55.1.8.1.3.6105.16.254.128.0.0.0.0.0.0.2.26.169.255.254.23.134.97 = stateful //Types: stateless(1), stateful(2), unknown(3) $oid_data = array(); foreach ($oids_ipv6 as $oid) { $oid_data = snmpwalk_cache_oid_num2($device, $oid, $oid_data, 'IPV6-MIB', mib_dirs()); } // Rewrite IPV6-MIB array foreach ($oid_data as $key => $entry) { list($ifIndex, $ip_address) = explode('.', $key, 2); $ip_address = snmp2ipv6($ip_address); if (!is_numeric($entry['ipv6AddrPfxLength'])) { $entry['ipv6AddrPfxLength'] = '128'; } if (is_ipv6_valid($ip_address, $entry['ipv6AddrPfxLength']) === FALSE) { continue; } $ip_data[$ifIndex][$ip_address]['ipAddressIfIndex'] = $ifIndex; $ip_data[$ifIndex][$ip_address]['ipAddressPrefix'] = $entry['ipv6AddrPfxLength']; $ip_data[$ifIndex][$ip_address]['ipAddressOrigin'] = $entry['ipv6AddrType']; } if ($debug && $ip_data) { echo "IPV6-MIB\n"; print_vars($ip_data); } }