diff --git a/lib/mactrack_cisco.php b/lib/mactrack_cisco.php index 83e23a06..d324fad4 100644 --- a/lib/mactrack_cisco.php +++ b/lib/mactrack_cisco.php @@ -106,12 +106,12 @@ function get_catalyst_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $high /* calculate the number of end user ports */ if (cacti_sizeof($portTrunking)) { - foreach ($portTrunking as $portTrunk) { - if ($portTrunk == 1) { - $device['ports_trunk']++; + foreach ($portTrunking as $portTrunk) { + if ($portTrunk == 1) { + $device['ports_trunk']++; + } } } - } /* build VLAN array from results */ $i = 0; @@ -301,6 +301,16 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $device['vlans_total'] = cacti_sizeof($vlan_ids) - 4; mactrack_debug('There are ' . (cacti_sizeof($vlan_ids)-4) . ' VLANS.'); + if (cacti_sizeof($vlan_names) == 0) { + cacti_log('No VLANs Name found: ' . $device['device_name']); + return $device; + } + + if (cacti_sizeof($vlan_trunkstatus) == 0) { + cacti_log('No VLANs Trunk Status found: ' . $device['device_name']); + return $device; + } + /* 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 (cacti_sizeof($portVoiceVLANs) > 0) { @@ -485,6 +495,7 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $portNumber = (isset($ifInterfaces[$ifIndex]['ifName']) ? $ifInterfaces[$ifIndex]['ifName'] : ''); $portName = (isset($ifInterfaces[$ifIndex]['ifAlias']) ? $ifInterfaces[$ifIndex]['ifAlias'] : ''); $portTrunk = (isset($portTrunking[$ifName]) ? $portTrunking[$ifName] : ''); + $portTrunkStatus = (isset($ifInterfaces[$ifIndex]['trunkPortState']) ? $ifInterfaces[$ifIndex]['trunkPortState'] : ''); if ($vvlans) { $vVlanID = (isset($portVoiceVLANs[$ifIndex]) ? $portVoiceVLANs[$ifIndex] : ''); @@ -492,12 +503,14 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $vVlanID = -1; } - $portTrunkStatus = (isset($ifInterfaces[$ifIndex]['trunkPortState']) ? $ifInterfaces[$ifIndex]['trunkPortState'] : ''); - /* only output legitimate end user ports */ + /* ifType: 6 = ethernetCsmacd + 53 = propVirtual + 161 = ieee8023adLag + */ if ($ifType == 6 || $ifType == 53 || $ifType == 161) { if (($portTrunkStatus == '2') || - (empty($portTrunkStatus)) || + //(empty($portTrunkStatus)) || (in_array($portNumber, $scan_trunk_port)) || (($vVlanID > 0) && ($vVlanID <= 1000))) { $port_array[$i]['vlan_id'] = $active_vlan['vlan_id']; @@ -509,8 +522,11 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $port_array[$i]['portTrunkStatus'] = $portTrunkStatus; $i++; - mactrack_debug('VLAN: ' . $active_vlan['vlan_id'] . ', ' . + mactrack_debug('HOST: ' . $device['hostname'] . ', ' . + 'VLAN: ' . $active_vlan['vlan_id'] . ', ' . 'NAME: ' . $active_vlan['vlan_name'] . ', ' . + 'TRUNK: ' . $portTrunkStatus . ', ' . + 'TYPE: ' . $ifType . ', ' . 'PORT: ' . $portNumber . ', ' . 'NAME: ' . $portName . ', ' . 'MAC: ' . $port_result['mac_address']); diff --git a/lib/mactrack_functions.php b/lib/mactrack_functions.php index b327a1c5..2aed0328 100644 --- a/lib/mactrack_functions.php +++ b/lib/mactrack_functions.php @@ -1352,9 +1352,10 @@ function get_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_r $brPortIfType = @$ifInterfaces[$port_key['port_number']]['ifType']; } - if (($brPortIfType >= 6) && - ($brPortIfType <= 9) && - (!isset($ifInterfaces[$brPortIfIndex]['portLink']))) { + if ((($brPortIfType >= 6 && $brPortIfType <= 9) || + $brPortIfType == 53 || $brPortIfType == 161) && + (!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'; @@ -2309,7 +2310,7 @@ function db_store_device_port_results(&$device, $port_array, $scan_date) { if ($port_value['port_number'] <> 'NOT USER' && $port_value['mac_address'] <> 'NOT USER' && $port_value['mac_address'] != '') { $mac_authorized = db_check_auth($port_value['mac_address']); - mactrack_debug('MAC Address \'' . $port_value['mac_address'] . '\' on device \'' . $device['device_name'] . '\' is ' . ($mac_authorized != '' ? '':'NOT') . ' Authorized'); + mactrack_debug('MAC Address \'' . $port_value['mac_address'] . '\' on device \'' . $device['device_name'] . '\' is ' . ($mac_authorized != '' ? '':'NOT ') . ' Authorized'); if ($mac_authorized != '') { $authorized_mac = 1; @@ -2437,6 +2438,7 @@ function perform_mactrack_db_maint() { ORDER BY partition_ordinal_position', array($database_default)); + /* $time = time(); $now = date('Y-m-d', $time); $format = date('Ymd', $time); @@ -2448,12 +2450,25 @@ function perform_mactrack_db_maint() { $lformat = date('Ymd', $lday_ts); $last_day = db_fetch_row("SELECT TO_DAYS('$lnow') AS today"); $last_day = $last_day['today']; + */ + + $tday_ts = strtotime('Today'); + $tday = date('Y-m-d', $tday_ts); + $tdformat = date('Ymd', $tday_ts); + $cur_day = db_fetch_row("SELECT TO_DAYS('$tday') AS today"); + $cur_day = $cur_day['today']; + + $lday_ts = strtotime('Yesterday'); + $lday = date('Y-m-d', $lday_ts); + $ldformat = date('Ymd', $lday_ts); + $last_day = db_fetch_row("SELECT TO_DAYS('$lday') AS today"); + $last_day = $last_day['today']; mactrack_debug("There are currently '" . cacti_sizeof($number_of_partitions) . "' Mactrack Partitions, We will keep '$days' of them."); - mactrack_debug("The current day is '$cur_day', the last day is '$last_day'"); + mactrack_debug("The current day is '$tday($cur_day)', the last day is '$lday($last_day)'"); if ($cur_day != $last_day) { - set_config_option('mactrack_lastday_timestamp', $time); + //set_config_option('mactrack_lastday_timestamp', $time); //no use if ($lday_ts != '') { cacti_log("MACTRACK: Creating new partition 'd" . $lformat . "'", false, "SYSTEM"); @@ -2463,6 +2478,7 @@ function perform_mactrack_db_maint() { PARTITION dMaxValue VALUES LESS THAN MAXVALUE)"); if ($days > 0) { + /* $user_partitions = cacti_sizeof($number_of_partitions) - 1; if ($user_partitions >= $days) { $i = 0; @@ -2476,12 +2492,35 @@ function perform_mactrack_db_maint() { $mactrack_deleted++; } } + */ + + $old_day = date('Ymd', strtotime("- $days Days")); + $old_partitions = db_fetch_assoc_prepared('SELECT PARTITION_NAME + FROM `information_schema`.`partitions` + WHERE table_schema = ? + AND table_name="mac_track_ports" + AND partition_name < ? + ORDER BY partition_ordinal_position', + array($database_default, 'd' . $old_day)); + + if (cacti_sizeof($old_partitions) > 0) { + foreach ($old_partitions as $old_partition) { + cacti_log("MACTRACK: Removing old partition '" . $old_partition['PARTITION_NAME'] . "'", false, "SYSTEM"); + mactrack_debug("Removing partition '" . $old_partition['PARTITION_NAME'] . "'"); + db_execute("ALTER TABLE mac_track_ports DROP PARTITION " . $old_partition['PARTITION_NAME']); + } + } } } } } } + db_execute_prepared('DELETE FROM mac_track_ips + WHERE scan_date < DATE_FORMAT(CURDATE() - ?,"%Y-%m-%d")', + array(read_config_option('mt_data_retention_ip'))); + db_execute('OPTIMIZE TABLE mac_track_ips'); + db_execute('REPLACE INTO mac_track_scan_dates (SELECT DISTINCT scan_date FROM mac_track_ports)'); diff --git a/mactrack_utilities.php b/mactrack_utilities.php index 58c9536e..cb73b856 100644 --- a/mactrack_utilities.php +++ b/mactrack_utilities.php @@ -110,12 +110,12 @@ function mactrack_display_run_status() { if ($collection_timing != 'disabled') { $seconds_offset = $collection_timing * 60; /* find out if it's time to collect device information */ - $base_start_time = read_config_option('mt_base_time', true); - $database_maint_time = read_config_option('mt_maint_time', true); - $last_run_time = read_config_option('mt_last_run_time', true); - $last_db_maint_time = read_config_option('mt_last_db_maint_time', true); + $base_start_time = read_config_option('mt_base_time', true); + $database_maint_time = read_config_option('mt_maint_time', true); + $last_run_time = read_config_option('mt_last_run_time', true); + $last_db_maint_time = read_config_option('mt_last_db_maint_time', true); $previous_base_start_time = read_config_option('mt_prev_base_time', true); - $previous_db_maint_time = read_config_option('mt_prev_db_maint_time', true); + $previous_db_maint_time = read_config_option('mt_prev_db_maint_time', true); /* see if the user desires a new start time */ if (!empty($previous_base_start_time)) { @@ -125,11 +125,13 @@ function mactrack_display_run_status() { } /* see if the user desires a new db maintenance time */ + /* if (!empty($previous_db_maint_time)) { if ($database_maint_time <> $previous_db_maint_time) { unset($last_db_maint_time); } } + */ /* determine the next start time */ $current_time = strtotime('now'); @@ -150,6 +152,8 @@ function mactrack_display_run_status() { $next_run_time = $last_run_time + $seconds_offset; } + /* determine the next db maintenance time */ + /* if (empty($last_db_maint_time)) { if (strtotime($base_start_time) < $current_time) { $next_db_maint_time = strtotime(date('Y-m-d') . ' ' . $database_maint_time) + 3600*24; @@ -159,6 +163,14 @@ function mactrack_display_run_status() { } else { $next_db_maint_time = $last_db_maint_time + 24*3600; } + */ + + $db_maint_time = strtotime($database_maint_time); + if ($last_db_maint_time < $db_maint_time) { + $next_db_maint_time = $db_maint_time; + } else { + $next_db_maint_time = strtotime('Tomorrow '. $database_maint_time); + } $time_till_next_run = $next_run_time - $current_time; $time_till_next_db_maint = $next_db_maint_time - $current_time; @@ -247,9 +259,13 @@ function applyFilter() { form_alternate_row(); print '