function get_cabletron_switch_ports($site, &$device, $lowPort, $highPort)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $device["vlans_total"] = 0;
    /* 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, FALSE, FALSE);
    $securefast_marker = @cacti_snmp_get($device["hostname"], $device["snmp_readstring"], ".1.3.6.1.4.1.52.4.2.4.2.1.1.1.1.1.1.1", $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("Cabletron securefast marker obtained");
    if (empty($securefast_marker)) {
        get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", TRUE, $lowPort, $highPort);
    } else {
        get_base_sfps_ports($site, $device, $ifInterfaces, "", TRUE, $lowPort, $highPort);
    }
    return $device;
}
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_generic_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 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");
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, FALSE);
    get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", TRUE, $lowPort, $highPort);
    return $device;
}
function get_IOS_dot1dTpFdbEntry_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;
    /* Variables to determine VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.2", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.3.1.1.4", $device);
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.46.1.6.1.1.14", $device);
    $device["vlans_total"] = sizeof($vlan_ids) - 3;
    mactrack_debug("There are " . (sizeof($vlan_ids) - 3) . " 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");
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, TRUE);
    /* get the Voice VLAN information if it exists */
    $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.87.1.4.1.1.37.0", $device);
    if (sizeof($portVoiceVLANs) > 0) {
        $vvlans = TRUE;
    } else {
        $portVoiceVLANs = xform_standard_indexed_data(".1.3.6.1.4.1.9.9.68.1.5.1.1.1", $device);
        if (sizeof($portVoiceVLANs) > 0) {
            $vvlans = TRUE;
        } else {
            $vvlans = FALSE;
        }
    }
    mactrack_debug("Cisco Voice VLAN collection complete");
    if ($vvlans) {
        mactrack_debug("Voice VLANs exist on this device");
    } else {
        mactrack_debug("Voice VLANs do not exist on this device");
    }
    if (sizeof($ifIndexes)) {
        foreach ($ifIndexes as $ifIndex) {
            $ifInterfaces[$ifIndex]["trunkPortState"] = @$vlan_trunkstatus[$ifIndex];
            if ($vvlans) {
                $ifInterfaces[$ifIndex]["vVlanID"] = @$portVoiceVLANs[$ifIndex];
            }
            if ($ifInterfaces[$ifIndex]["ifType"] == 6) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == "1") {
                $device["ports_trunk"]++;
            }
        }
    }
    mactrack_debug("ifInterfaces assembly complete.");
    /* build VLAN array from results */
    $i = 0;
    $j = 0;
    $active_vlans = array();
    if (sizeof($vlan_ids)) {
        foreach ($vlan_ids as $vlan_number => $vlanStatus) {
            $vlanName = $vlan_names[$vlan_number];
            if ($vlanStatus == 1) {
                /* vlan is operatinal */
                switch ($vlan_number) {
                    case "1002":
                    case "1003":
                    case "1004":
                    case "1005":
                        $active_vlan_ports = 0;
                        break;
                    default:
                        if ($device["snmp_version"] < "3") {
                            $snmp_readstring = $device["snmp_readstring"] . "@" . $vlan_number;
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.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"]);
                        } else {
                            $active_vlan_ports = cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.1.2.0", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $vlan_number, $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]);
                        }
                        if (!is_numeric($active_vlan_ports) || $active_vlan_ports < 0) {
                            $active_vlan_ports = 0;
                        }
                        mactrack_debug("VLAN Analysis for VLAN: " . $vlan_number . "/" . $vlanName . " is complete. ACTIVE PORTS: " . $active_vlan_ports);
                        if ($active_vlan_ports > 0) {
                            /* does the vlan have active ports on it */
                            $active_vlans[$j]["vlan_id"] = $vlan_number;
                            $active_vlans[$j]["vlan_name"] = $vlanName;
                            $active_vlans[$j]["active_ports"] = $active_vlan_ports;
                            $active_vlans++;
                            $j++;
                        }
                }
            }
            $i++;
        }
    }
    if (sizeof($active_vlans)) {
        $i = 0;
        /* get the port status information */
        foreach ($active_vlans as $active_vlan) {
            if ($device["snmp_version"] < "3") {
                $snmp_readstring = $device["snmp_readstring"] . "@" . $active_vlan["vlan_id"];
            } else {
                $snmp_readstring = "cisco@" . $active_vlan["vlan_id"];
            }
            mactrack_debug("Processing has begun for VLAN: " . $active_vlan["vlan_id"]);
            if ($highPort == 0) {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE);
            } else {
                $active_vlans[$i]["port_results"] = get_base_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, $snmp_readstring, FALSE, $lowPort, $highPort);
            }
            /* get bridge port mappings */
            /* get bridge port to ifIndex mappings */
            mactrack_debug("Bridge port information about to be collected.");
            mactrack_debug("VLAN_ID: " . $active_vlans[$i]["vlan_id"] . ", VLAN_NAME: " . $active_vlans[$i]["vlan_name"] . ", ACTIVE PORTS: " . sizeof($active_vlans[$i]["port_results"]));
            if (sizeof($active_vlans[$i]["port_results"]) > 0) {
                $brPorttoifIndexes[$i] = xform_standard_indexed_data(".1.3.6.1.2.1.17.1.4.1.2", $device, $snmp_readstring);
                mactrack_debug("Bridge port information collection complete.");
            }
            $i++;
        }
        $i = 0;
        $j = 0;
        $port_array = array();
        mactrack_debug("Final cross check's now being performed.");
        if (sizeof($active_vlans)) {
            foreach ($active_vlans as $active_vlan) {
                if (sizeof($active_vlan["port_results"])) {
                    foreach ($active_vlan["port_results"] as $port_result) {
                        $ifIndex = @$brPorttoifIndexes[$j][$port_result["port_number"]];
                        $ifType = @$ifInterfaces[$ifIndex]["ifType"];
                        $portNumber = @$ifInterfaces[$ifIndex]["ifName"];
                        $portName = @$ifInterfaces[$ifIndex]["ifAlias"];
                        $portTrunk = @$portTrunking[$ifName];
                        if ($vvlans) {
                            $vVlanID = @$portVoiceVLANs[$ifIndex];
                        } else {
                            $vVlanID = -1;
                        }
                        $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                        /* only output legitamate end user ports */
                        if ($ifType == 6) {
                            if ($portTrunkStatus == "2" || empty($portTrunkStatus) || $vVlanID > 0 && $vVlanID <= 1000) {
                                $port_array[$i]["vlan_id"] = $active_vlan["vlan_id"];
                                $port_array[$i]["vlan_name"] = $active_vlan["vlan_name"];
                                $port_array[$i]["port_number"] = $portNumber;
                                $port_array[$i]["port_name"] = $portName;
                                $port_array[$i]["mac_address"] = xform_mac_address($port_result["mac_address"]);
                                $device["ports_active"]++;
                                $i++;
                                mactrack_debug("VLAN: " . $active_vlan["vlan_id"] . ", " . "NAME: " . $active_vlan["vlan_name"] . ", " . "PORT: " . $portNumber . ", " . "NAME: " . $portName . ", " . "MAC: " . $port_result["mac_address"]);
                            }
                        }
                    }
                }
                $j++;
            }
        }
        /* display completion message */
        print "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", TOTAL PORTS: " . $device["ports_total"] . ", ACTIVE PORTS: " . $device["ports_active"] . "\n";
        $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 "\nINFO: HOST: " . $device["hostname"] . ", TYPE: " . substr($device["snmp_sysDescr"], 0, 40) . ", No active end devices on this device.\n";
        $device["snmp_status"] = HOST_UP;
        $device["last_runmessage"] = "Data collection completed ok.  No active end devices on this 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;
}
Exemple #6
0
function get_procurve_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;
    $active_vlans = array();
    /* get VLAN information */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.4.1.2", $device);
    /* get VLAN Trunk status */
    $vlan_trunkstatus = xform_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.8.1.1.1", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    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 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];
            if ($ifInterfaces[$ifIndex]["ifType"] >= 6 && $ifInterfaces[$ifIndex]["ifType"] <= 9) {
                $device["ports_total"]++;
            }
            if ($ifInterfaces[$ifIndex]["trunkPortState"] == 3) {
                $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_standard_indexed_data(".1.3.6.1.4.1.11.2.14.11.5.1.3.1.1.5.1.2", $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"];
                $portName = $ifName;
                $portTrunkStatus = @$ifInterfaces[$ifIndex]["trunkPortState"];
                /* only output legitamate 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 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_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;
}