function get_enterasys_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; $device["vlans_total"] = 0; /* get VLAN information */ $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.4.4.1.2", $device); /* get VLAN Trunk status */ $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.5.4", $device); $device["vlans_total"] = sizeof($vlan_trunkstatus); mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " 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 the ifTypes for the device */ $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device); mactrack_debug("ifTypes data collection complete."); /* get the ifNames for the device */ $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device); mactrack_debug("ifNames data collection complete."); /* get ports that happen to be link ports */ $link_ports = get_link_port_status($device); mactrack_debug("ipAddrTable scanning for link ports data collection complete."); if (sizeof($ifIndexes)) { foreach ($ifIndexes as $ifIndex) { $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex; $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex]; $ifInterfaces[$ifIndex]["ifType"] = mactrack_strip_alpha($ifTypes[$ifIndex]); $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex]; $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex]; } } mactrack_debug("ifInterfaces assembly complete."); /* calculate the number of end user ports */ if (sizeof($ifTypes)) { foreach ($ifTypes as $ifType) { $ifType = mactrack_strip_alpha($ifType); if ($ifType >= 6 && $ifType <= 9) { $device["ports_total"]++; } } } mactrack_debug("Total Ports = " . $device["ports_total"]); /* calculate the number of trunk ports */ if (sizeof($ifIndexes)) { foreach ($ifIndexes as $ifIndex) { if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1) { $device["ports_trunk"]++; } } } mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]); /* get VLAN details */ $i = 0; if (sizeof($vlan_ids)) { foreach ($vlan_ids as $vlan_id => $vlan_name) { $active_vlans[$i]["vlan_id"] = $vlan_id; $active_vlans[$i]["vlan_name"] = $vlan_name; $active_vlans++; $i++; } } if (sizeof($active_vlans)) { /* get the port status information */ $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE); $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.52.4.1.2.16.3.1.1.3.4", $device); $i = 0; $j = 0; $port_array = array(); foreach ($port_results as $port_result) { mactrack_debug("Got Here"); $ifIndex = $port_result["port_number"]; $ifType = mactrack_strip_alpha($ifTypes[$ifIndex]); $ifName = $ifNames[$ifIndex]; $portName = $ifName; $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"]; /* only output legitimate end user ports */ if ($ifType >= 6 && $ifType <= 9) { $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]]; $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]]; $port_array[$i]["port_number"] = @$port_result["port_number"]; $port_array[$i]["port_name"] = $portName; $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]); $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 devices 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_foundry_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; $device["vlans_total"] = 0; $device["ports_dual_mode"] = 0; /* get VLAN information */ $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.7.1.21", $device); /* get VLAN Trunk status */ $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.4", $device); $device["vlans_total"] = sizeof($vlan_trunkstatus); mactrack_debug("VLAN data collected. There are " . sizeof($vlan_ids) . " 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 the ifTypes for the device */ $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device); mactrack_debug("ifTypes data collection complete."); /* get the ifNames for the device */ $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device); mactrack_debug("ifNames data collection complete."); /* get ports that happen to be link ports */ $link_ports = get_link_port_status($device); mactrack_debug("ipAddrTable scanning for link ports data collection complete."); /* get ports that have no vlan id (non dual-mode) */ $port_dualmode = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.3.5.1.24", $device); mactrack_debug("ifVlanId data collection complete."); if (sizeof($ifIndexes)) { foreach ($ifIndexes as $ifIndex) { $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex; $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex]; $ifInterfaces[$ifIndex]["ifType"] = $ifTypes[$ifIndex]; $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex]; $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex]; $ifInterfaces[$ifIndex]["ifVlanId"] = @$port_dualmode[$ifIndex]; } } mactrack_debug("ifInterfaces assembly complete."); /* calculate the number of end user ports */ if (sizeof($ifTypes)) { foreach ($ifTypes as $ifType) { if ($ifType >= 6 && $ifType <= 9) { $device["ports_total"]++; } } } mactrack_debug("Total Ports = " . $device["ports_total"]); /* calculate the number of trunk ports */ if (sizeof($ifIndexes)) { foreach ($ifIndexes as $ifIndex) { if ($ifInterfaces[$ifIndex]["trunkPortState"] == 1 && $ifInterfaces[$ifIndex]["ifVlanId"] == 0) { $device["ports_trunk"]++; } } } mactrack_debug("Total Trunk Ports = " . $device["ports_trunk"]); /* get VLAN details */ $i = 0; if (sizeof($vlan_ids)) { foreach ($vlan_ids as $vlan_id => $vlan_name) { $active_vlans[$i]["vlan_id"] = $vlan_id; $active_vlans[$i]["vlan_name"] = $vlan_name; $active_vlans++; mactrack_debug("VLAN ID = " . $active_vlans[$i]["vlan_id"] . " VLAN Name = " . $active_vlans[$i]["vlan_name"]); $i++; } } if (sizeof($active_vlans)) { /* get the port status information */ $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE); $port_vlan_data = xform_standard_indexed_data(".1.3.6.1.4.1.1991.1.1.3.2.6.1.1", $device); $i = 0; $j = 0; $port_array = array(); if (sizeof($port_results)) { foreach ($port_results as $port_result) { $ifIndex = $port_result["port_number"]; $ifType = $ifTypes[$ifIndex]; $ifName = $ifNames[$ifIndex]; $portName = $ifName; $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"]; mactrack_debug("Port Number = " . $ifIndex . " Type = " . $ifType . " Name = " . $ifName . " Port Name = " . $portName . " Trunk Status = " . $portTrunkStatus); /* only output legitimate end user ports */ if ($ifType >= 6 && $ifType <= 9) { $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["port_number"]]; $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]]; $port_array[$i]["port_number"] = @$port_result["port_number"]; $port_array[$i]["port_name"] = $portName; $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]); $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++; } $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; if (sizeof($active_ports_array)) { foreach ($active_ports_array as $port_info) { $port_info = mactrack_strip_alpha($port_info); $ifInterfaces[$indexes[$i]]["ifType"] = mactrack_strip_alpha($ifInterfaces[$indexes[$i]]["ifType"]); mactrack_debug($ifInterfaces[$indexes[$i]]["ifType"]); if ($ifInterfaces[$indexes[$i]]["ifType"] >= 6 && $ifInterfaces[$indexes[$i]]["ifType"] <= 9 || $ifInterfaces[$indexes[$i]]["ifType"] == 71) { if ($port_info == 1) { $device["ports_active"]++; } $i++; } } } $device["ports_active"] = $device["ports_active"] - $device["ports_trunk"]; /* get IP Addresses */ $gateway = cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.4.1.1991.1.1.2.1.10.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"]); mactrack_debug("INFO: GATEWAY: " . $gateway); /* 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 devices 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_base_dot1qTpFdbEntry_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; if (sizeof($active_ports_array)) { foreach ($active_ports_array as $port_info) { $port_info = mactrack_strip_alpha($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 "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.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 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)) { $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"]; $i++; } } } } mactrack_debug("Port number information collected."); /* map mac address */ /* only continue if there were user ports defined */ if (sizeof($new_port_key_array)) { /* get the bridges active MAC addresses */ $port_macs = xform_stripped_oid(".1.3.6.1.2.1.17.7.1.2.2.1.1", $device, $snmp_readstring); if (sizeof($port_macs)) { foreach ($port_macs as $key => $port_mac) { $port_macs[$key] = xform_mac_address($port_mac); } } if (sizeof($new_port_key_array)) { 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)) { $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_norbay_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.2272.1.3.2.1.2", $device); $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.2272.1.3.3.1.4", $device); $device["vlans_total"] = sizeof($vlan_ids); mactrack_debug("There are " . sizeof($vlan_ids) . " 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); if (sizeof($ifIndexes)) { foreach ($ifIndexes as $ifIndex) { $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex]; $ifInterfaces[$ifIndex]["vlannum"] = @$vlan_ids[$ifIndex]; $ifInterfaces[$ifIndex]["ifOperStatus"] = mactrack_strip_alpha($ifInterfaces[$ifIndex]["ifOperStatus"]); if ($ifInterfaces[$ifIndex]["ifType"] == 6) { $device["ports_total"]++; } if ($ifInterfaces[$ifIndex]["ifOperStatus"] == 1) { $device["ports_active"]++; } if ($ifInterfaces[$ifIndex]["trunkPortState"] == 2) { mactrack_debug("Found Port Trunk: " . $ifInterfaces[$ifIndex]["ifDescr"]); $device["ports_trunk"]++; } } } mactrack_debug("ifInterfaces assembly complete."); $i = 0; if (sizeof($vlan_ids)) { foreach ($vlan_ids as $vlan_id => $vlan_name) { $active_vlans[$i]["vlan_id"] = $vlan_id; $active_vlans[$i]["vlan_name"] = $vlan_name; $active_vlans++; $i++; } } if (sizeof($active_vlans)) { $i = 0; /* get the port status information */ $port_results = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", "", FALSE); $port_vlan_data = xform_dot1q_vlan_associations($device); $i = 0; $j = 0; $port_array = array(); if (sizeof($port_results)) { foreach ($port_results as $port_result) { $ifIndex = $port_result["port_number"]; $ifType = $ifInterfaces[$ifIndex]["ifType"]; $ifName = $ifInterfaces[$ifIndex]["ifName"]; $ifDescr = $ifInterfaces[$ifIndex]["ifDescr"]; if (strpos($ifDescr, "BayStack") === false) { $portName = preg_replace("/ifc[0-9]+ /", "", $ifName); } else { $portName = preg_replace("/BayStack - /", "", $ifDescr); } $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"]; /* only output legitamate end user ports */ if ($ifType == 6 && $portTrunkStatus == 1) { $port_array[$i]["vlan_id"] = @$port_vlan_data[$port_result["key"]]; $port_array[$i]["vlan_name"] = @$vlan_ids[$port_array[$i]["vlan_id"]]; $port_array[$i]["port_number"] = @$port_result["port_number"]; $port_array[$i]["port_name"] = $portName; $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]); $device["ports_active"]++; foreach ($port_array as $test_array) { if ($test_array["port_name"] == $portName && $test_array["mac_address"] != $port_result["mac_address"]) { $port_array[$i]["port_number"] = @$port_result["port_number"] . " - *"; } } mactrack_debug("VLAN: " . $port_array[$i]["vlan_id"] . ", " . "NAME: " . $port_array[$i]["vlan_name"] . ", " . "PORT: " . $ifInterfaces[$ifIndex]["ifName"] . ", " . "NUMBER: " . $port_array[$i]["port_number"] . ", " . "NAME: " . $port_array[$i]["port_name"] . ", " . "MAC: " . $port_array[$i]["mac_address"]); $i++; } $j++; } } /* display completion message */ print "INFO: HOST: " . $device["hostname"] . ", TYPE: " . trim(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; }