$continue = TRUE; if (!sqgetGlobalVar('secret', $secret, SQ_POST) || empty($secret)) { $continue = FALSE; echo "<p>You must enter an encryption key.</p>\n"; } if (!sqgetGlobalVar('enc_string', $enc_string, SQ_POST) || empty($enc_string)) { $continue = FALSE; echo "<p>You must enter an encrypted string.</p>\n"; } if ($continue) { if (isset($enc_string) && !base64_decode($enc_string)) { echo "<p>Encrypted string should be BASE64 encoded.<br />\n" . "Please enter all characters that are listed after header name.</p>\n"; } elseif (isset($secret)) { $string = OneTimePadDecrypt($enc_string, base64_encode($secret)); if (sqgetGlobalVar('ip_addr', $is_addr, SQ_POST)) { $string = hex2ip($string); } echo "<p>Decoded string: " . htmlspecialchars($string) . "</p>\n"; } } echo "<hr />"; } ?> <form action="" method="post"> <p> Secret key: <input type="password" name="secret"><br /> Encrypted string: <input type="text" name="enc_string"><br /> <label for="ip_addr">Check here if you are decoding an address string (FromHash/ProxyHash): </label><input type="checkbox" name="ip_addr" id="ip_addr" /><br /> <button type="submit" name="submit" value="submit">Submit</button> </p> </form>
$query = 'SELECT `port_id`, `ifIndex`, `ifDescr` FROM `ports` WHERE `device_id` = ? AND `deleted` = ?'; foreach (dbFetchRows($query, array($device['device_id'], 0)) as $entry) { $ports_ifDescr[$entry['ifDescr']] = $entry; } // Rewrite F5-BIGIP-SYSTEM-MIB array foreach ($oid_data as $ip_name => $entry) { if ($entry['sysSelfIpUnitId'] != '0') { continue; } // Skip all except self Unit addresses $ifName = $entry['sysSelfIpVlanName']; if (isset($ports_ifDescr[$ifName])) { $ifIndex = $ports_ifDescr[$ifName]['ifIndex']; $ip_version = $entry['sysSelfIpAddrType']; $ip_address = hex2ip($entry['sysSelfIpAddr']); $ip_mask = hex2ip($entry['sysSelfIpNetmask']); if ($ip_version == 'ipv4') { $ip_mask_fix = explode('.', $ip_mask); if (empty($ip_mask) || count($ip_mask_fix) != 4) { $ip_mask = '255.255.255.255'; } } else { // IPv6 - not tested $prefix = 0; $m = str_split($ip_mask); foreach ($m as $c) { if ($c == ":") { continue; } if ($c == "0") { break;
$peer_ip = $peer['bgpPeerRemoteAddr']; $remote_ip = strstr($peer_ip, ':') ? Net_IPv6::compress($peer_ip) : $peer_ip; // Compact IPv6. Used only for log. echo "Checking BGP peer: " . $peer_ip . " "; if (!strstr($peer_ip, ':') && !$use_cisco_v2) { // Common IPv4 BGP4 MIB foreach ($bgp_oids as $bgp_oid) { ${$bgp_oid} = $bgp_peers[$peer_ip][$bgp_oid]; } } elseif ($use_cisco_v2) { // Cisco BGP4 V2 MIB $c_index = strstr($peer_ip, ':') ? 'ipv6.' . ip2hex($peer_ip, ':') : 'ipv4.' . $peer_ip; foreach ($bgp_oids as $bgp_oid) { $c_oid = str_replace(array('bgpPeer', 'Identifier'), array('cbgpPeer2', 'RemoteIdentifier'), $bgp_oid); if ($bgp_oid == 'bgpPeerLocalAddr') { $cisco_peers[$c_index][$c_oid] = hex2ip($cisco_peers[$c_index][$c_oid]); } ${$bgp_oid} = $cisco_peers[$c_index][$c_oid]; } } elseif ($use_vendor) { foreach ($bgp_oids as $bgp_oid) { $vendor_oid = $vendor_oids[$device['os']][str_replace('bgp', 'vendor_', $bgp_oid)]; ${$bgp_oid} = $vendor_peers[$peer_ip][$vendor_oid]; } print_debug("Peer: {$peer_ip} (State = {$bgpPeerState} AdminStatus = {$bgpPeerAdminStatus})"); } // FIXME I left the eventlog code for now, as soon as alerts send an entry to the eventlog this can go. if ($bgpPeerFsmEstablishedTime) { if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { if ($peer['bgpPeerState'] == $bgpPeerState) { log_event('BGP Session flapped: ' . $remote_ip . ' (AS' . $peer['bgpPeerRemoteAs'] . '), time ' . formatUptime($bgpPeerFsmEstablishedTime) . ' ago', $device, 'bgpPeer', $peer['bgpPeer_id']);
$old_mac = $entry['mac_address']; $old_address = $entry['ip_address']; $old_version = $entry['ip_version']; $old_table[$old_if][$old_version][$old_address] = $old_mac; } $ipv4_pattern = '/\\[(\\d+)\\](?:\\[ipv4\\])?\\["?([\\d\\.]+)"?\\]\\s+([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]{1,2})/i'; $ipv6_pattern = '/\\[(\\d+)\\](?:\\[ipv6\\])?\\["?([a-f\\d:]+)"?\\]\\s+(?:([a-f\\d]+):([a-f\\d]+):)?([a-f\\d]+):([a-f\\d]+):([a-f\\d]+):([a-f\\d]{1,2})/i'; foreach (explode("\n", $oid_data) as $data) { if (preg_match($ipv4_pattern, $data, $matches)) { $ip = $matches[2]; $ip_version = 4; } elseif (preg_match($ipv6_pattern, $data, $matches)) { if (count(explode(':', $matches[2])) === 8) { $ip = Net_IPv6::uncompress($matches[2], TRUE); } else { $ip = hex2ip($matches[2]); } $ip_version = 6; } else { // In principle the such shouldn't be. continue; } $if = $matches[1]; $port_id = $interface[$if]; if ($ip & $port_id) { if ($matches[3] === '' && $matches[4] === '') { // Convert IPv4 to fake MAC for 6to4 tunnels //ipNetToPhysicalPhysAddress[27][ipv6]["20:02:c0:58:63:01:00:00:00:00:00:00:00:00:00:00"] 0:0:c0:58 $matches[3] = 'ff'; $matches[4] = 'fe'; }
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $ip_version = 'ipv6'; if (!count($ip_data[$ip_version])) { // Get IP addresses from CISCO-IETF-IP-MIB //cIpAddressIfIndex.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = 450 //cIpAddressPrefix.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = cIpAddressPfxOrigin.450.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:00".64 //cIpAddressOrigin.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = manual //Origins: 1:other, 2:manual, 4:dhcp, 5:linklayer, 6:random $flags = OBS_SNMP_ALL ^ OBS_QUOTES_STRIP; $oid_data = array(); foreach (array('cIpAddressIfIndex', 'cIpAddressPrefix', 'cIpAddressType', 'cIpAddressOrigin') as $oid) { $oid_data = snmpwalk_cache_twopart_oid($device, $oid . '.' . $ip_version, $oid_data, 'CISCO-IETF-IP-MIB', NULL, $flags); if ($oid == 'cIpAddressIfIndex' && $GLOBALS['snmp_status'] === FALSE) { break; // Stop walk, not exist table } } //print_vars($oid_data); // Rewrite CISCO-IETF-IP-MIB array foreach ($oid_data[$ip_version] as $ip_snmp => $entry) { $ip_address = hex2ip($ip_snmp); $ifIndex = $entry['cIpAddressIfIndex']; $tmp_prefix = explode('.', $entry['cIpAddressPrefix']); $entry['cIpAddressPrefix'] = end($tmp_prefix); $ip_data[$ip_version][$ifIndex][$ip_address] = array('ifIndex' => $ifIndex, 'ip' => $ip_address, 'prefix' => $entry['cIpAddressPrefix'], 'type' => $entry['cIpAddressType'], 'origin' => $entry['cIpAddressOrigin']); } } unset($ifIndex, $ip_address, $tmp_prefix, $oid_data, $flags); // EOF
// Skip additional multiindex entries from table $data = array('device_id' => $device['device_id'], 'sla_index' => $sla_index, 'sla_owner' => $entry['rttMonCtrlAdminOwner'], 'sla_tag' => $entry['rttMonCtrlAdminTag'], 'rtt_type' => $entry['rttMonCtrlAdminRttType'], 'sla_status' => $entry['rttMonCtrlAdminStatus'], 'deleted' => 0); // Some fallbacks for when the tag is empty if (!$data['sla_tag']) { switch ($data['rtt_type']) { case 'http': case 'ftp': $data['sla_tag'] = $entry['rttMonEchoAdminURL']; break; case 'dns': $data['sla_tag'] = $entry['rttMonEchoAdminTargetAddressString']; break; case 'echo': case 'jitter': case 'icmpjitter': $data['sla_tag'] = hex2ip($entry['rttMonEchoAdminTargetAddress']); break; } } if (!isset($sla_db[$sla_index])) { // Not exist, add $sla_id = dbInsert($data, 'slas'); $GLOBALS['module_stats'][$module]['added']++; //echo "+"; } else { $sla_id = $sla_db[$sla_index]['sla_id']; $update_db = array(); foreach ($data as $key => $value) { if ($sla_db[$sla_index][$key] != $value) { $update_db[$key] = $value; }
$pws = snmpwalk_cache_oid($device, "cpwVcID", array(), "CISCO-IETF-PW-MIB", mib_dirs('cisco')); if ($GLOBALS['snmp_status'] !== FALSE) { $pws = snmpwalk_cache_oid($device, "cpwVcName", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcType", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcDescr", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcPsnType", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcPeerAddrType", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcPeerAddr", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcLocalIfMtu", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); $pws = snmpwalk_cache_oid($device, "cpwVcRemoteIfMtu", $pws, "CISCO-IETF-PW-MIB", mib_dirs('cisco')); // For MPLS pseudowires $pws = snmpwalk_cache_oid($device, "cpwVcMplsPeerLdpID", $pws, "CISCO-IETF-PW-MPLS-MIB", mib_dirs('cisco')); foreach ($pws as $pw_id => $pw) { $peer_addr_type = $pw['cpwVcPeerAddrType']; if ($peer_addr_type == "ipv4" || $peer_addr_type == "ipv6") { $peer_addr = hex2ip($pw['cpwVcPeerAddr']); } #if(!empty($pw['cpwVcMplsPeerLdpID']) { list($peer_addr) = explode(":", $pw['cpwVcMplsPeerLdpID']); } $cpw_remote_device = dbFetchCell('SELECT `device_id` FROM `' . $peer_addr_type . '_addresses` AS A, `ports` AS I WHERE A.`' . $peer_addr_type . '_address` = ? AND A.`port_id` = I.`port_id`;', array($peer_addr)); if (empty($cpw_remote_device)) { $cpw_remote_device = array('NULL'); } $if_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `ifDescr` = ? AND `device_id` = ?;', array($pw['cpwVcName'], $device['device_id'])); $pws_new = array('device_id' => $device['device_id'], 'port_id' => $if_id, 'peer_addr' => $peer_addr, 'peer_device_id' => $cpw_remote_device, 'peer_ldp_id' => $pw['cpwVcMplsPeerLdpID'], 'cpwVcID' => $pw['cpwVcID'], 'cpwOid' => $pw_id, 'pw_type' => $pw['cpwVcType'], 'pw_psntype' => $pw['cpwVcPsnType'], 'pw_local_mtu' => $pw['cpwVcLocalIfMtu'], 'pw_peer_mtu' => $pw['cpwVcRemoteIfMtu'], 'pw_descr' => $pw['cpwVcDescr']); if (!empty($pws_cache['pws_db'][$pw['cpwVcID']])) { $pseudowire_id = $pws_cache['pws_db'][$pw['cpwVcID']]['pseudowire_id']; if (empty($pws_cache['pws_db'][$pw['cpwVcID']]['peer_device_id'])) { $pws_cache['pws_db'][$pw['cpwVcID']]['peer_device_id'] = array('NULL'); } $update_array = array(); var_dump(array_keys($pws_new));
// End points $tunnel_endpt_json = array(); foreach ($ipsec_endpt_poll[$index] as $index_endpt => $entry) { $endpt = array(); $endpt['local'] = hex2ip($entry['cipSecEndPtLocalAddr1']); $ip2 = hex2ip($entry['cipSecEndPtLocalAddr2']); switch ($entry['cipSecEndPtLocalType']) { case 'ipSubnet': $endpt['local'] .= '/' . netmask2cidr($ip2); break; case 'ipAddrRange': $endpt['local'] .= ' - ' . $ip2; break; } $endpt['remote'] = hex2ip($entry['cipSecEndPtRemoteAddr1']); $ip2 = hex2ip($entry['cipSecEndPtRemoteAddr2']); switch ($entry['cipSecEndPtRemoteType']) { case 'ipSubnet': $endpt['remote'] .= '/' . netmask2cidr($ip2); break; case 'ipAddrRange': $endpt['remote'] .= ' - ' . $ip2; break; } $tunnel_endpt_json[$index_endpt] = $endpt; } $tunnel_endpt_json = json_encode($tunnel_endpt_json); $tunnel_endpt_hash = md5($tunnel_endpt_json); // Hash for index $tunnel_json = array(); foreach ($json_oids as $oid) {
$vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerRemoteAddr, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); //$vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerRemoteAddrType, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerLocalAddr, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); //$vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerIndex, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerState, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerAdminStatus, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerInUpdates, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerOutUpdates, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerInTotalMessages, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerOutTotalMessages, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerFsmEstablishedTime, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); $vendor_bgp = snmpwalk_cache_oid_num2($device, $vendor_PeerInUpdateElapsedTime, $vendor_bgp, $vendor_mib, $vendor_mib_dir, TRUE); // rewrite to pretty array. foreach ($vendor_bgp as $entry) { $v_ip = hex2ip($entry[$vendor_PeerRemoteAddr]); $entry[$vendor_PeerLocalAddr] = hex2ip($entry[$vendor_PeerLocalAddr]); print_r($entry); $vendor_peers[$v_ip] = $entry; } } } if ($device['os_group'] == "cisco") { foreach ($cbgp_oids as $cbgp_oid) { $c_oid = $use_cisco_v2 ? str_replace('cbgpPeer', 'cbgpPeer2', $cbgp_oid) : $cbgp_oid; echo "{$c_oid} "; $c_prefixes = snmpwalk_cache_oid($device, $c_oid, $c_prefixes, 'CISCO-BGP4-MIB', mib_dirs('cisco'), TRUE); } } #print_r($bgp_peers); $sql = 'SELECT *, `bgpPeers`.bgpPeer_id as bgpPeer_id '; $sql .= 'FROM `bgpPeers` ';
$is_active = $User->get('status', $id) == User::STATUS_ACTIVE; $buttons = (!$is_guest && !$is_root && !$is_bot ? h::{'a.cs-button-compact'}(h::icon('pencil'), ['href' => "{$a->action}/edit_raw/{$id}", 'data-title' => $L->edit_raw_user_data]) : '') . (!$is_guest && !$is_root && (!$is_bot || !$Config->core['simple_admin_mode']) ? h::{'a.cs-button-compact'}(h::icon('pencil-square-o'), ['href' => "{$a->action}/edit/{$id}", 'data-title' => $L->{$is_bot ? 'edit_bot_information' : 'edit_user_information'}]) : '') . (!$is_guest && !$is_root ? h::{'a.cs-button-compact'}(h::icon($is_active ? 'minus' : 'check'), ['href' => "{$a->action}/" . ($is_active ? 'deactivate' : 'activate') . "/{$id}", 'data-title' => $L->{($is_active ? 'de' : '') . 'activate_' . ($is_bot ? 'bot' : 'user')}]) : '') . (!$is_guest && !$is_root && !$is_bot ? h::{'a.cs-button-compact'}(h::icon('group'), ['href' => "{$a->action}/groups/{$id}", 'data-title' => $L->edit_user_groups]) : '') . (!$is_root ? h::{'a.cs-button-compact'}(h::icon('key'), ['href' => "{$a->action}/permissions/{$id}", 'data-title' => $L->{$is_bot ? 'edit_bot_permissions' : 'edit_user_permissions'}]) : '-'); $user_data = $User->get($columns, $id); if ($is_root && isset($user_data['password_hash'])) { $user_data['password_hash'] = '*****'; } if (isset($user_data['reg_ip'])) { $user_data['reg_ip'] = hex2ip($user_data['reg_ip'], 10); if ($user_data['reg_ip'][1]) { $user_data['reg_ip'] = $user_data['reg_ip'][0] . h::br() . $user_data['reg_ip'][1]; } else { $user_data['reg_ip'] = $user_data['reg_ip'][0]; } } if (isset($user_data['last_ip'])) { $user_data['last_ip'] = hex2ip($user_data['last_ip'], 10); if ($user_data['last_ip'][1]) { $user_data['last_ip'] = $user_data['last_ip'][0] . h::br() . $user_data['last_ip'][1]; } else { $user_data['last_ip'] = $user_data['last_ip'][0]; } } if (in_array(User::ADMIN_GROUP_ID, $groups)) { $type = h::info('a'); } elseif (in_array(User::USER_GROUP_ID, $groups)) { $type = h::info('u'); } elseif ($is_bot) { $type = h::info('b'); } else { $type = h::info('g'); }
// This hostname already checked, skip discover $remote_device_id = $GLOBALS['cache']['discovery-protocols'][$cdp_entry['cdpCacheDeviceId']]; } else { $remote_device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?", array($cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCacheDeviceId'])); // FIXME do LLDP-code-style hostname overwrite here as well? (see below) if (!$remote_device_id && is_valid_hostname($cdp_entry['cdpCacheDeviceId']) && !is_bad_xdp($cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCachePlatform'])) { $remote_device_id = discover_new_device($cdp_entry['cdpCacheDeviceId'], 'xdp', 'CDP', $device, $port); } // Cache remote device ID for other protocols $GLOBALS['cache']['discovery-protocols'][$cdp_entry['cdpCacheDeviceId']] = $remote_device_id; } if ($remote_device_id) { $if = $cdp_entry['cdpCacheDevicePort']; $remote_port_id = dbFetchCell("SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?", array($if, $if, $remote_device_id)); } else { $remote_port_id = "0"; } if (!is_bad_xdp($cdp_entry['cdpCacheDeviceId']) && $port['port_id'] && $cdp_entry['cdpCacheDeviceId'] && $cdp_entry['cdpCacheDevicePort']) { $remote_address = hex2ip($cdp_entry['cdpCacheAddress']); if (!get_ip_version($remote_address)) { $remote_address = NULL; } discover_link($valid_link, $port['port_id'], 'cdp', $remote_port_id, $cdp_entry['cdpCacheDeviceId'], $cdp_entry['cdpCacheDevicePort'], $cdp_entry['cdpCachePlatform'], $cdp_entry['cdpCacheVersion'], $remote_address); } } else { echo "X"; } } } } // EOF
/** * @dataProvider providerHex2IP * @group ip */ public function testHex2IP($string, $result) { $this->assertSame($result, hex2ip($string)); }
echo "IP-MIB\n"; print_vars($ip_data); } if ($device['os_group'] == 'cisco' && !count($ip_data)) { // Get IP addresses from CISCO-IETF-IP-MIB //cIpAddressIfIndex.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = 450 //cIpAddressPrefix.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = cIpAddressPfxOrigin.450.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:00".64 //cIpAddressOrigin.ipv6."20:01:04:70:00:15:00:bb:00:00:00:00:00:00:00:02" = manual //Origins: 1:other, 2:manual, 4:dhcp, 5:linklayer, 6:random $ip_data = array(); foreach ($oids_ip as $oid) { $oid_data = snmpwalk_cache_oid($device, 'c' . ucfirst($oid) . '.' . $ip_version, $oid_data, 'CISCO-IETF-IP-MIB', mib_dirs('cisco')); } // Rewrite CISCO-IETF-IP-MIB array foreach ($oid_data as $key => $entry) { $ip_address = hex2ip(str_replace($ip_version . '.', '', $key)); $ifIndex = $entry['cIpAddressIfIndex']; $entry['cIpAddressPrefix'] = end(explode('.', $entry['cIpAddressPrefix'])); if (!is_numeric($entry['cIpAddressPrefix'])) { $entry['cIpAddressPrefix'] = '128'; } if (is_ipv6_valid($ip_address, $entry['cIpAddressPrefix']) === FALSE) { continue; } foreach ($oids_ip as $oid) { $ip_data[$ifIndex][$ip_address][$oid] = $entry['c' . ucfirst($oid)]; } } if ($debug && $ip_data) { echo "CISCO-IETF-IP-MIB\n"; print_vars($ip_data);
$afis['1'] = 'ipv4'; $afis['2'] = 'ipv6'; $afis['ipv4'] = '1'; $afis['ipv6'] = '2'; $safis = array(1 => 'unicast', 2 => 'multicast', 4 => 'mpls', 66 => 'mdt', 128 => 'vpn', 129 => 'vpn multicast'); //print_vars($vendor_counters); foreach ($vendor_bgp as $idx => $entry) { if (empty($vendor_PeerIndex)) { $index = $idx; } else { $index = $entry[$vendor_PeerIndex]; } if (count($vendor_use_index)) { parse_bgp_peer_index($entry, $idx, $vendor_mib); } $peer_ip = hex2ip($entry[$vendor_PeerRemoteAddr]); $afi = $entry[$vendor_PeerRemoteAddrType]; $peer_as = $entry[$vendor_PeerRemoteAs]; foreach ($safis as $i => $safi) { if (isset($vendor_counters[$index . '.' . $afi . ".{$i}"]) || isset($vendor_counters[$index . '.' . $afis[$afi] . ".{$i}"])) { if (is_numeric($afi)) { $afi = $afis[$afi]; } print_debug("INDEX: {$index}, AS: {$peer_as}, IP: {$peer_ip}, AFI: {$afi}, SAFI: {$safi}"); if (OBS_DEBUG > 1) { var_dump($entry); } $af_list[$peer_ip][$afi][$safi] = 1; if (strlen($table_rows[$peer_ip][3])) { $table_rows[$peer_ip][3] .= ', '; }
//$pws = snmpwalk_cache_oid($device, 'pwLocalIfMtu', $pws, 'JUNIPER-VPN-MIB'); //$pws = snmpwalk_cache_oid($device, 'pwRemoteIfMtu', $pws, 'JUNIPER-VPN-MIB'); $pws = snmpwalk_cache_threepart_oid($device, 'jnxVpnPwRemoteSiteId', $pws, 'JUNIPER-VPN-MIB', NULL, $flags); // pwMplsPeerLdpID if (OBS_DEBUG > 1) { echo 'PWS_WALK: ' . count($pws) . "\n"; print_vars($pws); } foreach ($pws as $pw_type => $entry) { foreach ($entry as $pw_name => $entry2) { foreach ($entry2 as $pw_ifIndex => $pw) { //if (strlen($pw['jnxVpnPwRowStatus']) && $pw['jnxVpnPwRowStatus'] != 'active') { continue; } // Skip inactive (active, notinService, notReady, createAndGo, createAndWait, destroy) // Get full index $pw_index = snmp_translate('jnxVpnPwRowStatus.' . $pw_type . '."' . $pw_name . '".' . $pw_ifIndex, 'JUNIPER-VPN-MIB'); $pw_index = str_replace('.1.3.6.1.4.1.2636.3.26.1.4.1.4.', '', $pw_index); $peer_addr = hex2ip($pw['jnxVpnRemotePeIdAddress']); $peer_addr_version = get_ip_version($peer_addr); $peer_addr_type = $pw['jnxVpnRemotePeIdAddrType']; if ($peer_addr_version) { $peer_addr_type = 'ipv' . $peer_addr_version; // Override address type, because snmp sometime return incorrect $peer_rdns = gethostbyaddr6($peer_addr); // PTR name if ($peer_addr_type == 'ipv6') { $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE); } // FIXME. Retarded way $remote_device = dbFetchCell('SELECT `device_id` FROM `' . $peer_addr_type . '_addresses` LEFT JOIN `ports` USING(`port_id`) WHERE `' . $peer_addr_type . '_address` = ? LIMIT 1;', array($peer_addr)); } else {
// Get full index $sla_index = snmp_translate('pingCtlRowStatus."' . $sla_owner . '"."' . $sla_name . '"', $mib); $sla_index = str_replace('.1.3.6.1.2.1.80.1.2.1.23.', '', $sla_index); $data = array('device_id' => $device['device_id'], 'sla_mib' => $mib, 'sla_index' => $sla_name, 'sla_owner' => $sla_owner, 'sla_tag' => $entry['pingCtlTargetAddress'], 'sla_status' => $entry['pingCtlRowStatus'], 'sla_graph' => 'jitter', 'deleted' => 0); if ($entry['pingCtlAdminStatus'] == 'disabled') { // If SLA administarively disabled, exclude from polling $data['deleted'] = 1; } // Type conversions // Standart types: pingIcmpEcho, pingUdpEcho, pingSnmpQuery, pingTcpConnectionAttempt // Juniper types: jnxPingIcmpTimeStamp, jnxPingHttpGet, jnxPingHttpGetMetadata, jnxPingDnsQuery, jnxPingNtpQuery, jnxPingUdpTimestamp // HH3C types: $data['rtt_type'] = str_replace(array('ping', 'jnxPing', 'hh3cNqa'), '', $entry['pingCtlType']); // Tag / Target if (isHexString($entry['pingCtlTargetAddress']) || stripos($data['rtt_type'], 'Echo') !== FALSE) { $data['sla_tag'] = hex2ip($data['sla_tag']); } // Limits $data['sla_limit_high'] = $entry['pingCtlTimeOut'] > 0 ? $entry['pingCtlTimeOut'] * 1000 : 5000; $data['sla_limit_high_warn'] = intval($data['sla_limit_high'] / 5); /* // Migrate old indexes if (isset($sla_db[$mib_lower][$sla_owner.'.'.$name])) { // Old (non numeric) indexes $sla_db[$mib_lower][$sla_index] = $sla_db[$mib_lower][$sla_owner.'.'.$name]; unset($sla_db[$mib_lower][$sla_owner.'.'.$name]); dbUpdate(array('sla_index' => $sla_index, 'sla_mib' => $mib), 'slas', "`sla_id` = ?", array($sla_db[$mib_lower][$sla_index]['sla_id'])); } */ // Note, here used complex index (owner.index)
$pws = snmpwalk_cache_oid($device, "pwType", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwDescr", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwPsnType", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwPeerAddrType", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwPeerAddr", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwLocalIfMtu", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwRemoteIfMtu", $pws, $mib, mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwRemoteIfString", $pws, $mib, mib_dirs()); // For MPLS pseudowires $pws = snmpwalk_cache_oid($device, "pwMplsLocalLdpID", $pws, "PW-MPLS-STD-MIB", mib_dirs()); $pws = snmpwalk_cache_oid($device, "pwMplsPeerLdpID", $pws, "PW-MPLS-STD-MIB", mib_dirs()); //echo("PWS_WALK: ".count($pws)."\n"); var_dump($pws); foreach ($pws as $pw_id => $pw) { $peer_addr_type = $pw['pwPeerAddrType']; if ($peer_addr_type == "ipv4" || $peer_addr_type == "ipv6") { $peer_addr = hex2ip($pw['pwPeerAddr']); } if (!get_ip_version($peer_addr) && $pw['pwMplsPeerLdpID']) { // Sometime return wrong peer addr (not hex string): // pwPeerAddr.8 = "\\<h&" $peer_addr = preg_replace('/:\\d+$/', '', $pw['pwMplsPeerLdpID']); } if (get_ip_version($peer_addr)) { $peer_rdns = gethostbyaddr6($peer_addr); // PTR name if ($peer_addr_type == 'ipv6') { $peer_addr = Net_IPv6::uncompress($peer_addr, TRUE); } // FIXME. Retarded way $cpw_remote_device = dbFetchCell('SELECT `device_id` FROM `' . $peer_addr_type . '_addresses` AS A, `ports` AS I WHERE A.`' . $peer_addr_type . '_address` = ? AND A.`port_id` = I.`port_id` LIMIT 1;', array($peer_addr)); } else {