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_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_repeater_rev4_ports($site, &$device, $lowPort, $highPort) { global $debug, $scan_date; $snmp_readstring = get_repeater_snmp_readstring($device); if (strlen($snmp_readstring) > 0) { $ports_active = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.5.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"]) - 1; $ports_total = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.4.1.52.4.1.1.1.4.1.1.4.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"]) - 1; /* get the ignore ports list */ $ignore_ports = port_list_to_array($device["ignorePorts"]); print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $ports_total . ", ACTIVE PORTS: " . $ports_active; if ($debug) { print "\n"; } $device["vlans_total"] = 0; $device["ports_total"] = $ports_total; if ($ports_active >= 0) { $device["ports_active"] = $ports_active; } else { $device["ports_active"] = 0; } if ($device["snmp_version"] == 2) { $snmp_version = "2c"; } else { $snmp_version = $device["snmp_version"]; } $port_keys = array(); $return_array = array(); $new_port_key_array = array(); $port_number = 0; $nextOID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.2"; $to = ceil($device["snmp_timeout"] / 1000); $i = 0; $previous_port = 0; while (1) { $exec_string = trim(read_config_option("path_snmpgetnext") . " -c " . $snmp_readstring . " -OnUQ -v " . $snmp_version . " -r " . $device["snmp_retries"] . " -t " . $to . " " . $device["hostname"] . ":" . $device["snmp_port"] . " " . $nextOID); exec($exec_string, $return_array, $return_code); list($nextOID, $port_number) = explode("=", $return_array[$i]); if ($port_number < $previous_port) { break; } if ($port_number <= $highPort && $port_number >= $lowPort) { if (!in_array($port_number, $ignore_ports)) { /* set defaults for devices in case they don't have/support vlans */ $new_port_key_array[$i]["vlan_id"] = "N/A"; $new_port_key_array[$i]["vlan_name"] = "N/A"; $new_port_key_array[$i]["port_name"] = "N/A"; $new_port_key_array[$i]["key"] = trim(substr($nextOID, 36)); $new_port_key_array[$i]["port_number"] = trim(strtr($port_number, " ", "")); } $previous_port = trim(strtr($port_number, " ", "")); } else { break; } mactrack_debug("CMD: " . $exec_string . ", PORT: " . $port_number); $i++; $port_number = ""; } if (sizeof($new_port_key_array) > 0) { /* map mac address */ $i = 0; foreach ($new_port_key_array as $port_key) { $OID = ".1.3.6.1.4.1.52.4.1.1.1.4.1.5.2.1.1." . $port_key["key"]; $mac_address = @cacti_snmp_get($device["hostname"], $snmp_readstring, $OID, $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"]); $new_port_key_array[$i]["mac_address"] = xform_mac_address($mac_address); mactrack_debug("OID: " . $OID . ", MAC ADDRESS: " . $new_port_key_array[$i]["mac_address"]); $i++; } $device["last_runmessage"] = "Data collection completed ok"; } else { mactrack_debug("INFO: The following device has no active ports: " . $site . "/" . $device["hostname"] . "\n"); $device["last_runmessage"] = "Data collection completed ok"; } } else { mactrack_debug("ERROR: Could not determine snmp_readstring for host: " . $site . "/" . $device["hostname"] . "\n"); $device["snmp_status"] = HOST_ERROR; $device["last_runmessage"] = "ERROR: Could not determine snmp_readstring for host."; } if (!$debug) { print " - Complete\n"; } $device["ports_active"] = $ports_active; $device["macs_active"] = sizeof($new_port_key_array); db_store_device_port_results($device, $new_port_key_array, $scan_date); return $device; }
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; } }