* @package observium * @subpackage ajax * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $config['install_dir'] = "../.."; include_once "../../includes/sql-config.inc.php"; include $config['html_dir'] . "/includes/functions.inc.php"; include $config['html_dir'] . "/includes/authenticate.inc.php"; if (!$_SESSION['authenticated']) { echo "unauthenticated"; exit; } if (is_numeric($_GET['device_id']) && device_permitted($_GET['device_id'])) { foreach (dbFetchRows("SELECT `port_id`,`port_label_short`,`ifAlias`,`ifDescr`,`ifName` FROM `ports` WHERE `device_id` = ? AND deleted = 0 ORDER BY ifIndex", array($_GET['device_id'])) as $interface) { $descr = array(); if (empty($interface['port_label_short'])) { $device = device_by_id_cache($interface['port_id']); process_port_label($interface, $device); } $descr[] = $interface['port_label_short']; if ($interface['ifAlias']) { // second part $descr[] = $interface['ifAlias']; } $string = addslashes(implode(" - ", $descr)); echo "obj.options[obj.options.length] = new Option('" . $string . "','" . $interface['port_id'] . "');\n"; } } // EOF
foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($device['device_id'])) as $port) { $ports_db[$port['ifIndex']] = $port; $ports_db_l[$port['ifIndex']] = $port['port_id']; } print_cli(count($ports_db) . " ports" . PHP_EOL); print_cli_data_field("Discovering ports", 3); $table_rows = array(); // New interface detection foreach ($port_stats as $ifIndex => $port) { $port['ifIndex'] = $ifIndex; $table_row = array($ifIndex, truncate($port['ifDescr'], 30), $port['ifName'], truncate($port['ifAlias'], 20), $port['ifType'], $port['ifOperStatus']); // Check the port against our filters. if (is_port_valid($port, $device)) { $table_row[] = '%gno%n'; if (!is_array($ports_db[$ifIndex])) { process_port_label($port, $device); // Process ifDescr if needed $table_row[1] = truncate($port['ifDescr'], 30); $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifAlias' => $port['ifAlias'], 'ifDescr' => $port['ifDescr'], 'ifName' => $port['ifName'], 'ifType' => $port['ifType']), 'ports'); $ports_db[$ifIndex] = dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device['device_id'], $ifIndex)); echo " " . $port['ifName'] . "(" . $ifIndex . ")[" . $ports_db[$ifIndex]['port_id'] . "]"; } else { if ($ports_db[$ifIndex]['deleted'] == "1") { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports_db[$ifIndex]['port_id'])); log_event("Interface DELETED mark removed", $device, 'port', $ports_db[$ifIndex]); $ports_db[$ifIndex]['deleted'] = "0"; echo "U"; } else { echo "."; } }
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. }