Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
    }
}
Пример #4
0
function get_extreme_switch_ports($site, &$device, $lowPort = 0, $highPort = 0, $extremeware = false)
{
    global $debug, $scan_date;
    /* initialize port counters */
    $device["ports_total"] = 0;
    $device["ports_active"] = 0;
    $device["ports_trunk"] = 0;
    $device["vlans_total"] = 0;
    $device["macs_active"] = 0;
    /* get VLAN information
    	   VLAN index
    	   .1.3.6.1.4.1.1916.1.2.1.2.1.1
    	   EXTREME-VLAN-MIB::extremeVlanIfIndex.<vlanid> = index
    	   VLAN name
    	   .1.3.6.1.4.1.1916.1.2.1.2.1.2
    	   EXTREME-VLAN-MIB::extremeVlanIfDescr.<vlanid> = description
    	   VLAN ID
    	   .1.3.6.1.4.1.1916.1.2.1.2.1.10
    	   EXTREME-VLAN-MIB::extremeVlanIfVlanId.<vlanid> = tag id
    	 */
    $vlan_ids = xform_standard_indexed_data(".1.3.6.1.4.1.1916.1.2.1.2.1.10", $device);
    $vlan_names = xform_standard_indexed_data(".1.3.6.1.4.1.1916.1.2.1.2.1.2", $device);
    $device["vlans_total"] = sizeof($vlan_ids);
    mactrack_debug("There are " . sizeof($vlan_ids) . " VLANS.");
    /* get the ifIndexes for the device
    	   .1.3.6.1.2.1.2.2.1.1
    	   RFC1213-MIB::ifIndex.<index> = index
    	   .1.3.6.1.2.1.2.2.1.2
    	   RFC1213-MIB::ifDescr.<index> = description
    	   .1.3.6.1.2.1.2.2.1.3
    	   RFC1213-MIB::ifType.<index> = type (6=ether)
    	   .1.3.6.1.2.1.31.1.1.1.1
    	   IF-MIB::ifName.<index> = name
    	   .1.3.6.1.2.1.31.1.1.1.18
    	   IF-MIB::ifAlias.<index> = alias
    	 */
    $ifInterfaces = build_InterfacesTable($device, $ifIndexes, TRUE, TRUE);
    mactrack_debug("ifInterfaces assembly complete.");
    /* get VLAN details */
    $i = 0;
    foreach ($vlan_ids as $vlan_index => $vlan_id) {
        $active_vlans[$i]["vlan_id"] = $vlan_id;
        $active_vlans[$i]["vlan_name"] = $vlan_names[$vlan_index];
        $active_vlans++;
        mactrack_debug("VLAN ID = " . $active_vlans[$i]["vlan_id"] . " VLAN Name = " . $active_vlans[$i]["vlan_name"]);
        $i++;
    }
    if (sizeof($active_vlans) > 0) {
        /* get the port status information */
        /* get port_number and MAC addr */
        /*extremeXOS
        		  addr mac
        		  .1.3.6.1.4.1.1916.1.16.4.1.1
        		  EXTREME-BASE-MIB::extremeFdb.4.1.1.<MAC>.<vlanid>= hex MAC
        		  index du vlan ?
        		  .1.3.6.1.4.1.1916.1.16.4.1.2
        		  EXTREME-BASE-MIB::extremeFdb.4.1.2.<MAC>.<vlanid>=vlanid
        		  index du port
        		  .1.3.6.1.4.1.1916.1.16.4.1.3
        		  EXTREME-BASE-MIB::extremeFdb.4.1.3.<MAC>.<vlanid>=port id
        		  status
        		  .1.3.6.1.4.1.1916.1.16.4.1.4
        		  EXTREME-BASE-MIB::extremeFdb.4.1.4.<MAC>.<vlanid>= 3 learned
        
        		  extremeware
        		  .1.3.6.1.4.1.1916.1.16.1.1.3
        		  EXTREME-FDB-MIB::extremeFdbMacFdbMacAddress.<vlanid>.<id> = mac
        		  .1.3.6.1.4.1.1916.1.16.1.1.4
        		  EXTREME-FDB-MIB::extremeFdbMacFdbPortIfIndex.<vlanid>.<id> = index du port
        		  .1.3.6.1.4.1.1916.1.16.1.1.5
        		  EXTREME-FDB-MIB::extremeFdbMacFdbStatus.<vlanid>.<id> = 3 learned
        		 */
        if ($extremeware) {
            $mac_addr_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.1.1.3", $device);
            $mac_port_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.1.1.4", $device);
            $mac_status_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.1.1.5", $device);
        } else {
            $mac_addr_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.4.1.1", $device);
            $mac_vlan_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.4.1.2", $device);
            $mac_port_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.4.1.3", $device);
            $mac_status_list = xform_stripped_oid(".1.3.6.1.4.1.1916.1.16.4.1.4", $device);
        }
        $port_array = array();
        foreach ($mac_addr_list as $mac_key => $mac_addr) {
            /* check if mac addr is 'learned'  or 'mgnt' */
            if (isset($mac_status_list[$mac_key]) and $mac_status_list[$mac_key] == "3" || $mac_status_list[$mac_key] == "5") {
                $ifIndex = $mac_port_list[$mac_key];
                $ifType = $ifInterfaces[$ifIndex]["ifType"];
                //$ifType = $ifTypes[$ifIndex];
                /* only output legitimate end user ports */
                if ($ifType >= 6 && $ifType <= 9) {
                    if ($extremeware) {
                        $vlanid = substr($mac_key, 0, strpos($mac_key, "."));
                        $new_port_array["vlan_id"] = $vlan_ids[$vlanid];
                        $new_port_array["vlan_name"] = $vlan_names[$vlanid];
                    } else {
                        $new_port_array["vlan_id"] = $vlan_ids[$mac_vlan_list[$mac_key]];
                        $new_port_array["vlan_name"] = $vlan_names[$mac_vlan_list[$mac_key]];
                    }
                    //$new_port_array["port_number"]  = $ifIndex;
                    //$new_port_array["port_name"]    = $ifInterfaces[$ifIndex]["ifName"];
                    $new_port_array["port_number"] = $ifInterfaces[$ifIndex]["ifName"];
                    $new_port_array["port_name"] = $ifInterfaces[$ifIndex]["ifAlias"];
                    $new_port_array["mac_address"] = xform_mac_address($mac_addr_list[$mac_key]);
                    $ifInterfaces[$ifIndex]["Used"] = 1;
                    $port_array[] = $new_port_array;
                    mactrack_debug("VLAN: " . $new_port_array["vlan_id"] . ", " . "NAME: " . $new_port_array["vlan_name"] . ", " . "PORT: " . $ifIndex . ", " . "NAME: " . $new_port_array["port_name"] . ", " . "MAC: " . $new_port_array["mac_address"]);
                }
            }
        }
        $device["ports_total"] = sizeof($ifInterfaces);
        $device["ports_active"] = 0;
        foreach ($ifInterfaces as $interface) {
            if (isset($interface["Used"])) {
                $device["ports_active"]++;
            }
        }
        /* 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;
}
Пример #5
0
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;
}
Пример #6
0
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_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;
    }
}
Пример #8
0
function get_base_sfps_ports($site, &$device, &$ifInterfaces, $snmp_readstring, $store_to_db, $lowPort, $highPort)
{
    global $debug, $scan_date;
    /* initialize variables */
    $port_number = 0;
    $ports_active = 0;
    $ports_total = 0;
    /* 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);
    /* get the ignore ports list */
    $ignore_ports = port_list_to_array($device["ignorePorts"]);
    $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) {
                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;
    }
    /* now obtain securefast port information */
    $sfps_A_ports = xform_indexed_data(".1.3.6.1.4.1.52.4.2.4.2.2.3.6.1.1.6", $device, 3);
    $sfps_A_mac_addresses = xform_indexed_data(".1.3.6.1.4.1.52.4.2.4.2.2.3.6.1.1.8", $device, 3);
    $sfps_A_keys = array_keys($sfps_A_ports);
    $sfps_A_size = sizeof($sfps_A_ports);
    $j = 0;
    $i = 0;
    while ($j < $sfps_A_size) {
        $port_number = $sfps_A_ports[$sfps_A_keys[$j]];
        $mac_address = $sfps_A_mac_addresses[$sfps_A_keys[$j]];
        if ($port_number >= $lowPort && $port_number <= $highPort) {
            if (!in_array($port_number, $ignore_ports)) {
                $temp_port_A_array[$i]["port_number"] = $port_number;
                $temp_port_A_array[$i]["mac_address"] = xform_mac_address($mac_address);
                $i++;
            }
        }
        $j++;
    }
    $j = 0;
    $port_array = array();
    for ($i = 0; $i < sizeof($temp_port_A_array); $i++) {
        $port_array[$temp_port_A_array[$i]["port_number"]]["vlan_id"] = "N/A";
        $port_array[$temp_port_A_array[$i]["port_number"]]["vlan_name"] = "N/A";
        $port_array[$temp_port_A_array[$i]["port_number"]]["port_name"] = "N/A";
        $port_array[$temp_port_A_array[$i]["port_number"]]["port_number"] = $temp_port_A_array[$i]["port_number"];
        $port_array[$temp_port_A_array[$i]["port_number"]]["mac_address"] = $temp_port_A_array[$i]["mac_address"];
    }
    if ($store_to_db) {
        if (sizeof($port_array) > 0) {
            $device["last_runmessage"] = "Data collection completed ok";
            $device["macs_active"] = sizeof($port_array);
            db_store_device_port_results($device, $port_array, $scan_date);
        } else {
            $device["last_runmessage"] = "WARNING: Poller did not find active ports on this device.";
        }
        if (!$debug) {
            print " - Complete\n";
        }
    } else {
        return $port_array;
    }
}
Пример #9
0
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;
    }
}
Пример #10
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;
}
Пример #11
0
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;
}
Пример #12
0
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;
    }
}