$found = 1; echo '<li class="nav-header">Ports found: ' . count($results) . '</li>'; foreach ($results as $result) { humanize_port($result); echo '<li class="divider" style="margin: 0px;"></li>'; echo '<li>'; echo '<a href="' . generate_port_url($result) . '">'; $name = rewrite_ifname($result['ifDescr']); if (strlen($name) > 35) { $name = substr($name, 0, 35) . "..."; } $description = $result['ifAlias']; if (strlen($description) > 80) { $description = substr($description, 0, 80) . "..."; } $type = rewrite_iftype($result['ifType']); if ($description) { $type .= ' | '; } echo '<dl style="border-left: 10px solid ' . $result['table_tab_colour'] . '; " class="dl-horizontal dl-search"> <dt style="padding-left: 10px; text-align: center;"><img src="images/icons/' . $result['icon'] . '.png" /></dt> <dd><strong>' . highlight_search(htmlentities($name)) . ' <small>' . $result['hostname'] . '<br />' . $type . highlight_search(htmlentities($description)) . '</small></strong></dd> </dl>'; } echo "</a></li>"; } /// SEARCH SENSORS $results = dbFetchRows("SELECT * FROM `sensors`\n LEFT JOIN `devices` ON `sensors`.`device_id` = `devices`.`device_id`\n WHERE `sensor_descr` LIKE '%{$queryString}%' {$query_permitted_device}\n ORDER BY `sensor_descr` LIMIT 8"); if (count($results)) { $found = 1; echo '<li class="nav-header">Sensors found: ' . count($results) . '</li>';
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage webui * @copyright (C) 2006-2015 Adam Armstrong * */ /// FIXME. Ohh noo.. someone FIX this huuuuuuge page foreach ($ports as $port) { # if (is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } $speed = humanspeed($port['ifSpeed']); $type = rewrite_iftype($port['ifType']); $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); if ($port['in_errors'] > 0 || $port['out_errors'] > 0) { $error_img = generate_port_link($port, "<img src='images/16/chart_curve_error.png' alt='接口错误' border=0>", '错误'); } else { $error_img = ''; } humanize_port($port); $graph_type = "port_" . $vars['graph']; $graph_array = array(); if ($_SESSION['widescreen']) { if ($_SESSION['big_graphs']) { $width_div = 585; $width = 507; $height = 149;
//$state_insert = $port['state']; //$state_insert['port_id'] = $port['port_id']; //$insert = dbInsert($state_insert, 'ports-state'); //if ($insert === FALSE) { print_error("Certain MEMORY DB error for table 'ports-state'."); } //else { print_debug("STATE inserted port_id=".$port['port_id']); } //unset($state_insert); } else { //$updated = dbUpdate($port['state'], 'ports-state', '`port_id` = ?', array($port['port_id'])); //print_debug("STATE updated rows=$updated"); } } // Add table row $table_row = array(); $table_row[] = $port['ifIndex']; $table_row[] = $port['port_label_short']; $table_row[] = rewrite_iftype($port['ifType']); $table_row[] = formatRates($port['ifSpeed']); $table_row[] = formatRates($port['stats']['ifInBits_rate']); $table_row[] = formatRates($port['stats']['ifOutBits_rate']); $table_row[] = formatStorage($port['stats']['ifInOctets_diff']); $table_row[] = formatStorage($port['stats']['ifOutOctets_diff']); $table_row[] = format_si($port['stats']['ifInUcastPkts_rate']); $table_row[] = format_si($port['stats']['ifOutUcastPkts_rate']); $table_row[] = $port['port_64bit'] ? "%gY%w" : "%rN%w"; $table_rows[] = $table_row; unset($table_row); // End Update Database } elseif ($port['disabled'] != "1") { print_message("Port Deleted."); // Port missing from SNMP cache. if (isset($port['ifIndex']) && $port['deleted'] != "1") {
} foreach (array('ifType', 'ifSpeed', 'port_descr_type') as $entry) { $query = "SELECT `{$entry}` FROM `ports`"; $query .= " LEFT JOIN `devices` USING (`device_id`)"; if (isset($where_array[$entry])) { $tmp = $where_array[$entry]; unset($where_array[$entry]); $query .= ' WHERE 1 ' . implode('', $where_array); $where_array[$entry] = $tmp; } else { $query .= $where; } $query .= " AND `{$entry}` != ''" . $cache['where']['ports_permitted'] . " GROUP BY `{$entry}` ORDER BY `{$entry}`"; foreach (dbFetchRows($query) as $data) { if ($entry == "ifType") { $form_items[$entry][$data['ifType']] = rewrite_iftype($data['ifType']) . ' (' . $data['ifType'] . ')'; } elseif ($entry == "ifSpeed") { $form_items[$entry][$data[$entry]] = formatRates($data[$entry]); } else { $form_items[$entry][$data[$entry]] = nicecase($data[$entry]); } } } $form_items['devices'] = generate_form_values('device'); // Always all devices asort($form_items['ifType']); $form_items['sort'] = array('device' => 'Device', 'port' => 'Port', 'speed' => 'Speed', 'traffic' => 'Traffic In+Out', 'traffic_in' => 'Traffic In', 'traffic_out' => 'Traffic Out', 'traffic_perc' => 'Traffic Percentage In+Out', 'traffic_perc_in' => 'Traffic Percentage In', 'traffic_perc_out' => 'Traffic Percentage Out', 'packets' => 'Packets In+Out', 'packets_in' => 'Packets In', 'packets_out' => 'Packets Out', 'errors' => 'Errors', 'media' => 'Media', 'descr' => 'Description'); $form = array('type' => 'rows', 'space' => '10px', 'submit_by_key' => TRUE, 'url' => generate_url($vars)); // First row $form['row'][0]['device_id'] = array('type' => 'multiselect', 'name' => 'Device', 'value' => $vars['device_id'], 'width' => '100%', 'values' => $form_items['devices']); $form['row'][0]['ifDescr'] = array('type' => 'text', 'name' => 'Port Name', 'value' => $vars['ifDescr'], 'width' => '100%', 'placeholder' => TRUE);
function humanize_port(&$port) { global $config, $cache; // Exit if already humanized if ($port['humanized']) { return; } // Process port data to make it pretty for printing. EVOLUTION, BITCHES. // Lots of hacky shit will end up here with if (os); // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts) if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) { $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']]; } else { $device = device_by_id_cache($port['device_id']); } $os = $device['os']; $port['human_speed'] = humanspeed($port['ifSpeed']); $port['human_type'] = rewrite_iftype($port['ifType']); $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); $port['human_mac'] = format_mac($port['ifPhysAddress']); // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2 // Note, only for 'calix' os now if ($os == 'calix') { unset($config['os'][$os]['ifname']); $version_parts = explode('.', $device['version']); if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) { $config['os'][$os]['ifname'] = 1; } } if (isset($config['os'][$os]['ifname'])) { if ($port['ifName'] == "") { $port['label'] = $port['ifDescr']; } else { $port['label'] = $port['ifName']; } } elseif (isset($config['os'][$os]['ifalias'])) { $port['label'] = $port['ifAlias']; } else { $port['label'] = $port['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $port['label'] .= ' ' . $port['ifIndex']; } else { $port['label'] = $port['ifDescr']; } } // Set entity variables for use by code which uses entities $port['entity_name'] = $port['label']; $port['entity_shortname'] = $port['label']; $port['entity_descr'] = $port['ifAlias']; if ($device['os'] == "speedtouch") { list($port['label']) = explode("thomson", $port['label']); } $port['table_tab_colour'] = "#aaaaaa"; $port['row_class'] = ""; // Default $port['admin_status'] = $port['ifAdminStatus']; if ($port['ifAdminStatus'] == "down") { $port['admin_status'] = 'disabled'; $port['row_class'] = "warning"; $port['icon'] = 'port-disabled'; } elseif ($port['ifAdminStatus'] == "up") { $port['admin_status'] = 'enabled'; switch ($port['ifOperStatus']) { case 'down': $port['table_tab_colour'] = "#cc0000"; $port['row_class'] = "error"; $port['icon'] = 'port-down'; break; case 'monitoring': // This is monitoring ([e|r]span) ports $port['table_tab_colour'] = "#008C00"; $port['row_class'] = "success"; $port['icon'] = 'port-up'; break; case 'lowerLayerDown': $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-down'; break; case 'testing': $port['table_tab_colour'] = "#85004b"; $port['row_class'] = "info"; $port['icon'] = 'port-ignored'; break; case 'up': $port['table_tab_colour'] = "#194B7F"; $port['row_class'] = ""; $port['icon'] = 'port-up'; break; } } // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it. if ($device['status'] == '0') { $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-ignored'; } $port['in_rate'] = $port['ifInOctets_rate'] * 8; $port['out_rate'] = $port['ifOutOctets_rate'] * 8; // Colour in bps based on speed if > 50, else by UI convention. $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100); if ($port['in_rate'] == 0) { $port['bps_in_style'] = ''; } elseif ($in_perc < '50') { $port['bps_in_style'] = 'color: #008C00;'; } else { $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; '; } // Colour out bps based on speed if > 50, else by UI convention. $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100); if ($port['out_rate'] == 0) { $port['bps_out_style'] = ''; } elseif ($out_perc < '50') { $port['bps_out_style'] = 'color: #394182;'; } else { $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; '; } // Colour in and out pps based on UI convention $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;'; $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;'; $port['humanized'] = TRUE; /// Set this so we can check it later. }
function is_port_valid($port, $device) { global $config; $valid = TRUE; if (isset($port['ifOperStatus']) && strlen($port['ifOperStatus']) && !in_array($port['ifOperStatus'], array('testing', 'dormant', 'down', 'lowerLayerDown', 'unknown', 'up', 'monitoring'))) { // See http://tools.cisco.com/Support/SNMP/do/BrowseOID.do?objectInput=ifOperStatus $valid = FALSE; print_debug("ignored (by ifOperStatus = notPresent or invalid value)."); } if ($valid && !isset($port['ifType'])) { /* Some devices (ie D-Link) report ports without any usefull info, example: [74] => Array ( [ifName] => po22 [ifInMulticastPkts] => 0 [ifInBroadcastPkts] => 0 [ifOutMulticastPkts] => 0 [ifOutBroadcastPkts] => 0 [ifLinkUpDownTrapEnable] => enabled [ifHighSpeed] => 0 [ifPromiscuousMode] => false [ifConnectorPresent] => false [ifAlias] => po22 [ifCounterDiscontinuityTime] => 0:0:00:00.00 ) */ $valid = FALSE; print_debug("ignored (by empty ifType)."); } if ($port['ifDescr'] === '' && $config['os'][$device['os']]['ifType_ifDescr'] && $port['ifIndex']) { // This happen on some liebert UPS devices $type = rewrite_iftype($port['ifType']); if ($type) { $port['ifDescr'] = $type . ' ' . $port['ifIndex']; } } $if = $config['os'][$device['os']]['ifname'] ? $port['ifName'] : $port['ifDescr']; if ($valid && is_array($config['bad_if'])) { foreach ($config['bad_if'] as $bi) { if (stripos($if, $bi) !== FALSE) { $valid = FALSE; print_debug("ignored (by descr): {$if} [ {$bi} ]"); break; } } } if ($valid && is_array($config['bad_ifalias_regexp'])) { foreach ($config['bad_ifalias_regexp'] as $bi) { if (preg_match($bi . 'i', $port['ifAlias'])) { $valid = FALSE; print_debug("ignored (by ifAlias): " . $port['ifAlias'] . " [ {$bi} ]"); break; } } } if ($valid && is_array($config['bad_if_regexp'])) { foreach ($config['bad_if_regexp'] as $bi) { if (preg_match($bi . 'i', $if)) { $valid = FALSE; print_debug("ignored (by regexp): {$if} [ {$bi} ]"); break; } } } if ($valid && is_array($config['bad_iftype'])) { foreach ($config['bad_iftype'] as $bi) { if (strpos($port['ifType'], $bi) !== FALSE) { $valid = FALSE; print_debug("ignored (by ifType): " . $port['ifType'] . " [ {$bi} ]"); break; } } } if ($valid && empty($port['ifDescr']) && empty($port['ifName'])) { $valid = FALSE; print_debug("ignored (by empty ifDescr and ifName)."); } if ($valid && $device['os'] == 'catos' && strstr($if, "vlan")) { $valid = FALSE; } return $valid; }
function humanize_port(&$port) { global $config, $cache; // Exit if already humanized if ($port['humanized']) { return; } // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts) if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) { $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']]; } else { $device = device_by_id_cache($port['device_id']); } // Workaround for devices/ports who long time not updated and have empty port_label if (empty($port['port_label']) || strlen($port['port_label_base'] . $port['port_label_num']) == 0) { process_port_label($port, $device); } // Set humanised values for use in UI $port['human_speed'] = humanspeed($port['ifSpeed']); $port['human_type'] = rewrite_iftype($port['ifType']); $port['html_class'] = port_html_class($port['ifOperStatus'], $port['ifAdminStatus'], $port['encrypted']); $port['human_mac'] = format_mac($port['ifPhysAddress']); // Set entity_* values for code which expects them. $port['entity_name'] = $port['port_label']; $port['entity_shortname'] = $port['port_label_short']; $port['entity_descr'] = $port['ifAlias']; $port['table_tab_colour'] = "#aaaaaa"; $port['row_class'] = ""; $port['icon'] = 'port-ignored'; // Default $port['admin_status'] = $port['ifAdminStatus']; if ($port['ifAdminStatus'] == "down") { $port['admin_status'] = 'disabled'; $port['row_class'] = "disabled"; $port['icon'] = 'port-disabled'; } elseif ($port['ifAdminStatus'] == "up") { $port['admin_status'] = 'enabled'; switch ($port['ifOperStatus']) { case 'up': $port['table_tab_colour'] = "#194B7F"; $port['row_class'] = "up"; $port['icon'] = 'port-up'; break; case 'monitoring': // This is monitoring ([e|r]span) ports $port['table_tab_colour'] = "#008C00"; $port['row_class'] = "success"; $port['icon'] = 'port-up'; break; case 'down': $port['table_tab_colour'] = "#cc0000"; $port['row_class'] = "error"; $port['icon'] = 'port-down'; break; case 'lowerLayerDown': $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-down'; break; case 'testing': case 'unknown': case 'dormant': case 'notPresent': $port['table_tab_colour'] = "#85004b"; $port['row_class'] = "info"; $port['icon'] = 'port-ignored'; break; } } // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it. if ($device['status'] == '0') { $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-ignored'; } $port['in_rate'] = $port['ifInOctets_rate'] * 8; $port['out_rate'] = $port['ifOutOctets_rate'] * 8; // Colour in bps based on speed if > 50, else by UI convention. if ($port['ifSpeed'] > 0) { $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100); $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100); } else { // exclude division by zero error $in_perc = 0; $out_perc = 0; } if ($port['in_rate'] == 0) { $port['bps_in_style'] = ''; } elseif ($in_perc < '50') { $port['bps_in_style'] = 'color: #008C00;'; } else { $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; '; } // Colour out bps based on speed if > 50, else by UI convention. if ($port['out_rate'] == 0) { $port['bps_out_style'] = ''; } elseif ($out_perc < '50') { $port['bps_out_style'] = 'color: #394182;'; } else { $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; '; } // Colour in and out pps based on UI convention $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;'; $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;'; $port['humanized'] = TRUE; /// Set this so we can check it later. }