示例#1
0
function get_dlink_l2_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");
    /* 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.");
    foreach ($ifIndexes as $ifIndex) {
        $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
        $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
        $ifInterfaces[$ifIndex]["ifType"] = $ifTypes[$ifIndex];
        $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
    }
    mactrack_debug("ifInterfaces assembly complete.");
    get_dlink_l2_dot1dTpFdbEntry_ports($site, $device, $ifInterfaces, "", TRUE, $lowPort, $highPort);
    return $device;
    mactrack_debug("ppp------>>finish function get_dlink_l2_switch_ports for dev=: " . " dev=" . $device["hostname"]);
}
示例#2
0
function get_linux_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");
    /* 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.2.2.1.2", $device);
    mactrack_debug("ifNames data collection complete.");
    foreach ($ifNames as $ifkey => $value) {
        if (substr_count($value, ".") > 0) {
            $ifVlan[$ifkey] = substr($value, strpos($value, ".") + 1);
        } else {
            $ifVlan[$ifkey] = "N/A";
        }
    }
    /* 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.");
    foreach ($ifIndexes as $ifIndex) {
        $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
        $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
        $ifInterfaces[$ifIndex]["ifType"] = convert_port_state_data($ifTypes[$ifIndex]);
        $ifInterfaces[$ifIndex]["vlan_id"] = $ifVlan[$ifIndex];
        //$ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
    }
    mactrack_debug("ifInterfaces assembly complete.");
    get_linux_dot1dTpFdbEntry_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;
}
示例#4
0
function build_InterfacesTable(&$device, &$ifIndexes, $getLinkPorts = FALSE, $getAlias = FALSE)
{
    global $cnn_id;
    /* initialize the interfaces array */
    $ifInterfaces = array();
    /* 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. '" . sizeof($ifIndexes) . "' rows found!");
    $ifTypes = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.3", $device);
    if (sizeof($ifTypes)) {
        foreach ($ifTypes as $key => $value) {
            if (!is_numeric($value)) {
                $parts = explode("(", $value);
                $piece = $parts[1];
                $ifTypes[$key] = str_replace(")", "", trim($piece));
            }
        }
    }
    mactrack_debug("ifTypes data collection complete. '" . sizeof($ifTypes) . "' rows found!");
    $ifNames = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.1", $device);
    mactrack_debug("ifNames data collection complete. '" . sizeof($ifNames) . "' rows found!");
    /* get ports names through use of ifAlias */
    if ($getAlias) {
        $ifAliases = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.18", $device);
        mactrack_debug("ifAlias data collection complete. '" . sizeof($ifAliases) . "' rows found!");
    }
    /* get ports that happen to be link ports */
    if ($getLinkPorts) {
        $link_ports = get_link_port_status($device);
        mactrack_debug("ipAddrTable scanning for link ports data collection complete. '" . sizeof($link_ports) . "' rows found!");
    }
    /* required only for interfaces table */
    $db_data = db_fetch_assoc("SELECT * FROM mac_track_interfaces WHERE device_id='" . $device["device_id"] . "' ORDER BY ifIndex");
    if (sizeof($db_data)) {
        foreach ($db_data as $interface) {
            $db_interface[$interface["ifIndex"]] = $interface;
        }
    }
    /* mark all interfaces as not present */
    db_execute("UPDATE mac_track_interfaces SET present=0 WHERE device_id=" . $device["device_id"]);
    $insert_prefix = "INSERT INTO mac_track_interfaces (site_id, device_id, sysUptime, ifIndex, ifType, ifName, ifAlias, linkPort, vlan_id," . " vlan_name, vlan_trunk_status, ifSpeed, ifHighSpeed, ifDuplex, " . " ifDescr, ifMtu, ifPhysAddress, ifAdminStatus, ifOperStatus, ifLastChange, " . " ifInOctets, ifOutOctets, ifHCInOctets, ifHCOutOctets, ifInNUcastPkts, ifOutNUcastPkts, ifInUcastPkts, ifOutUcastPkts, " . " ifInDiscards, ifInErrors, ifInUnknownProtos, ifOutDiscards, ifOutErrors, " . " int_ifInOctets, int_ifOutOctets, int_ifHCInOctets, int_ifHCOutOctets, int_ifInNUcastPkts, int_ifOutNUcastPkts, int_ifInUcastPkts, int_ifOutUcastPkts, " . " int_ifInDiscards, int_ifInErrors, int_ifInUnknownProtos, int_ifOutDiscards, int_ifOutErrors, int_discards_present, int_errors_present, " . " last_down_time, last_up_time, stateChanges, present) VALUES ";
    $insert_suffix = " ON DUPLICATE KEY UPDATE sysUptime=VALUES(sysUptime), ifType=VALUES(ifType), ifName=VALUES(ifName), ifAlias=VALUES(ifAlias), linkPort=VALUES(linkPort)," . " vlan_id=VALUES(vlan_id), vlan_name=VALUES(vlan_name), vlan_trunk_status=VALUES(vlan_trunk_status)," . " ifSpeed=VALUES(ifSpeed), ifHighSpeed=VALUES(ifHighSpeed), ifDuplex=VALUES(ifDuplex), ifDescr=VALUES(ifDescr), ifMtu=VALUES(ifMtu), ifPhysAddress=VALUES(ifPhysAddress), ifAdminStatus=VALUES(ifAdminStatus)," . " ifOperStatus=VALUES(ifOperStatus), ifLastChange=VALUES(ifLastChange), " . " ifInOctets=VALUES(ifInOctets), ifOutOctets=VALUES(ifOutOctets), ifHCInOctets=VALUES(ifHCInOctets), ifHCOutOctets=VALUES(ifHCOutOctets), " . " ifInNUcastPkts=VALUES(ifInNUcastPkts), ifOutNUcastPkts=VALUES(ifOutNUcastPkts), ifInUcastPkts=VALUES(ifInUcastPkts), ifOutUcastPkts=VALUES(ifOutUcastPkts), " . " ifInDiscards=VALUES(ifInDiscards), ifInErrors=VALUES(ifInErrors)," . " ifInUnknownProtos=VALUES(ifInUnknownProtos), ifOutDiscards=VALUES(ifOutDiscards), ifOutErrors=VALUES(ifOutErrors)," . " int_ifInOctets=VALUES(int_ifInOctets), int_ifOutOctets=VALUES(int_ifOutOctets), int_ifHCInOctets=VALUES(int_ifHCInOctets), int_ifHCOutOctets=VALUES(int_ifHCOutOctets), " . " int_ifInNUcastPkts=VALUES(int_ifInNUcastPkts), int_ifOutNUcastPkts=VALUES(int_ifOutNUcastPkts), int_ifInUcastPkts=VALUES(int_ifInUcastPkts), int_ifOutUcastPkts=VALUES(int_ifOutUcastPkts), " . " int_ifInDiscards=VALUES(int_ifInDiscards), int_ifInErrors=VALUES(int_ifInErrors)," . " int_ifInUnknownProtos=VALUES(int_ifInUnknownProtos), int_ifOutDiscards=VALUES(int_ifOutDiscards)," . " int_ifOutErrors=VALUES(int_ifOutErrors), " . " int_discards_present=VALUES(int_discards_present), int_errors_present=VALUES(int_errors_present)," . " last_down_time=VALUES(last_down_time), last_up_time=VALUES(last_up_time)," . " stateChanges=VALUES(stateChanges), present='1'";
    $insert_vals = "";
    $ifSpeed = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.5", $device);
    mactrack_debug("ifSpeed data collection complete. '" . sizeof($ifSpeed) . "' rows found!");
    $ifHighSpeed = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.15", $device);
    mactrack_debug("ifHighSpeed data collection complete. '" . sizeof($ifHighSpeed) . "' rows found!");
    $ifDuplex = xform_standard_indexed_data(".1.3.6.1.2.1.10.7.2.1.19", $device);
    mactrack_debug("ifDuplex data collection complete. '" . sizeof($ifDuplex) . "' rows found!");
    $ifDescr = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.2", $device);
    mactrack_debug("ifDescr data collection complete. '" . sizeof($ifDescr) . "' rows found!");
    $ifMtu = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.4", $device);
    mactrack_debug("ifMtu data collection complete. '" . sizeof($ifMtu) . "' rows found!");
    $ifPhysAddress = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.6", $device);
    mactrack_debug("ifPhysAddress data collection complete. '" . sizeof($ifPhysAddress) . "' rows found!");
    $ifAdminStatus = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.7", $device);
    if (sizeof($ifAdminStatus)) {
        foreach ($ifAdminStatus as $key => $value) {
            if (substr_count(strtolower($value), "up") || $value == "1") {
                $ifAdminStatus[$key] = 1;
            } else {
                $ifAdminStatus[$key] = 0;
            }
        }
    }
    mactrack_debug("ifAdminStatus data collection complete. '" . sizeof($ifAdminStatus) . "' rows found!");
    $ifOperStatus = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.8", $device);
    if (sizeof($ifOperStatus)) {
        foreach ($ifOperStatus as $key => $value) {
            if (substr_count(strtolower($value), "up") || $value == "1") {
                $ifOperStatus[$key] = 1;
            } else {
                $ifOperStatus[$key] = 0;
            }
        }
    }
    mactrack_debug("ifOperStatus data collection complete. '" . sizeof($ifOperStatus) . "' rows found!");
    $ifLastChange = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.9", $device);
    mactrack_debug("ifLastChange data collection complete. '" . sizeof($ifLastChange) . "' rows found!");
    /* get timing for rate information */
    $prev_octets_time = strtotime($device["last_rundate"]);
    $cur_octets_time = time();
    if ($prev_octets_time == 0) {
        $divisor = FALSE;
    } else {
        $divisor = $cur_octets_time - $prev_octets_time;
    }
    /* if the device is snmpv2 use high speed and don't bother with the low speed stuff */
    $ifInOctets = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.10", $device);
    mactrack_debug("ifInOctets data collection complete. '" . sizeof($ifInOctets) . "' rows found!");
    $ifOutOctets = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.16", $device);
    mactrack_debug("ifOutOctets data collection complete. '" . sizeof($ifOutOctets) . "' rows found!");
    if ($device["snmp_version"] > 1) {
        $ifHCInOctets = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.6", $device);
        mactrack_debug("ifHCInOctets data collection complete. '" . sizeof($ifHCInOctets) . "' rows found!");
        $ifHCOutOctets = xform_standard_indexed_data(".1.3.6.1.2.1.31.1.1.1.10", $device);
        mactrack_debug("ifHCOutOctets data collection complete. '" . sizeof($ifHCOutOctets) . "' rows found!");
    }
    $ifInNUcastPkts = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.12", $device);
    mactrack_debug("ifInNUcastPkts data collection complete. '" . sizeof($ifInNUcastPkts) . "' rows found!");
    $ifOutNUcastPkts = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.18", $device);
    mactrack_debug("ifOutNUcastPkts data collection complete. '" . sizeof($ifOutNUcastPkts) . "' rows found!");
    $ifInUcastPkts = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.11", $device);
    mactrack_debug("ifInUcastPkts data collection complete. '" . sizeof($ifInUcastPkts) . "' rows found!");
    $ifOutUcastPkts = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.17", $device);
    mactrack_debug("ifOutUcastPkts data collection complete. '" . sizeof($ifOutUcastPkts) . "' rows found!");
    /* get information on error conditions */
    $ifInDiscards = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.13", $device);
    mactrack_debug("ifInDiscards data collection complete. '" . sizeof($ifInDiscards) . "' rows found!");
    $ifInErrors = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.14", $device);
    mactrack_debug("ifInErrors data collection complete. '" . sizeof($ifInErrors) . "' rows found!");
    $ifInUnknownProtos = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.15", $device);
    mactrack_debug("ifInUnknownProtos data collection complete. '" . sizeof($ifInUnknownProtos) . "' rows found!");
    $ifOutDiscards = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.19", $device);
    mactrack_debug("ifOutDiscards data collection complete. '" . sizeof($ifOutDiscards) . "' rows found!");
    $ifOutErrors = xform_standard_indexed_data(".1.3.6.1.2.1.2.2.1.20", $device);
    mactrack_debug("ifOutErrors data collection complete. '" . sizeof($ifOutErrors) . "' rows found!");
    $vlan_id = "";
    $vlan_name = "";
    $vlan_trunk = "";
    $i = 0;
    $sysUpTime = (int) $device["snmp_sysUptime"];
    $frecuency = (int) read_config_option("mt_collection_timing", TRUE) * 60;
    foreach ($ifIndexes as $ifIndex) {
        $ifInterfaces[$ifIndex]["ifIndex"] = $ifIndex;
        $ifInterfaces[$ifIndex]["ifName"] = @$ifNames[$ifIndex];
        $ifInterfaces[$ifIndex]["ifType"] = @$ifTypes[$ifIndex];
        if ($getLinkPorts) {
            $ifInterfaces[$ifIndex]["linkPort"] = @$link_ports[$ifIndex];
            $linkPort = @$link_ports[$ifIndex];
        } else {
            $linkPort = 0;
        }
        if ($getAlias && sizeof($ifAliases)) {
            $ifInterfaces[$ifIndex]["ifAlias"] = @$ifAliases[$ifIndex];
            $ifAlias = @$ifAliases[$ifIndex];
        } else {
            $ifAlias = "";
        }
        /* update the last up/down status */
        if (!isset($db_interface[$ifIndex]["ifOperStatus"])) {
            if ($ifOperStatus[$ifIndex] == 1) {
                $last_up_time = date("Y-m-d H:i:s");
                $stateChanges = 0;
                $seconds = $sysUpTime - $ifLastChange[$ifIndex];
                $seconds /= 100;
                $seconds = '- ' . round($seconds) . ' seconds';
                $last_down_time = date('Y-m-d H:i:s', strtotime($seconds));
            } else {
                $last_down_time = date("Y-m-d H:i:s");
                $stateChanges = 0;
                $seconds = $sysUpTime - $ifLastChange[$ifIndex];
                $seconds /= 100;
                $seconds = '- ' . round($seconds) . ' seconds';
                $last_up_time = date('Y-m-d H:i:s', strtotime($seconds));
            }
        } else {
            $last_up_time = $db_interface[$ifIndex]["last_up_time"];
            $last_down_time = $db_interface[$ifIndex]["last_down_time"];
            $stateChanges = $db_interface[$ifIndex]["stateChanges"];
            if ($db_interface[$ifIndex]["ifOperStatus"] == 0) {
                /* interface previously not up */
                if ($ifOperStatus[$ifIndex] == 1) {
                    /* the interface just went up, mark the time */
                    $last_up_time = date("Y-m-d H:i:s");
                    $stateChanges += 1;
                    /* if the interface has never been marked down before, make it the current time */
                    if ($db_interface[$ifIndex]["last_down_time"] == '0000-00-00 00:00:00') {
                        $last_down_time = '0000-00-00 00:00:00';
                    }
                } else {
                    /* if the interface has never been down, make the current time */
                    $last_down_time = date("Y-m-d H:i:s");
                    /* if the interface stayed down, set the last up time if not set before */
                    if ($db_interface[$ifIndex]["last_up_time"] == '0000-00-00 00:00:00') {
                        $last_up_time = '0000-00-00 00:00:00';
                    }
                    /* if the interface has gone up and down since the last scan */
                    if ($sysUpTime > $frecuency * 100 && $sysUpTime - $ifLastChange[$ifIndex] < $frecuency * 100) {
                        $seconds = $sysUpTime - $ifLastChange[$ifIndex];
                        $seconds /= 100;
                        $seconds = '- ' . round($seconds) . ' seconds';
                        $last_up_time = date('Y-m-d H:i:s', strtotime($seconds));
                    }
                }
            } else {
                if ($ifOperStatus[$ifIndex] == 0) {
                    /* the interface just went down, mark the time */
                    $last_down_time = date("Y-m-d H:i:s");
                    $stateChanges += 1;
                    /* if the interface has never been up before, mark it the current time */
                    if ($db_interface[$ifIndex]["last_up_time"] == '0000-00-00 00:00:00') {
                        $last_up_time = '0000-00-00 00:00:00';
                    }
                } else {
                    $last_up_time = date("Y-m-d H:i:s");
                    if ($db_interface[$ifIndex]["last_down_time"] == '0000-00-00 00:00:00') {
                        $last_down_time = '0000-00-00 00:00:00';
                    }
                    /* if the interface has gone down and up since the last scan */
                    if ($sysUpTime > $frecuency * 100 && $sysUpTime - $ifLastChange[$ifIndex] < $frecuency * 100) {
                        $seconds = $sysUpTime - $ifLastChange[$ifIndex];
                        $seconds /= 100;
                        $seconds = '- ' . round($seconds) . ' seconds';
                        $last_down_time = date('Y-m-d H:i:s', strtotime($seconds));
                    }
                }
            }
        }
        /* do the in octets */
        $int_ifInOctets = get_link_int_value("ifInOctets", $ifIndex, $ifInOctets, $db_interface, $divisor, "traffic");
        /* do the out octets */
        $int_ifOutOctets = get_link_int_value("ifOutOctets", $ifIndex, $ifOutOctets, $db_interface, $divisor, "traffic");
        if ($device["snmp_version"] > 1) {
            /* do the in octets */
            $int_ifHCInOctets = get_link_int_value("ifHCInOctets", $ifIndex, $ifHCInOctets, $db_interface, $divisor, "traffic", "64");
            /* do the out octets */
            $int_ifHCOutOctets = get_link_int_value("ifHCOutOctets", $ifIndex, $ifHCOutOctets, $db_interface, $divisor, "traffic", "64");
        }
        /* accomodate values in high speed octets for interfaces that don't support 64 bit */
        if (isset($ifInOctets[$ifIndex])) {
            if (!isset($ifHCInOctets[$ifIndex])) {
                $ifHCInOctets[$ifIndex] = $ifInOctets[$ifIndex];
                $int_ifHCInOctets = $int_ifInOctets;
            }
        }
        if (isset($ifOutOctets[$ifIndex])) {
            if (!isset($ifHCOutOctets[$ifIndex])) {
                $ifHCOutOctets[$ifIndex] = $ifOutOctets[$ifIndex];
                $int_ifHCOutOctets = $int_ifOutOctets;
            }
        }
        $int_ifInNUcastPkts = get_link_int_value("ifInNUcastPkts", $ifIndex, $ifInNUcastPkts, $db_interface, $divisor, "traffic");
        $int_ifOutNUcastPkts = get_link_int_value("ifOutNUcastPkts", $ifIndex, $ifOutNUcastPkts, $db_interface, $divisor, "traffic");
        $int_ifInUcastPkts = get_link_int_value("ifInUcastPkts", $ifIndex, $ifInUcastPkts, $db_interface, $divisor, "traffic");
        $int_ifOutUcastPkts = get_link_int_value("ifOutUcastPkts", $ifIndex, $ifOutUcastPkts, $db_interface, $divisor, "traffic");
        /* see if in error's have been increasing */
        $int_ifInErrors = get_link_int_value("ifInErrors", $ifIndex, $ifInErrors, $db_interface, $divisor, "errors");
        /* see if out error's have been increasing */
        $int_ifOutErrors = get_link_int_value("ifOutErrors", $ifIndex, $ifOutErrors, $db_interface, $divisor, "errors");
        if ($int_ifInErrors > 0 || $int_ifOutErrors > 0) {
            $int_errors_present = TRUE;
        } else {
            $int_errors_present = FALSE;
        }
        /* see if in discards's have been increasing */
        $int_ifInDiscards = get_link_int_value("ifInDiscards", $ifIndex, $ifInDiscards, $db_interface, $divisor, "errors");
        /* see if out discards's have been increasing */
        $int_ifOutDiscards = get_link_int_value("ifOutDiscards", $ifIndex, $ifOutDiscards, $db_interface, $divisor, "errors");
        if ($int_ifInDiscards > 0 || $int_ifOutDiscards > 0) {
            $int_discards_present = TRUE;
        } else {
            $int_discards_present = FALSE;
        }
        /* see if in discards's have been increasing */
        $int_ifInUnknownProtos = get_link_int_value("ifInUnknownProtos", $ifIndex, $ifInUnknownProtos, $db_interface, $divisor, "errors");
        /* format the update packet */
        if ($i == 0) {
            $insert_vals .= " ";
        } else {
            $insert_vals .= ",";
        }
        $mac_address = @xform_mac_address($ifPhysAddress[$ifIndex]);
        $insert_vals .= "('" . @$device["site_id"] . "', '" . @$device["device_id"] . "', '" . @$device["snmp_sysUptime"] . "', '" . @$ifIndex . "', '" . @$ifTypes[$ifIndex] . "', " . @$cnn_id->qstr(@$ifNames[$ifIndex]) . ", " . @$cnn_id->qstr($ifAlias) . ", '" . @$linkPort . "', '" . @$vlan_id . "', " . @$cnn_id->qstr(@$vlan_name) . ", '" . @$vlan_trunk . "', '" . @$ifSpeed[$ifIndex] . "', '" . @$ifHighSpeed[$ifIndex] . "', '" . @$ifDuplex[$ifIndex] . "', " . @$cnn_id->qstr(@$ifDescr[$ifIndex]) . ", '" . @$ifMtu[$ifIndex] . "', '" . $mac_address . "', '" . @$ifAdminStatus[$ifIndex] . "', '" . @$ifOperStatus[$ifIndex] . "', '" . @$ifLastChange[$ifIndex] . "', '" . @$ifInOctets[$ifIndex] . "', '" . @$ifOutOctets[$ifIndex] . "', '" . @$ifHCInOctets[$ifIndex] . "', '" . @$ifHCOutOctets[$ifIndex] . "', '" . @$ifInNUcastPkts[$ifIndex] . "', '" . @$ifOutNUcastPkts[$ifIndex] . "', '" . @$ifInUcastPkts[$ifIndex] . "', '" . @$ifOutUcastPkts[$ifIndex] . "', '" . @$ifInDiscards[$ifIndex] . "', '" . @$ifInErrors[$ifIndex] . "', '" . @$ifInUnknownProtos[$ifIndex] . "', '" . @$ifOutDiscards[$ifIndex] . "', '" . @$ifOutErrors[$ifIndex] . "', '" . @$int_ifInOctets . "', '" . @$int_ifOutOctets . "', '" . @$int_ifHCInOctets . "', '" . @$int_ifHCOutOctets . "', '" . @$int_ifInNUcastPkts . "', '" . @$int_ifOutNUcastPkts . "', '" . @$int_ifInUcastPkts . "', '" . @$int_ifOutUcastPkts . "', '" . @$int_ifInDiscards . "', '" . @$int_ifInErrors . "', '" . @$int_ifInUnknownProtos . "', '" . @$int_ifOutDiscards . "', '" . @$int_ifOutErrors . "', '" . @$int_discards_present . "', '" . $int_errors_present . "', '" . $last_down_time . "', '" . $last_up_time . "', '" . $stateChanges . "', '" . "1')";
        $i++;
    }
    mactrack_debug("ifInterfaces assembly complete: " . strlen($insert_prefix . $insert_vals . $insert_suffix));
    if (strlen($insert_vals)) {
        /* add/update records in the database */
        db_execute($insert_prefix . $insert_vals . $insert_suffix);
        /* remove all obsolete records from the database */
        db_execute("DELETE FROM mac_track_interfaces WHERE present=0 AND device_id=" . $device["device_id"]);
        /* set the percent utilized fields, you can't do this for vlans */
        db_execute("UPDATE mac_track_interfaces\r\n\t\t\tSET inBound=(int_ifHCInOctets*8)/(ifHighSpeed*10000), outBound=(int_ifHCOutOctets*8)/(ifHighSpeed*10000)\r\n\t\t\tWHERE ifHighSpeed>0 AND ifName NOT LIKE 'Vl%' AND device_id=" . $device["device_id"]);
        mactrack_debug("Adding IfInterfaces Records");
    }
    if ($device["host_id"] > 0) {
        mactrack_find_host_graphs($device["device_id"], $device["host_id"]);
    }
    return $ifInterfaces;
}
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;
}
示例#6
0
function get_3Com_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_readstring = "", $store_to_db = TRUE, $lowPort = 1, $highPort = 9999)
{
    global $debug, $scan_date;
    mactrack_debug("Start get_3Com_base_dot1dTpFdbEntry_ports");
    /* 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);
    /* get the consol port */
    $link_ports = get_link_port_status($device);
    $i = 0;
    foreach ($active_ports_array as $port_info) {
        if ($ifInterfaces[$indexes[$i]]["ifType"] == 6 && $ifInterfaces[$indexes[$i]]["linkPort"] != 1) {
            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 */
        //$device["ignorePorts"] = $device["ignorePorts"].":Port1/50";
        $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("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;
    }
}