function get_3Com_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { global $debug, $scan_date; /* initialize variables */ $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_key_array = array(); $port_descr = array(); $port_number = 0; $ports_active = 0; $active_ports = 0; $ports_total = 0; /* cisco uses a hybrid read string, if one is not defined, use the default */ if ($snmp_readstring == "") { $snmp_readstring = $device["snmp_readstring"]; } /* get the operational status of the ports */ $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); $indexes = array_keys($active_ports_array); $i = 0; foreach ($active_ports_array as $port_info) { if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 117) { if ($port_info == 1) { $ports_active++; } $ports_total++; } $i++; } if ($store_to_db) { print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active; if ($debug) { print "\n"; } $device["ports_active"] = $ports_active; $device["ports_total"] = $ports_total; $device["macs_active"] = 0; } if ($ports_active > 0) { /* get bridge port to ifIndex mapping */ $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.3", $device, $snmp_readstring); /* get device active port numbers */ $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.2", $device, $snmp_readstring); /* get the ignore ports list from device */ $ignore_ports = port_list_to_array($device["ignorePorts"]); /* determine user ports for this device and transfer user ports to a new array. */ $i = 0; foreach ($port_numbers as $key => $port_number) { if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) { $ifname = $ifInterfaces[$bridgePortIfIndexes[$port_number]]["ifName"]; if (!in_array($ifname, $ignore_ports)) { if (@$port_status[$key] == "3") { $port_key_array[$i]["key"] = $key; $port_key_array[$i]["port_number"] = $port_number; $i++; } } } } /* compare the user ports to the brige port data, store additional relevant data about the port. */ $i = 0; foreach ($port_key_array as $port_key) { /* map bridge port to interface port and check type */ if ($port_key["port_number"] > 0) { if (sizeof($bridgePortIfIndexes) != 0) { /* some hubs do not always return a port number in the bridge table. test for it by isset and substiture the port number from the ifTable if it isnt in the bridge table */ if (isset($bridgePortIfIndexes[$port_key["port_number"]])) { $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]]; } else { $brPortIfIndex = @$port_key["port_number"]; } $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"]; } else { $brPortIfIndex = $port_key["port_number"]; $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"]; } if (($brPortIfType >= 6 && $brPortIfType <= 9 || $brPortIfType == 117) && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) { /* set some defaults */ $new_port_key_array[$i]["vlan_id"] = "N/A"; $new_port_key_array[$i]["vlan_name"] = "N/A"; $new_port_key_array[$i]["mac_address"] = "NOT USER"; $new_port_key_array[$i]["port_number"] = "NOT USER"; $new_port_key_array[$i]["port_name"] = "N/A"; /* now set the real data */ $new_port_key_array[$i]["key"] = $port_key["key"]; $new_port_key_array[$i]["port_number"] = $port_key["port_number"]; $new_port_key_array[$i]["port_name"] = $ifInterfaces[$brPortIfIndex]["ifName"]; $i++; } } } mactrack_debug("Port number information collected."); /* map mac address */ /* only continue if there were user ports defined */ if (sizeof($new_port_key_array) > 0) { /* get the bridges active MAC addresses */ $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring); foreach ($port_macs as $key => $port_mac) { $port_macs[$key] = xform_mac_address($port_mac); } foreach ($new_port_key_array as $key => $port_key) { $new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]]; mactrack_debug("INDEX: '" . $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]); } mactrack_debug("Port mac address information collected."); } else { mactrack_debug("No user ports on this network."); } } else { mactrack_debug("No user ports on this network."); } if ($store_to_db) { if ($ports_active <= 0) { $device["last_runmessage"] = "Data collection completed ok"; } elseif (sizeof($new_port_key_array) > 0) { $device["last_runmessage"] = "Data collection completed ok"; $device["macs_active"] = sizeof($new_port_key_array); db_store_device_port_results($device, $new_port_key_array, $scan_date); } else { $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; } if (!$debug) { print " - Complete\n"; } } else { return $new_port_key_array; } }
function get_JEX_switch_ports($site, &$device, $lowPort = 0, $highPort = 0) { global $debug, $scan_date; /* initialize port counters */ $device["ports_total"] = 0; $device["ports_active"] = 0; $device["ports_trunk"] = 0; /* get VLAN information */ $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.5", $device); $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.2636.3.40.1.5.1.5.1.2", $device); /* get VLAN Trunk status */ $device["vlans_total"] = sizeof($vlan_ids) - 1; mactrack_debug("VLAN data collected. There are " . (sizeof($vlan_ids) - 1) . " VLANS."); /* get the ifIndexes for the device */ $ifIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.1", $device); mactrack_debug("ifIndexes data collection complete"); /* get and store the interfaces table */ $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE); foreach ($ifIndexes as $ifIndex) { $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex]; if ($ifInterfaces[$ifIndex]["ifType"] == "propVirtual(53)" or $ifInterfaces[$ifIndex]["ifType"] == "ieee8023adLag(161)") { $device["ports_total"]++; } if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) { $device["ports_trunk"]++; } } mactrack_debug("ifInterfaces assembly complete."); $i = 0; foreach ($vlan_ids as $vlan_id => $vlan_num) { $active_vlans[$vlan_id]["vlan_id"] = $vlan_num; $active_vlans[$vlan_id]["vlan_name"] = $vlan_names[$vlan_id]; $active_vlans++; $i++; } mactrack_debug("Vlan assembly complete."); if (sizeof($active_vlans) > 0) { $i = 0; /* get the port status information */ //$port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE); $mac_results = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device); $port_results = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device); $i = 0; $j = 0; $port_array = array(); foreach ($mac_results as $num => $mac_result) { if ($mac_result != 0) { $Xvlanid = substr($num, 0, strpos($num, ".")); $Xmac = mach(substr($num, strpos($num, ".") + 1)); $ifIndex = $port_results[$mac_result]; $ifType = $ifInterfaces[$ifIndex]["ifType"]; $ifName = $ifInterfaces[$ifIndex]["ifName"]; $portName = $ifName; $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"]; /* only output legitamate end user ports */ //if ((($ifType >= 6) && ($ifType <= 9)) and ( $portName != "" or $portName != "1" )) { if ($portName != "" and $portName != "1") { $port_array[$i]["vlan_id"] = $active_vlans[$Xvlanid]["vlan_id"]; //@$vlan_ids[$Xvlanid]; $port_array[$i]["vlan_name"] = $active_vlans[$Xvlanid]["vlan_name"]; //@$vlan_names[$Xvlandid]; $port_array[$i]["port_number"] = @$port_results[$mac_result]; $port_array[$i]["port_name"] = trim($ifName); $port_array[$i]["mac_address"] = xform_mac_address($Xmac); $device["ports_active"]++; mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]); $i++; } $j++; } } /* display completion message */ print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"]; $device["last_runmessage"] = "Data collection completed ok"; $device["macs_active"] = sizeof($port_array); db_store_device_port_results($device, $port_array, $scan_date); } else { print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active devcies on this network device."; $device["snmp_status"] = HOST_UP; $device["last_runmessage"] = "Data collection completed ok. No active devices on this network device."; } return $device; }
function get_extreme_arp_table($site, &$device, $extremeware = false) { global $debug, $scan_date; /* EXTREME-FDB-MIB::extremeFdbIpFdbIPAddress : The IP Address of the IP FDB entry. .1.3.6.1.4.1.1916.1.16.2.1.2 EXTREME-FDB-MIB::extremeFdbIpFdbMacAddress : The MAC address corresponding to the IP Address. .1.3.6.1.4.1.1916.1.16.2.1.3 EXTREME-FDB-MIB::extremeFdbIpFdbVlanIfIndex : The ifIndex of the Vlan on which this ip is learned. .1.3.6.1.4.1.1916.1.16.2.1.4 EXTREME-FDB-MIB::extremeFdbIpFdbPortIfIndex : The IfIndex of the port on which this entry was learned. .1.3.6.1.4.1.1916.1.16.2.1.5 EXTREME-VLAN-MIB::extremeVlanIfIndex.<vlanid> = index .1.3.6.1.4.1.1916.1.2.1.2.1.1 EXTREME-VLAN-MIB::extremeVlanIfDescr.<vlanid> = description .1.3.6.1.4.1.1916.1.2.1.2.1.2 EXTREME-VLAN-MIB::extremeVlanIfVlanId.<vlanid> = tag id .1.3.6.1.4.1.1916.1.2.1.2.1.10 BRIDGE-MIB::dot1dBasePortIfIndex : get Ifindex from extremeFdbIpFdbPortIfIndex .1.3.6.1.2.1.17.1.4.1.2 IF-MIB::ifName : get name of port from IfIndex .1.3.6.1.2.1.31.1.1.1.1 */ if ($extremeware) { // for extremeware use standard apr table + ifDescr for interface name /* get the atifIndexes for the device */ $atifIndexes = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.1", $device); $atEntries = array(); if (sizeof($atifIndexes)) { mactrack_debug("atifIndexes data collection complete"); $atPhysAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.2", $device); mactrack_debug("atPhysAddress data collection complete"); $atNetAddress = xform_stripped_oid(".1.3.6.1.2.1.3.1.1.3", $device); mactrack_debug("atNetAddress data collection complete"); $ifDescr = xform_stripped_oid(".1.3.6.1.2.1.2.2.1.2", $device); mactrack_debug("ifDescr data collection complete"); } $i = 0; if (sizeof($atifIndexes)) { foreach ($atifIndexes as $key => $atifIndex) { $atEntries[$i]["atifIndex"] = $ifDescr[$atifIndex]; $atEntries[$i]["atPhysAddress"] = xform_mac_address($atPhysAddress[$key]); $atEntries[$i]["atNetAddress"] = xform_net_address($atNetAddress[$key]); $i++; } } } else { /* get the atifIndexes for the device */ $FdbPortIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.5", $device); $atEntries = array(); if (sizeof($FdbPortIfIndex)) { mactrack_debug("FdbPortIfIndex data collection complete"); $FdbMacAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.3", $device); mactrack_debug("FdbMacAddress data collection complete"); $FdbIPAddress = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.2", $device); mactrack_debug("FdbIPAddress data collection complete"); $FdbVlanIfIndex = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.2.1.4", $device); mactrack_debug("FdbVlanIfIndex data collection complete"); $VlanIfVlanId = xform_stripped_oid(".1.3.6.1.4.1.1916.1.2.1.2.1.10", $device); mactrack_debug("VlanIfVlanId data collection complete"); $BasePortIfIndex = xform_stripped_oid(".1.3.6.1.2.1.17.1.4.1.2", $device); mactrack_debug("BasePortIfIndex data collection complete"); $ifName = xform_stripped_oid(".1.3.6.1.2.1.31.1.1.1.1", $device); mactrack_debug("ifName data collection complete"); } $i = 0; if (sizeof($FdbPortIfIndex)) { foreach ($FdbPortIfIndex as $key => $PortIndex) { $atEntries[$i]["atifIndex"] = $ifName[$BasePortIfIndex[$PortIndex]] . ", vlan:" . $VlanIfVlanId[$FdbVlanIfIndex[$key]]; $atEntries[$i]["atPhysAddress"] = xform_mac_address($FdbMacAddress[$key]); $atEntries[$i]["atNetAddress"] = xform_net_address($FdbIPAddress[$key]); $i++; } } mactrack_debug("atEntries assembly complete."); } /* output details to database */ if (sizeof($atEntries)) { foreach ($atEntries as $atEntry) { $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "','" . $device["device_name"] . "','" . $atEntry["atifIndex"] . "','" . $atEntry["atPhysAddress"] . "','" . $atEntry["atNetAddress"] . "','" . $scan_date . "')"; //mactrack_debug("SQL: " . $insert_string); db_execute($insert_string); } } /* save ip information for the device */ $device["ips_total"] = sizeof($atEntries); db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'"); mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: nb IP=" . sizeof($atEntries) . "."); }
function get_enterasys_N7_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { global $debug, $scan_date; mactrack_debug("FUNCTION: get_enterasys_N7_dot1dTpFdbEntry_ports started"); /* initialize variables */ $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_key_array = array(); $port_number = 0; $ports_active = 0; $active_ports = 0; $ports_total = 0; /* cisco uses a hybrid read string, if one is not defined, use the default */ if ($snmp_readstring == "") { $snmp_readstring = $device["snmp_readstring"]; } /* get the operational status of the ports */ $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); mactrack_debug("get active ports: " . sizeof($active_ports_array)); $indexes = array_keys($active_ports_array); $i = 0; foreach ($active_ports_array as $port_info) { if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9) { if ($port_info == 1) { $ports_active++; } $ports_total++; } $i++; } if ($store_to_db) { print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active; if ($debug) { print "\n"; } $device["ports_active"] = $ports_active; $device["ports_total"] = $ports_total; $device["macs_active"] = 0; } if ($ports_active > 0) { /* get bridge port to ifIndex mapping: dot1dBasePortIfIndex from dot1dBasePortTable GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.1: 1 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.2: 4 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.64: 12001 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.65: 12002 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.66: 12003 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.67: 12004 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.68: 12005 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.69: 12006 GET NEXT: 1.3.6.1.2.1.17.1.4.1.2.70: 12007 where table index = bridge port (dot1dBasePort) and table value = ifIndex */ /* -------------------------------------------- */ $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); mactrack_debug("get bridgePortIfIndexes: " . sizeof($bridgePortIfIndexes)); /* get port status: dot1dTpFdbStatus from dot1dTpFdbTable GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.0.94.0.1.1: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.32.11.99: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.37.228.26: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.227.37.238.180: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.56.96.234: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.59.133.114: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.107.157.61: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.107.189.168: 3 GET NEXT: 1.3.6.1.2.1.17.4.3.1.3.0.1.230.109.208.105: 3 where table index = MAC Address (dot1dTpFdbAddress e.g. 0.0.94.0.1.1 = 00:00:5E:00:01:01) and table value = port status (other(1), invalid(2), learned(3), self(4), mgmt(5)*/ /* -------------------------------------------- */ $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.3", $device, $snmp_readstring); mactrack_debug("get port_status: " . sizeof($port_status)); /* get device active port numbers: dot1dTpFdbPort from dot1dTpFdbTable GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.0.94.0.1.1: 72 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.32.11.99: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.37.228.26: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.227.37.238.180: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.56.96.234: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.59.133.114: 69 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.107.157.61: 70 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.107.189.168: 68 GET NEXT: 1.3.6.1.2.1.17.4.3.1.2.0.1.230.109.208.105: 68 where table index = MAC Address (dot1dTpFdbAddress e.g. 0.0.94.0.1.1 = 00:00:5E:00:01:01) and table value = bridge port */ /* -------------------------------------------- */ $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.2", $device, $snmp_readstring); mactrack_debug("get port_numbers: " . sizeof($port_numbers)); /* get VLAN information */ /* -------------------------------------------- */ #$vlan_ids = xform_enterasys_N7_vlan_associations($device, $snmp_readstring); $vlan_ids = xform_dot1q_vlan_associations($device, $snmp_readstring); mactrack_debug("get vlan_ids: " . sizeof($vlan_ids)); #print_r($vlan_ids); /* get the ignore ports list from device */ $ignore_ports = port_list_to_array($device["ignorePorts"]); /* determine user ports for this device and transfer user ports to a new array. */ $i = 0; foreach ($port_numbers as $key => $port_number) { /* key = MAC Address from dot1dTpFdbTable */ /* value = bridge port */ if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) { if (!in_array($port_number, $ignore_ports)) { if (@$port_status[$key] == "3") { $port_key_array[$i]["key"] = $key; $port_key_array[$i]["port_number"] = $port_number; #print("i: $i, Key: " . $port_key_array[$i]["key"] . ", Number: $port_number\n"); $i++; } } } } /* compare the user ports to the brige port data, store additional relevant data about the port. */ $i = 0; foreach ($port_key_array as $port_key) { /* map bridge port to interface port and check type */ if ($port_key["port_number"] > 0) { if (sizeof($bridgePortIfIndexes) != 0) { /* some hubs do not always return a port number in the bridge table. test for it by isset and substiture the port number from the ifTable if it isnt in the bridge table */ #print("searching bridge port: " . $port_key["port_number"] .", Bridge: " . $bridgePortIfIndexes[$port_key["port_number"]] . "\n"); if (isset($bridgePortIfIndexes[$port_key["port_number"]])) { $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]]; } else { $brPortIfIndex = @$port_key["port_number"]; } $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"]; } else { $brPortIfIndex = $port_key["port_number"]; $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"]; } if ($brPortIfType >= 6 && $brPortIfType <= 9 && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) { /* set some defaults */ $new_port_key_array[$i]["vlan_id"] = "N/A"; $new_port_key_array[$i]["vlan_name"] = "N/A"; $new_port_key_array[$i]["mac_address"] = "NOT USER"; $new_port_key_array[$i]["port_number"] = "NOT USER"; $new_port_key_array[$i]["port_name"] = "N/A"; /* now set the real data */ $new_port_key_array[$i]["key"] = @$port_key["key"]; $new_port_key_array[$i]["port_number"] = @$brPortIfIndex; $new_port_key_array[$i]["vlan_id"] = @$vlan_ids[$port_key["key"]]; #print_r($new_port_key_array[$i]); $i++; } } } mactrack_debug("Port number information collected: " . sizeof($new_port_key_array)); /* map mac address */ /* only continue if there were user ports defined */ if (sizeof($new_port_key_array) > 0) { /* get the bridges active MAC addresses */ $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring); foreach ($port_macs as $key => $port_mac) { $port_macs[$key] = xform_mac_address($port_mac); } foreach ($new_port_key_array as $key => $port_key) { $new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]]; mactrack_debug("INDEX: '" . $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]); } mactrack_debug("Port mac address information collected: " . sizeof($port_macs)); } else { mactrack_debug("No user ports on this network."); } } else { mactrack_debug("No user ports on this network."); } if ($store_to_db) { if ($ports_active <= 0) { $device["last_runmessage"] = "Data collection completed ok"; } elseif (sizeof($new_port_key_array) > 0) { $device["last_runmessage"] = "Data collection completed ok"; $device["macs_active"] = sizeof($new_port_key_array); db_store_device_port_results($device, $new_port_key_array, $scan_date); } else { $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; } if (!$debug) { print " - Complete\n"; } } else { return $new_port_key_array; } }
function get_dlink_l2_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { global $debug, $scan_date; /* initialize variables */ $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_key_array = array(); $port_number = 0; $ports_active = 0; $active_ports = 0; $ports_total = 0; /* cisco uses a hybrid read string, if one is not defined, use the default */ if ($snmp_readstring == "") { $snmp_readstring = $device["snmp_readstring"]; } /* get the operational status of the ports */ $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); $indexes = array_keys($active_ports_array); $i = 0; foreach ($active_ports_array as $port_info) { //print ("=type--]=[". $ifInterfaces[$indexes[$i]]["ifType"] . "]\n"); if (convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) >= 6 && convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) <= 9 || convert_dlink_data($ifInterfaces[$indexes[$i]]["ifType"]) == 117) { if (convert_dlink_data($port_info) == 1) { $ports_active++; } $ports_total++; } $i++; } if ($store_to_db) { print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active; if ($debug) { print "\n"; } $device["ports_active"] = $ports_active; $device["ports_total"] = $ports_total; $device["macs_active"] = 0; } if ($ports_active > 0) { /* get bridge port to ifIndex mapping */ $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); $vlan_names = xform_standard_indexed_data(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device, $snmp_readstring); $port_status = xform_stripped_oid("1.3.6.1.2.1.17.7.1.2.2.1.3", $device, $snmp_readstring); /* get device active port numbers */ $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring); /* get device active port numbers */ //$vlan_id = get_vlan_id_oid($port_numbers); /* get device active port numbers */ //$vlan_ids = xform_dlink_vlan_associations($device, $snmp_readstring); /* get the ignore ports list from device */ $ignore_ports = port_list_to_array($device["ignorePorts"]); /* determine user ports for this device and transfer user ports to a new array. */ $i = 0; foreach ($port_numbers as $key => $port_number) { if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort) { if (!in_array($port_number, $ignore_ports)) { if (@$port_status[$key] == "3" || @$port_status[$key] == "1") { $port_key_array[$i]["key"] = $key; $port_key_array[$i]["port_number"] = $port_number; //print ("---------->>>key(i)=[$key] port_number=[$port_number] ]\n"); $i++; } } } } $i = 0; // foreach ($vlan_ids as $key => $vlan_item) { // $port_key_array[$i]["key"] = $key; // $port_key_array[$i]["vlan_id"] = $vlan_item["vlan_id"]; // $port_key_array[$i]["vlan_name"] = $vlan_item["vlan_name"]; //print ("---------->>>key(i)=[$i = $vlan_item] vlan_id=[" . $vlan_item["vlan_id"] . "][" . $vlan_item["vlan_name"] . "]\n"); // $i++; // } // $i = 0; // foreach ($vlan_ids as $key => $vlan_name) { // //$port_key_array[$i]["key"] = $key; // $port_key_array[$i]["vlan_name"] = $vlan_name[$i]["vlan_name"]; // print ("---------->>>key(i)=[$i] vlan_name=[" . $vlan_name[$i]["vlan_name"] . "]\n"); // $i++; // } /* compare the user ports to the brige port data, store additional relevant data about the port. */ $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.18", $device); $i = 0; foreach ($port_key_array as $port_key) { /* map bridge port to interface port and check type */ if ($port_key["port_number"] >= 0) { if (sizeof($bridgePortIfIndexes) != 0) { /* some hubs do not always return a port number in the bridge table. test for it by isset and substiture the port number from the ifTable if it isnt in the bridge table */ if (isset($bridgePortIfIndexes[$port_key["port_number"]])) { $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]]; } else { $brPortIfIndex = @$port_key["port_number"]; } $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"]; } else { $brPortIfIndex = $port_key["port_number"]; $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"]; } if ((convert_dlink_data($brPortIfType) >= 6 && convert_dlink_data($brPortIfType) <= 9 || convert_dlink_data($brPortIfType) == 117) && !isset($ifInterfaces[$brPortIfIndex]["portLink"])) { /* set some defaults */ $new_port_key_array[$i]["vlan_id"] = get_dlink_vlan_id($port_key["key"]); $new_port_key_array[$i]["vlan_name"] = $vlan_names[$new_port_key_array[$i]["vlan_id"]]; $new_port_key_array[$i]["mac_address"] = dlink_convert_macs($port_key["key"]); $new_port_key_array[$i]["port_number"] = $port_key["port_number"]; $new_port_key_array[$i]["port_name"] = @$ifNames[$port_key["port_number"]]; //print ("===bef key=[". $port_key[$i]["vlan_id"] . "]\n"); /* now set the real data */ $new_port_key_array[$i]["key"] = $port_key["key"]; //$new_port_key_array[$i]["port_number"] = $port_key["port_number"]; //$new_port_key_array[$i]["mac_address"] = dlink_convert_macs($port_key["key"]); // print ("===check key=[". $new_port_key_array["key"] . "] = [" . $port_key["key"] . "]\n"); // print ("===check key2[". $new_port_key_array[$i]["key"] . "] = [" . $port_key[$i]["key"] . "]\n"); //print ("----------key(i)=[$i]-[$key] port=[" . $new_port_key_array[$i]["port_number"] . "] vlan_id=[" . $new_port_key_array[$i]["vlan_id"] . "] mac_address=[" . $new_port_key_array[$i]["mac_address"] . "] vlan_name=[" . $new_port_key_array[$i]["vlan_name"] . "]\n"); //mactrack_debug("INDEX: [$i]-[" . $port_key["key"] . "] port=[" . $new_port_key_array[$i]["port_number"] . "] vlan_id=[" . $new_port_key_array[$i]["vlan_id"] . "] mac_address=[" . $new_port_key_array[$i]["mac_address"] . "] vlan_name=[" . $new_port_key_array[$i]["vlan_name"] . "]"); $i++; } } } mactrack_debug("Port number information collected."); /* map mac address */ /* only continue if there were user ports defined */ // if (sizeof($new_port_key_array) > 0) { // /* get the bridges active MAC addresses */ // // $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.4.3.1.1", $device, $snmp_readstring); // $port_macs = xform_dlink_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring); // // foreach ($port_macs as $key => $port_mac) { // // //print ("===bef key=[". $key . "]\n"); // //print ("===bef port_macs[key]=[". $port_macs[$key] . "]\n"); // $port_macs[$key] = xform_mac_address($port_mac); // //print ("===aft port_macs[key]=[". $port_macs[$key] . "]\n"); // } // // foreach ($new_port_key_array as $key => $port_key) { // // // print ("===++++++==[key]=[". $port_key["key"] . "]\n"); // // } // foreach ($port_macs as $key => $port_mac) { // // // print ("===------==[key]=[". @$port_mac[4] . "]\n"); // // } // // foreach ($new_port_key_array as $key => $port_key) { // $new_port_key_array[$key]["mac_address"] = @$port_macs[$port_key["key"]]; // //print ("==key=[$key] = [". $new_port_key_array[$key]["mac_address"] . "] port=[" . $new_port_key_array[$key]["port_number"] . "]\n"); // //print ("==2aft port_key[key]=[". $port_key["key"] . "]\n"); // //print ("==2aft port_macs[port_key[key]]=[". @$port_macs[$port_key["key"]] . "]\n"); // //$new_port_key_array[$key]["vlan_id"] = @$port_macs[$port_key["key"]]["vlan_id"]; // // print ("===check key3[". $new_port_key_array[$key] . "] = [ " . $port_macs[$port_key["key"]] . "]\n"); // // mactrack_debug("INDEX: '". $key . "' MAC ADDRESS: key=" . $port_key["key"] . "=[" . $port_key["key"] . "] vlan_id=[" . $port_key["vlan_id"]); // } // // mactrack_debug("Port mac address information collected."); // }else{ // mactrack_debug("No user ports on this network."); // } } else { mactrack_debug("No user ports on this network."); } if ($store_to_db) { if ($ports_active <= 0) { $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; } elseif (sizeof($new_port_key_array) > 0) { $device["last_runmessage"] = "Data collection completed ok"; $device["macs_active"] = sizeof($new_port_key_array); db_store_device_port_results($device, $new_port_key_array, $scan_date); } else { $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; } if (!$debug) { print " - Complete\n"; } } else { return $new_port_key_array; } }
function get_base_dell_dot1qFdb_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999) { global $debug, $scan_date; /* initialize variables */ $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_key_array = array(); $port_number = 0; $ports_active = 0; $active_ports = 0; $ports_total = 0; $snmp_readstring = $device["snmp_readstring"]; /* get the operational status of the ports */ $active_ports_array = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device); $indexes = array_keys($active_ports_array); /* Sanitize active ports array, removing text junk as the dell's don't return just a plain numeric value */ if (sizeof($active_ports_array)) { foreach ($active_ports_array as $key => $tempPorts) { preg_match("/[0-9]{1,3}/", $tempPorts, $newStatus); $active_ports_array[$key] = $newStatus[0]; } } $i = 0; if (sizeof($active_ports_array)) { foreach ($active_ports_array as $port_info) { if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 71) { if ($port_info == 1) { $ports_active++; } $ports_total++; } $i++; } } if ($store_to_db) { print "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", OPER PORTS: " . $ports_active; if ($debug) { print "\n"; } $device["ports_active"] = $ports_active; $device["ports_total"] = $ports_total; $device["macs_active"] = 0; } if ($ports_active > 0) { /* get bridge port to ifIndex mapping */ $bridgePortIfIndexes = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring); $port_status = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.3", $device, $snmp_readstring); /* Sanitize port_status array, removing text junk as the dell's don't return just a plain numeric value*/ if (sizeof($port_status)) { foreach ($port_status as $key => $tempStatus) { preg_match("/[0-9]{1,3}/", $tempStatus, $newStatus); $port_status[$key] = $newStatus[0]; } } //print_r($port_status); /* get device active port numbers This is the OID that shows the mac address as the index and the port as the value*/ $port_numbers = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.2", $device, $snmp_readstring); /* get the ignore ports list from device */ $ignore_ports = port_list_to_array($device["ignorePorts"]); /* get the bridge root port so we don't capture active ports on it */ $bridge_root_port = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.2.7.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]); /* determine user ports for this device and transfer user ports to a new array. */ $i = 0; if (sizeof($port_numbers)) { foreach ($port_numbers as $key => $port_number) { if ($highPort == 0 || $port_number >= $lowPort && $port_number <= $highPort && $bridge_root_port != $port_number) { if (!in_array($port_number, $ignore_ports)) { if (@$port_status[$key] == "3" || @$port_status[$key] == "5") { $port_key_array[$i]["key"] = $key; $port_key_array[$i]["port_number"] = $port_number; $i++; } } } } } /* compare the user ports to the brige port data, store additional relevant data about the port. */ $i = 0; if (sizeof($port_key_array)) { foreach ($port_key_array as $port_key) { /* map bridge port to interface port and check type */ if ($port_key["port_number"] > 0) { if (sizeof($bridgePortIfIndexes) != 0) { $brPortIfIndex = @$bridgePortIfIndexes[$port_key["port_number"]]; $brPortIfType = @$ifInterfaces[$brPortIfIndex]["ifType"]; } else { $brPortIfIndex = $port_key["port_number"]; $brPortIfType = @$ifInterfaces[$port_key["port_number"]]["ifType"]; } if ($brPortIfType >= 6 && $brPortIfType <= 9 || $brPortIfType == 71) { /* set some defaults */ $new_port_key_array[$i]["vlan_id"] = "N/A"; $new_port_key_array[$i]["vlan_name"] = "N/A"; $new_port_key_array[$i]["mac_address"] = "NOT USER"; $new_port_key_array[$i]["port_number"] = "NOT USER"; $new_port_key_array[$i]["port_name"] = "N/A"; /* now set the real data */ $new_port_key_array[$i]["key"] = $port_key["key"]; $new_port_key_array[$i]["port_number"] = $port_key["port_number"]; $new_port_key_array[$i]["port_name"] = $ifInterfaces[$port_key["port_number"]]["ifAlias"]; $i++; } } } } mactrack_debug("Port number information collected."); /* map mac address */ /* only continue if there were user ports defined */ if (sizeof($new_port_key_array)) { foreach ($new_port_key_array as $key => $port_mac) { $new_port_key_array[$key]["mac_address"] = dell_mac_address_convert($port_mac["key"]); mactrack_debug("INDEX: '" . $key . "' MAC ADDRESS: " . $new_port_key_array[$key]["mac_address"]); } /* Map Vlan names to pvid's */ $vlan_names = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.4.3.1.1", $device, $snmp_readstring); /* map pvid's to ports with vlan names*/ if (sizeof($new_port_key_array)) { foreach ($new_port_key_array as $key => $port) { $temp_array = explode(".", $port["key"]); $new_port_key_array[$key]["vlan_id"] = $temp_array[0]; $new_port_key_array[$key]["vlan_name"] = @$vlan_names[$new_port_key_array[$key]["vlan_id"]]; } } mactrack_debug("Port mac address information collected."); } else { mactrack_debug("No user ports on this network."); } } else { mactrack_debug("No user ports on this network."); } if ($store_to_db) { if ($ports_active <= 0) { $device["last_runmessage"] = "Data collection completed ok"; } elseif (sizeof($new_port_key_array) > 0) { $device["last_runmessage"] = "Data collection completed ok"; $device["macs_active"] = sizeof($new_port_key_array); db_store_device_port_results($device, $new_port_key_array, $scan_date); } else { $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device."; } if (!$debug) { print " - Complete\n"; } } else { return $new_port_key_array; } }