function get_port_stats_by_port_hostname() { // This will return port stats based on a devices hostname and ifName global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); $ifName = urldecode($router['ifname']); $port = dbFetchRow('SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?', array($device_id, $ifName)); $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); $port['in_perc'] = @round($port['in_rate'] / $port['ifSpeed'] * 100); $port['out_perc'] = @round($port['in_rate'] / $port['ifSpeed'] * 100); $port['in_pps'] = format_bi($port['ifInUcastPkts_rate']); $port['out_pps'] = format_bi($port['ifOutUcastPkts_rate']); $output = array('status' => 'ok', 'port' => $port); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
} elseif ($vars['view'] == "quick" || $vars['view'] == "accurate") { echo "<h3>Billed Ports</h3>"; // Collected Earlier foreach ($ports as $port) { echo generate_port_link($port) . " on " . generate_device_link($port) . "<br />"; } echo "<h3>Bill Summary</h3>"; if ($bill_data['bill_type'] == "quota") { // The Customer is billed based on a pre-paid quota with overage in xB echo "<h4>Quota Bill</h4>"; $percent = round($total_data / $bill_data['bill_quota'] * 100, 2); $unit = "MB"; $total_data = round($total_data, 2); echo "Billing Period from " . $fromtext . " to " . $totext; echo "<br />Transferred " . format_bytes_billing($total_data) . " of " . format_bytes_billing($bill_data['bill_quota']) . " (" . $percent . "%)"; echo "<br />Average rate " . formatRates($rate_average); $background = get_percentage_colours($percent); echo "<p>" . print_percentage_bar(350, 20, $perc, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']) . "</p>"; $type = "&ave=yes"; } elseif ($bill_data['bill_type'] == "cdr") { // The customer is billed based on a CDR with 95th%ile overage echo "<h4>CDR / 95th Bill</h4>"; $unit = "kbps"; $cdr = $bill_data['bill_cdr']; $rate_95th = round($rate_95th, 2); $percent = round($rate_95th / $cdr * 100, 2); $type = "&95th=yes"; echo "<strong>" . $fromtext . " to " . $totext . "</strong>\n <br />Measured " . format_si($rate_95th) . "bps of " . format_si($cdr) . "bps (" . $percent . "%) @ 95th %ile"; $background = get_percentage_colours($percent); echo "<p>" . print_percentage_bar(350, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']) . "</p>"; # echo("<p>Billing Period : " . $fromtext . " to " . $totext . "<br />
function listBillPorts($bill_id) { $res = ""; $res .= "<table>"; $res .= " <tr>"; $res .= " <th>Device</th>"; $res .= " <th>Hardeware</th>"; $res .= " <th>Interface/Port</th>"; $res .= " <th>Speed</th>"; //$res .= " <th>Description</th>"; //$res .= " <th>Notes</th>"; $res .= " </tr>"; foreach (dbFetchRows("SELECT * FROM `bill_ports` as b, `ports` as p, `devices` as d WHERE b.bill_id = ? AND p.port_id = b.port_id AND d.device_id = p.device_id", array($bill_id)) as $row) { if (bill_permitted($bill_id)) { $device['name'] = $row['sysName']; //$device['port'] = $row['ifName']." (".$row['ifDescr'].")"; $device['port'] = $row['ifName']; $device['speed'] = formatRates($row['ifSpeed']); $device['hw'] = $row['hardware']; $device['descr'] = $row['port_descr_descr']; $device['notes'] = $row['port_descr_notres']; $res .= " <tr>"; $res .= " <td>" . $device['name'] . "</td>"; $res .= " <td>" . $device['hw'] . "</td>"; $res .= " <td>" . $device['port'] . "</td>"; $res .= " <td>" . $device['speed'] . "</td>"; //$res .= " <td>".$device['descr']."</td>"; //$res .= " <td>".$device['notes']."</td>"; $res .= " </tr>"; } } $res .= "</table>"; return $res; }
// Hide tooltip for empty echo '<br /><span data-rel="' . $rel . '" class="small ' . $class . '" data-tooltip="<strong class=\'small ' . $class . '\'>' . $port['ifVlan'] . ' [' . $vlan_name . ']</strong>">VLAN ' . $port['ifVlan'] . '</span>'; } else { if ($port['ifVrf']) { $vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", array($port['ifVrf'])); echo '<span class="small text-warning" data-rel="tooltip" data-tooltip="VRF">' . $vrf_name . '</span>'; } } } if ($port_adsl['adslLineCoding']) { echo "</td><td style='width: 150px;'>"; echo $port_adsl['adslLineCoding'] . "/" . rewrite_adslLineType($port_adsl['adslLineType']); echo "<br />"; echo "Sync:" . formatRates($port_adsl['adslAtucChanCurrTxRate']) . "/" . formatRates($port_adsl['adslAturChanCurrTxRate']); echo "<br />"; echo "Max:" . formatRates($port_adsl['adslAtucCurrAttainableRate']) . "/" . formatRates($port_adsl['adslAturCurrAttainableRate']); echo "</td><td style='width: 150px;'>"; echo "Atten:" . $port_adsl['adslAtucCurrAtn'] . "dB/" . $port_adsl['adslAturCurrAtn'] . "dB"; echo "<br />"; echo "SNR:" . $port_adsl['adslAtucCurrSnrMgn'] . "dB/" . $port_adsl['adslAturCurrSnrMgn'] . "dB"; } else { echo "</td><td style='width: 150px;'>"; if ($port['ifType'] && $port['ifType'] != "") { echo "<span class=small>" . $port['human_type'] . "</span>"; } else { echo "-"; } echo "<br />"; if ($ifHardType && $ifHardType != "") { echo "<span class=small>" . $ifHardType . "</span>"; } else {
echo "</span>"; $width = "120"; $height = "40"; $from = $config['time']['day']; echo "</td><td width=135>"; echo formatRates($port['ifInOctets_rate'] * 8) . " <img class='optionicon' src='images/icons/arrow_updown.png' /> " . formatRates($port['ifOutOctets_rate'] * 8); echo "<br />"; $port['graph_type'] = "port_bits"; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&id=" . $port['port_id'] . "&from=" . $from . "&to=" . $config['time']['now'] . "&width=" . $width . "&height=" . $height . "&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']); echo "</td><td width=135>"; echo "" . formatRates($port['adslAturChanCurrTxRate']) . "/" . formatRates($port['adslAtucChanCurrTxRate']); echo "<br />"; $port['graph_type'] = "port_adsl_speed"; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&id=" . $port['port_id'] . "&from=" . $from . "&to=" . $config['time']['now'] . "&width=" . $width . "&height=" . $height . "&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']); echo "</td><td width=135>"; echo "" . formatRates($port['adslAturCurrAttainableRate']) . "/" . formatRates($port['adslAtucCurrAttainableRate']); echo "<br />"; $port['graph_type'] = "port_adsl_attainable"; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&id=" . $port['port_id'] . "&from=" . $from . "&to=" . $config['time']['now'] . "&width=" . $width . "&height=" . $height . "&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']); echo "</td><td width=135>"; echo "" . $port['adslAturCurrAtn'] . "dB/" . $port['adslAtucCurrAtn'] . "dB"; echo "<br />"; $port['graph_type'] = "port_adsl_attenuation"; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&id=" . $port['port_id'] . "&from=" . $from . "&to=" . $config['time']['now'] . "&width=" . $width . "&height=" . $height . "&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']); echo "</td><td width=135>"; echo "" . $port['adslAturCurrSnrMgn'] . "dB/" . $port['adslAtucCurrSnrMgn'] . "dB"; echo "<br />"; $port['graph_type'] = "port_adsl_snr"; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . "&id=" . $port['port_id'] . "&from=" . $from . "&to=" . $config['time']['now'] . "&width=" . $width . "&height=" . $height . "&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $port['graph_type']); echo "</td><td width=135>"; echo "" . $port['adslAturCurrOutputPwr'] . "dBm/" . $port['adslAtucCurrOutputPwr'] . "dBm";
} echo '</tr></table>'; $graph_array = $vars; $graph_array['height'] = "300"; $graph_array['width'] = $graph_width; echo generate_box_close(); $form = array('type' => 'rows', 'space' => '5px', 'submit_by_key' => TRUE, 'url' => 'graphs' . generate_url($vars)); // Datetime Field $form['row'][0]['timestamp'] = array('type' => 'datetime', 'grid' => 10, 'grid_xs' => 10, 'presets' => TRUE, 'min' => '2007-04-03 16:06:59', 'max' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d H:i:s', $vars['from']), 'to' => date('Y-m-d H:i:s', $vars['to'])); $search_grid = 2; if ($type == "port") { if ($subtype == "bits") { $speed_list = array('auto' => 'Autoscale', 'speed' => 'Interface Speed (' . formatRates($port['ifSpeed'], 4, 4) . ')'); foreach ($config['graphs']['ports_scale_list'] as $entry) { $speed = intval(unit_string_to_numeric($entry, 1000)); $speed_list[$entry] = formatRates($speed, 4, 4); } $form['row'][0]['scale'] = array('type' => 'select', 'name' => 'Scale', 'grid' => 2, 'width' => '100%', 'value' => isset($vars['scale']) ? $vars['scale'] : $config['graphs']['ports_scale_default'], 'values' => $speed_list); //reduce timestamp element grid sizes $form['row'][0]['timestamp']['grid'] -= 2; } if (in_array($subtype, array('bits', 'percent', 'upkts', 'pktsize'))) { $form['row'][0]['style'] = array('type' => 'select', 'name' => 'Graph style', 'grid' => 2, 'width' => '100%', 'value' => isset($vars['style']) ? $vars['style'] : $config['graphs']['style'], 'values' => array('default' => 'Default', 'mrtg' => 'MRTG')); //reduce timestamp element grid sizes $form['row'][0]['timestamp']['grid'] -= 1; unset($form['row'][0]['timestamp']['grid_xs']); $search_grid = 1; } } // Update button $form['row'][0]['update'] = array('type' => 'submit', 'grid' => $search_grid, 'grid_xs' => $search_grid > 1 ? $search_grid : 12, 'right' => TRUE);
foreach (dbFetchRows("SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 24", array($bill_id)) as $history) { if (bill_permitted($history['bill_id'])) { unset($class); $datefrom = $history['bill_datefrom']; $dateto = $history['bill_dateto']; $type = $history['bill_type']; $percent = $history['bill_percent']; $dir_95th = $history['dir_95th']; $rate_95th = formatRates($history['rate_95th']); $total_data = format_number($history['traf_total'], $config['billing']['base']); if ($type == "CDR") { $allowed = formatRates($history['bill_allowed']); $used = formatRates($history['rate_95th']); $in = formatRates($history['rate_95th_in']); $out = formatRates($history['rate_95th_out']); $overuse = $history['bill_overuse'] <= 0 ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-important\">" . formatRates($history['bill_overuse']) . "</span>"; $label = "inverse"; } elseif ($type == "Quota") { $allowed = format_number($history['bill_allowed'], $config['billing']['base']); $used = format_number($history['total_data'], $config['billing']['base']); $in = format_number($history['traf_in'], $config['billing']['base']); $out = format_number($history['traf_out'], $config['billing']['base']); $overuse = $history['bill_overuse'] <= 0 ? "<span class=\"badge badge-success\">-</span>" : "<span class=\"badge badge-imprtant\">" . format_number($history['bill_overuse'], $config['billing']['base']) . "B</span>"; $label = "info"; } $total_data = $type == "Quota" ? "<span class=\"badge badge-warning\"><strong>" . $total_data . "</strong></span>" : "<span class=\"badge\">" . $total_data . "</span>"; $rate_95th = $type == "CDR" ? "<span class=\"badge badge-warning\"><strong>" . $rate_95th . "</strong></span>" : "<span class=\"badge\">" . $rate_95th . "</span>"; switch (true) { case $percent >= 90: $perc['BG'] = "danger"; break;
echo "</td><td width=100>"; if ($port_details) { $interface['graph_type'] = "port_bits"; echo generateiflink($interface, "<img src='graph.php?type=port_bits&port=" . $interface['interface_id'] . "&from=" . $day . "&to=" . $now . "&width=100&height=20&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $interface['graph_type']); $interface['graph_type'] = "port_upkts"; echo generateiflink($interface, "<img src='graph.php?type=port_upkts&port=" . $interface['interface_id'] . "&from=" . $day . "&to=" . $now . "&width=100&height=20&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $interface['graph_type']); $interface['graph_type'] = "port_errors"; echo generateiflink($interface, "<img src='graph.php?type=port_errors&port=" . $interface['interface_id'] . "&from=" . $day . "&to=" . $now . "&width=100&height=20&legend=no&bg=" . str_replace("#", "", $row_colour) . "'>", $interface['graph_type']); } echo "</td><td width=120>"; if ($interface['ifOperStatus'] == "up") { $interface['in_rate'] = $interface['ifInOctets_rate'] * 8; $interface['out_rate'] = $interface['ifOutOctets_rate'] * 8; $in_perc = @round($interface['in_rate'] / $interface['ifSpeed'] * 100); $out_perc = @round($interface['in_rate'] / $interface['ifSpeed'] * 100); echo "<img src='images/16/arrow_left.png' align=absmiddle> <span style='color: " . percent_colour($in_perc) . "'>" . formatRates($interface['in_rate']) . "<br />\n <img align=absmiddle src='images/16/arrow_out.png'> <span style='color: " . percent_colour($out_perc) . "'>" . formatRates($interface['out_rate']) . "<br />\n <img src='images/icons/arrow_pps_in.png' align=absmiddle> " . format_bi($interface['ifInUcastPkts_rate']) . "pps</span><br />\n <img src='images/icons/arrow_pps_out.png' align=absmiddle> " . format_bi($interface['ifOutUcastPkts_rate']) . "pps</span>"; } echo "</td><td width=75>"; if ($interface['ifSpeed'] && $interface['ifAlias'] != "") { echo "<span class=box-desc>" . humanspeed($interface['ifSpeed']) . "</span>"; } echo "<br />"; # if($interface[ifDuplex] != unknown) { echo("<span class=box-desc>Duplex " . $interface['ifDuplex'] . "</span>"); } else { echo("-"); } if ($device['os'] == "ios" || $device['os'] == "iosxe") { if ($interface['ifTrunk']) { echo "<span class=box-desc><span class=red>" . $interface['ifTrunk'] . "</span></span>"; } elseif ($interface['ifVlan']) { echo "<span class=box-desc><span class=blue>VLAN " . $interface['ifVlan'] . "</span></span>"; } elseif ($interface['ifVrf']) { $vrf = mysql_fetch_array(mysql_query("SELECT * FROM vrfs WHERE vrf_id = '" . $interface['ifVrf'] . "'")); echo "<span style='color: green;'>" . $vrf['vrf_name'] . "</span>";
if (bill_permitted($history['bill_id'])) { unset($class); $datefrom = $history['bill_datefrom']; $dateto = $history['bill_dateto']; $type = $history['bill_type']; $percent = $history['bill_percent']; $dir_95th = $history['dir_95th']; $rate_95th = formatRates($history['rate_95th']); $total_data = format_number($history['traf_total'], $config['billing']['base']); $background = get_percentage_colours($percent); if ($type == 'CDR') { $allowed = formatRates($history['bill_allowed']); $used = formatRates($history['rate_95th']); $in = formatRates($history['rate_95th_in']); $out = formatRates($history['rate_95th_out']); $overuse = $history['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . formatRates($history['bill_overuse']) . '</span>'; } else { if ($type == 'Quota') { $allowed = format_number($history['bill_allowed'], $config['billing']['base']); $used = format_number($history['total_data'], $config['billing']['base']); $in = format_number($history['traf_in'], $config['billing']['base']); $out = format_number($history['traf_out'], $config['billing']['base']); $overuse = $history['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . format_number($history['bill_overuse'], $config['billing']['base']) . 'B</span>'; } } $total_data = $type == 'Quota' ? '<b>' . $total_data . '</b>' : $total_data; $rate_95th = $type == 'CDR' ? '<b>' . $rate_95th . '</b>' : $rate_95th; $url = generate_url($vars, array('detail' => $history['bill_hist_id'])); echo ' <tr> <td></td>
* * @package observium * @subpackage graphs * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $defs = ' DEF:in_octets=' . $rrd_filename . ':INOCTETS:AVERAGE'; $defs .= ' DEF:out_octets=' . $rrd_filename . ':OUTOCTETS:AVERAGE'; $defs .= ' CDEF:in_bits=in_octets,8,*'; $defs .= ' CDEF:out_bits=out_octets,8,*'; $defs .= ' CDEF:in=in_bits,' . $port['ifSpeed'] . ',/,100,*'; $defs .= ' CDEF:out=out_bits,' . $port['ifSpeed'] . ',/,100,*'; $defs .= ' CDEF:in_max=in'; $defs .= ' CDEF:out_max=out'; $defs .= ' HRULE:100#555:'; $defs .= ' HRULE:-100#555:'; $colour_area_out = '3E629F'; $colour_line_out = '070A64'; $colour_area_in = '72B240'; $colour_line_in = '285B00'; #$colour_area_in_max = 'cc88cc'; #$colour_area_out_max = 'FFefaa'; $graph_max = 0; $scale_max = '100'; $scale_min = '-100'; $unit_text = '% of ' . formatRates($port['ifSpeed'], 4, 4); $args['nototal'] = 1; $print_total = 0; $nototal = 1; include $config['html_dir'] . '/includes/graphs/generic_duplex.inc.php'; // EOF
function humanspeed($speed) { $speed = formatRates($speed); if ($speed == "") { $speed = "-"; } return $speed; }
//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") { dbUpdate(array('deleted' => '1', 'ifLastChange' => date('Y-m-d H:i:s', $polled)), 'ports', '`device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $port['ifIndex'])); log_event("Interface was marked as DELETED", $device, 'port', $port); }
$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); $form['row'][0]['state'] = array('type' => 'multiselect', 'name' => 'Port State', 'width' => '100%', 'value' => $vars['state'], 'values' => array('up' => 'Up', 'down' => ' Down', 'admindown' => 'Admin Down')); $form['row'][0]['ifType'] = array('type' => 'multiselect', 'name' => 'Port Media', 'width' => '100%', 'value' => $vars['ifType'], 'values' => $form_items['ifType']);
} elseif ($port['ifVlan']) { echo '<p class=box-desc><span class=blue>VLAN ' . $port['ifVlan'] . '</span></p>'; } elseif ($port['ifVrf']) { $vrf = dbFetchRow('SELECT * FROM vrfs WHERE vrf_id = ?', array($port['ifVrf'])); echo "<p style='color: green;'>" . $vrf['vrf_name'] . '</p>'; } //end if } //end if if ($port_adsl['adslLineCoding']) { echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; echo $port_adsl['adslLineCoding'] . '/' . rewrite_adslLineType($port_adsl['adslLineType']); echo '<br />'; echo 'Sync:' . formatRates($port_adsl['adslAtucChanCurrTxRate']) . '/' . formatRates($port_adsl['adslAturChanCurrTxRate']); echo '<br />'; echo 'Max:' . formatRates($port_adsl['adslAtucCurrAttainableRate']) . '/' . formatRates($port_adsl['adslAturCurrAttainableRate']); echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; echo 'Atten:' . $port_adsl['adslAtucCurrAtn'] . 'dB/' . $port_adsl['adslAturCurrAtn'] . 'dB'; echo '<br />'; echo 'SNR:' . $port_adsl['adslAtucCurrSnrMgn'] . 'dB/' . $port_adsl['adslAturCurrSnrMgn'] . 'dB'; } else { echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; if ($port['ifType'] && $port['ifType'] != '') { echo '<span class=box-desc>' . fixiftype($port['ifType']) . '</span>'; } else { echo '-'; } echo '<br />'; if ($ifHardType && $ifHardType != '') { echo '<span class=box-desc>' . $ifHardType . '</span>'; } else {
echo '>'; if ($vars['sort'] == $col['sort']) { echo $col['head'] . ' *'; } else { echo '<a href="' . generate_url($vars, array('sort' => $col['sort'])) . '">' . $col['head'] . '</a>'; } echo "</th>"; } echo " </tr></thead>"; $ports_disabled = 0; $ports_down = 0; $ports_up = 0; $ports_total = 0; foreach ($ports as $port) { $device = device_by_id_cache($port['device_id']); #&$GLOBALS['cache']['devices']['id'][$port['device_id']]; $ports_total++; humanize_port($port); 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>", errors); } else { $error_img = ""; } $port['bps_in'] = formatRates($port['ifInOctets_rate'] * 8); $port['bps_out'] = formatRates($port['ifOutOctets_rate'] * 8); $port['pps_in'] = format_si($port['ifInUcastPkts_rate']) . "pps"; $port['pps_out'] = format_si($port['ifOutUcastPkts_rate']) . "pps"; echo "<tr class='ports " . $port['row_class'] . "'>\n <td style='background-color: " . $port['table_tab_colour'] . ";'></td>\n <td></td>\n <td><span class=entity>" . generate_device_link($device, short_hostname($device['hostname'], "20")) . "</span><br />\n <span class=em>" . truncate($port['location'], 32, "") . "</span></td>\n\n <td><span class=entity>" . generate_port_link($port, rewrite_ifname($port['label'])) . " " . $error_img . "</span><br />\n <span class=em>" . truncate($port['ifAlias'], 50, '') . "</span></td>" . '<td> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . formatRates($port['in_rate']) . '</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . formatRates($port['out_rate']) . '</span><br /></td>' . '<td> <i class="icon-circle-arrow-down" style="' . $port['bps_in_style'] . '"></i> <span class="small" style="' . $port['bps_in_style'] . '">' . $port['ifInOctets_perc'] . '%</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['bps_out_style'] . '"></i> <span class="small" style="' . $port['bps_out_style'] . '">' . $port['ifOutOctets_perc'] . '%</span><br /></td>' . '<td><i class="icon-circle-arrow-down" style="' . $port['pps_in_style'] . '"></i> <span class="small" style="' . $port['pps_in_style'] . '">' . format_bi($port['ifInUcastPkts_rate']) . 'pps</span><br />' . '<i class="icon-circle-arrow-up" style="' . $port['pps_out_style'] . '"></i> <span class="small" style="' . $port['pps_out_style'] . '">' . format_bi($port['ifOutUcastPkts_rate']) . 'pps</span></td>' . "<td>" . $port['human_speed'] . "<br />" . $port['ifMtu'] . "</td>\n <td >" . $port['human_type'] . "<br />" . $port['human_mac'] . "</td>\n </tr>\n"; } echo '</td></tr></table>'; echo pagination($vars, count($ports));
// If we have a valid ifSpeed we should populate the stats for checking. if (is_numeric($this_port['ifSpeed'])) { $port['stats']['ifInBits_perc'] = round($port['stats']['ifInBits_rate'] / $this_port['ifSpeed'] * 100); $port['stats']['ifOutBits_perc'] = round($port['stats']['ifOutBits_rate'] / $this_port['ifSpeed'] * 100); } echo 'bps(' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ')'; echo 'bytes(' . formatStorage($port['stats']['ifInOctets_diff']) . '/' . formatStorage($port['stats']['ifOutOctets_diff']) . ')'; echo 'pkts(' . format_si($port['stats']['ifInUcastPkts_rate']) . 'pps/' . format_si($port['stats']['ifOutUcastPkts_rate']) . 'pps)'; // Port utilisation % threshold alerting. // FIXME allow setting threshold per-port. probably 90% of ports we don't care about. if ($config['alerts']['port_util_alert'] && $port['ignore'] == '0') { // Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this. // Check both inbound and outbound rates $saturation_threshold = $this_port['ifSpeed'] * ($config['alerts']['port_util_perc'] / 100); echo 'IN: ' . $port['stats']['ifInBits_rate'] . ' OUT: ' . $port['stats']['ifOutBits_rate'] . ' THRESH: ' . $saturation_threshold; if (($port['stats']['ifInBits_rate'] >= $saturation_threshold || $port['stats']['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0) { log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates($this_port['stats']['ifSpeed']), $device, 'interface', $port['port_id']); } } // Update RRDs $rrdfile = $host_rrd . '/port-' . safename($port['ifIndex'] . '.rrd'); if (!is_file($rrdfile)) { rrdtool_create($rrdfile, ' --step 300 DS:INOCTETS:DERIVE:600:0:12500000000 DS:OUTOCTETS:DERIVE:600:0:12500000000 DS:INERRORS:DERIVE:600:0:12500000000 DS:OUTERRORS:DERIVE:600:0:12500000000 DS:INUCASTPKTS:DERIVE:600:0:12500000000 DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 DS:INNUCASTPKTS:DERIVE:600:0:12500000000 DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 DS:INDISCARDS:DERIVE:600:0:12500000000
foreach ($adsl_db_oids as $oid) { $data = str_replace('"', '', $this_port[$oid]); // FIXME - do we need this? $port['adsl_update'][$oid] = $data; } dbUpdate($port['adsl_update'], 'ports_adsl', '`port_id` = ?', array($port_id)); if ($this_port['adslAtucCurrSnrMgn'] > '1280') { $this_port['adslAtucCurrSnrMgn'] = 'U'; } if ($this_port['adslAturCurrSnrMgn'] > '1280') { $this_port['adslAturCurrSnrMgn'] = 'U'; } $fields = array(); foreach ($adsl_oids as $oid) { $oid = 'adsl' . $oid; $data = str_replace('"', '', $this_port[$oid]); // Set data to be "unknown" if it's garbled, unexistant or zero if (!is_numeric($data)) { $data = 'U'; } $fields[$oid] = $data; } if (!is_file($rrdfile)) { rrdtool_create($rrdfile, $rrd_create); } rrdtool_update($rrdfile, $fields); $tags = array('ifName' => $port['ifName']); influx_update($device, 'adsl', $tags, $fields); echo 'ADSL (' . $this_port['adslLineCoding'] . '/' . formatRates($this_port['adslAtucChanCurrTxRate']) . '/' . formatRates($this_port['adslAturChanCurrTxRate']) . ')'; } //end if
echo 'pkts(' . format_si($port['stats']['ifInUcastPkts_rate']) . 'pps/' . format_si($port['stats']['ifOutUcastPkts_rate']) . 'pps)'; // Store aggregate in/out state if ($config['memcached']['enable'] === true) { $port['state']['ifOctets_rate'] = $port['stats']['ifOutOctets_rate'] + $port['stats']['ifInOctets_rate']; $port['state']['ifUcastPkts_rate'] = $port['stats']['ifOutUcastPkts_rate'] + $port['stats']['ifInUcastPkts_rate']; $port['state']['ifErrors_rate'] = $port['stats']['ifOutErrors_rate'] + $port['stats']['ifInErrors_rate']; } // Port utilisation % threshold alerting. // FIXME allow setting threshold per-port. probably 90% of ports we don't care about. if ($config['alerts']['port_util_alert'] && $port['ignore'] == '0') { // Check for port saturation of $config['alerts']['port_util_perc'] or higher. Alert if we see this. // Check both inbound and outbound rates $saturation_threshold = $this_port['ifSpeed'] * ($config['alerts']['port_util_perc'] / 100); echo 'IN: ' . $port['stats']['ifInBits_rate'] . ' OUT: ' . $port['stats']['ifOutBits_rate'] . ' THRESH: ' . $saturation_threshold; if (($port['stats']['ifInBits_rate'] >= $saturation_threshold || $port['stats']['ifOutBits_rate'] >= $saturation_threshold) && $saturation_threshold > 0) { log_event('Port reached saturation threshold: ' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates($this_port['stats']['ifSpeed']), $device, 'interface', $port['port_id']); notify($device, 'Port saturation threshold reached on ' . $device['hostname'], 'Port saturation threshold alarm: ' . $device['hostname'] . ' on ' . $port['ifDescr'] . "\nRates:" . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ' - ifspeed: ' . formatRates($this_port['ifSpeed'])); } } // Update RRDs $rrdfile = $host_rrd . '/port-' . safename($port['ifIndex'] . '.rrd'); if (!is_file($rrdfile)) { rrdtool_create($rrdfile, ' --step 300 \\ DS:INOCTETS:DERIVE:600:0:12500000000 \\ DS:OUTOCTETS:DERIVE:600:0:12500000000 \\ DS:INERRORS:DERIVE:600:0:12500000000 \\ DS:OUTERRORS:DERIVE:600:0:12500000000 \\ DS:INUCASTPKTS:DERIVE:600:0:12500000000 \\ DS:OUTUCASTPKTS:DERIVE:600:0:12500000000 \\ DS:INNUCASTPKTS:DERIVE:600:0:12500000000 \\ DS:OUTNUCASTPKTS:DERIVE:600:0:12500000000 \\ DS:INDISCARDS:DERIVE:600:0:12500000000 \\
private function _port($params) { $params = explode(' ', $params); $hostname = $params[0]; $ifname = $params[1]; if (!$hostname || !$ifname) { return $this->respond('Error: Missing hostname or ifname.'); } $device = dbFetchRow('SELECT * FROM `devices` WHERE `hostname` = ?', array($hostname)); $port = dbFetchRow('SELECT * FROM `ports` WHERE (`ifName` = ? OR `ifDescr` = ?) AND device_id = ?', array($ifname, $ifname, $device['device_id'])); if ($this->user['level'] < 5 && !in_array($port['port_id'], $this->user['ports']) && !in_array($device['device_id'], $this->user['devices'])) { return $this->respond('Error: Permission denied.'); } $bps_in = formatRates($port['ifInOctets_rate'] * 8); $bps_out = formatRates($port['ifOutOctets_rate'] * 8); $pps_in = format_bi($port['ifInUcastPkts_rate']); $pps_out = format_bi($port['ifOutUcastPkts_rate']); return $this->respond($port['ifAdminStatus'] . '/' . $port['ifOperStatus'] . ' ' . $bps_in . ' > bps > ' . $bps_out . ' | ' . $pps_in . 'pps > PPS > ' . $pps_out . 'pps'); }
echo '</span>'; $width = '120'; $height = '40'; $from = $config['time']['day']; echo '</td><td width=135>'; echo formatRates($port['ifInOctets_rate'] * 8) . " <img class='optionicon' src='images/icons/arrow_updown.png' /> " . formatRates($port['ifOutOctets_rate'] * 8); echo '<br />'; $port['graph_type'] = 'port_bits'; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . '&id=' . $port['port_id'] . '&from=' . $from . '&to=' . $config['time']['now'] . '&width=' . $width . '&height=' . $height . '&legend=no&bg=' . str_replace('#', '', $row_colour) . "'>", $port['graph_type']); echo '</td><td width=135>'; echo '' . formatRates($port['adslAturChanCurrTxRate']) . '/' . formatRates($port['adslAtucChanCurrTxRate']); echo '<br />'; $port['graph_type'] = 'port_adsl_speed'; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . '&id=' . $port['port_id'] . '&from=' . $from . '&to=' . $config['time']['now'] . '&width=' . $width . '&height=' . $height . '&legend=no&bg=' . str_replace('#', '', $row_colour) . "'>", $port['graph_type']); echo '</td><td width=135>'; echo '' . formatRates($port['adslAturCurrAttainableRate']) . '/' . formatRates($port['adslAtucCurrAttainableRate']); echo '<br />'; $port['graph_type'] = 'port_adsl_attainable'; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . '&id=' . $port['port_id'] . '&from=' . $from . '&to=' . $config['time']['now'] . '&width=' . $width . '&height=' . $height . '&legend=no&bg=' . str_replace('#', '', $row_colour) . "'>", $port['graph_type']); echo '</td><td width=135>'; echo '' . $port['adslAturCurrAtn'] . 'dB/' . $port['adslAtucCurrAtn'] . 'dB'; echo '<br />'; $port['graph_type'] = 'port_adsl_attenuation'; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . '&id=' . $port['port_id'] . '&from=' . $from . '&to=' . $config['time']['now'] . '&width=' . $width . '&height=' . $height . '&legend=no&bg=' . str_replace('#', '', $row_colour) . "'>", $port['graph_type']); echo '</td><td width=135>'; echo '' . $port['adslAturCurrSnrMgn'] . 'dB/' . $port['adslAtucCurrSnrMgn'] . 'dB'; echo '<br />'; $port['graph_type'] = 'port_adsl_snr'; echo generate_port_link($port, "<img src='graph.php?type=" . $port['graph_type'] . '&id=' . $port['port_id'] . '&from=' . $from . '&to=' . $config['time']['now'] . '&width=' . $width . '&height=' . $height . '&legend=no&bg=' . str_replace('#', '', $row_colour) . "'>", $port['graph_type']); echo '</td><td width=135>'; echo '' . $port['adslAturCurrOutputPwr'] . 'dBm/' . $port['adslAtucCurrOutputPwr'] . 'dBm';
/** * @dataProvider providerFormatRates */ public function testFormatRates($value, $round, $sf, $result) { $this->assertSame($result, formatRates($value, $round, $sf)); }
function humanspeed($speed) { if ($speed == '') { return '-'; } else { return formatRates($speed); } }
<?php // Generate a list of ports and then call the multi_bits grapher to generate from the list $i = 0; foreach ($ports as $port) { if (is_file($config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"))) { $rrd_list[$i]['filename'] = $config['rrd_dir'] . "/" . $port['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"); $rrd_list[$i]['descr'] = $port['ifDescr']; $i++; } } $units = 'bps'; $total_units = 'B'; $colours_in = 'greens'; $multiplier = "8"; $colours_out = 'blues'; $nototal = 1; $ds_in = "INOCTETS"; $ds_out = "OUTOCTETS"; #print_r($rates); if ($bill['bill_type'] == "cdr") { $custom_graph = " COMMENT:'\\r' "; $custom_graph .= " HRULE:" . $rates['rate_95th'] . "#cc0000:'95th %ile \\: " . formatRates($rates['rate_95th']) . " (" . $rates['dir_95th'] . ") (CDR\\: " . formatRates($bill['bill_cdr']) . ")'"; $custom_graph .= " HRULE:" . $rates['rate_95th'] * -1 . "#cc0000"; } elseif ($bill['bill_type'] == "quota") { $custom_graph = " COMMENT:'\\r' "; $custom_graph .= " HRULE:" . $rates['rate_average'] . "#cc0000:'Usage \\: " . format_bytes_billing($rates['total_data']) . " (" . formatRates($rates['rate_average']) . ")'"; $custom_graph .= " HRULE:" . $rates['rate_average'] * -1 . "#cc0000"; } include "includes/graphs/generic_multi_bits_separated.inc.php";
$port['alert_array'][$oid] = $this_port[$oid]; } } // If we have a valid ifSpeed we should populate the percentage stats for checking. if (is_numeric($this_port['ifSpeed'])) { $port['stats']['ifInBits_perc'] = round($port['stats']['ifInBits_rate'] / $this_port['ifSpeed'] * 100); $port['stats']['ifOutBits_perc'] = round($port['stats']['ifOutBits_rate'] / $this_port['ifSpeed'] * 100); $port['alert_array']['ifSpeed'] = $this_port['ifSpeed']; } $port['state']['ifInOctets_perc'] = $port['stats']['ifInBits_perc']; $port['state']['ifOutOctets_perc'] = $port['stats']['ifOutBits_perc']; $port['alert_array']['ifInOctets_perc'] = $port['stats']['ifInBits_perc']; $port['alert_array']['ifOutOctets_perc'] = $port['stats']['ifOutBits_perc']; $port['alert_array']['rx_ave_pktsize'] = $port['state']['ifInOctets_delta'] / ($port['state']['ifInUcastPkts_delta'] + $port['state']['ifInNUcastPkts_delta']); $port['alert_array']['tx_ave_pktsize'] = $port['state']['ifOutOctets_delta'] / ($port['state']['ifOutUcastPkts_delta'] + $port['state']['ifOutNUcastPkts_delta']); echo 'bps(' . formatRates($port['stats']['ifInBits_rate']) . '/' . formatRates($port['stats']['ifOutBits_rate']) . ')'; echo 'bytes(' . formatStorage($port['stats']['ifInOctets_diff']) . '/' . formatStorage($port['stats']['ifOutOctets_diff']) . ')'; echo 'pkts(' . format_si($port['stats']['ifInUcastPkts_rate']) . 'pps/' . format_si($port['stats']['ifOutUcastPkts_rate']) . 'pps)'; // Store aggregate in/out state $port['state']['ifOctets_rate'] = $port['stats']['ifOutOctets_rate'] + $port['stats']['ifInOctets_rate']; $port['state']['ifUcastPkts_rate'] = $port['stats']['ifOutUcastPkts_rate'] + $port['stats']['ifInUcastPkts_rate']; $port['state']['ifErrors_rate'] = $port['stats']['ifOutErrors_rate'] + $port['stats']['ifInErrors_rate']; // Update RRDs $rrdfile = get_port_rrdfilename($port); rrdtool_create($device, $rrdfile, "\\\n DS:INOCTETS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTOCTETS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INERRORS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTERRORS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INUCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTUCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INNUCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTNUCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INDISCARDS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTDISCARDS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INUNKNOWNPROTOS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INBROADCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTBROADCASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:INMULTICASTPKTS:DERIVE:600:0:" . $config['max_port_speed'] . " \\\n DS:OUTMULTICASTPKTS:DERIVE:600:0:" . $config['max_port_speed']); $this_port['rrd_update'] = array($this_port['ifInOctets'], $this_port['ifOutOctets'], $this_port['ifInErrors'], $this_port['ifOutErrors'], $this_port['ifInUcastPkts'], $this_port['ifOutUcastPkts'], $this_port['ifInNUcastPkts'], $this_port['ifOutNUcastPkts'], $this_port['ifInDiscards'], $this_port['ifOutDiscards'], $this_port['ifInUnknownProtos'], $this_port['ifInBroadcastPkts'], $this_port['ifOutBroadcastPkts'], $this_port['ifInMulticastPkts'], $this_port['ifOutMulticastPkts']); rrdtool_update($device, $rrdfile, $this_port['rrd_update']); // End Update IF-MIB // Update PAgP if ($this_port['pagpOperationMode'] || $port['pagpOperationMode']) { $log_event = array();
} else { unset($as); unset($astext); unset($asn); } if (!isset($vars['graph'])) { $vars['graph'] = "bits"; } $graph_type = "macaccounting_" . $vars['graph']; if ($vars['subview'] == "minigraphs") { if (!$asn) { $asn = "无会话"; } echo "<div style='display: block; padding: 3px; margin: 3px; min-width: 221px; max-width:221px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e5e5e5;'>\n " . $addy['ipv4_address'] . " - " . $asn . "\n <a href='#' onmouseover=\"return overlib('\\\n <div style=\\'font-size: 16px; padding:5px; font-weight: bold; color: #555555;\\'>" . $name . " - " . $addy['ipv4_address'] . " - " . $asn . "</div>\\\n <img src=\\'graph.php?id=" . $acc['ma_id'] . "&type={$graph_type}&from=" . $config['time']['twoday'] . "&to=" . $config['time']['now'] . "&width=450&height=150\\'>\\\n ', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >\n <img src='graph.php?id=" . $acc['ma_id'] . "&type={$graph_type}&from=" . $config['time']['twoday'] . "&to=" . $config['time']['now'] . "&width=213&height=45'></a>\n\n <span style='font-size: 10px;'>" . $name . "</span>\n </div>"; } else { echo "\n <tr>\n <td width=20></td>\n <td width=200><bold>" . format_mac($acc['mac']) . "</bold></td>\n <td width=200>" . implode($ips, "<br />") . "</td>\n <td width=500>" . $name . " " . $arp_name . "</td>\n <td width=100>" . formatRates($acc['bytes_input_rate'] / 8) . "</td>\n <td width=100>" . formatRates($acc['bytes_output_rate'] / 8) . "</td>\n <td width=100>" . format_number($acc['pkts_input_rate'] / 8) . "pps</td>\n <td width=100>" . format_number($acc['pkts_output_rate'] / 8) . "pps</td>\n </tr>\n "; $peer_info['astext']; if ($vars['subview'] == "graphs") { $graph_array['type'] = $graph_type; $graph_array['id'] = $acc['ma_id']; $graph_array['height'] = "100"; $graph_array['to'] = $config['time']['now']; echo '<tr><td colspan="8">'; print_graph_row($graph_array); echo "</td></tr>"; $i++; } } } echo "</table>"; }
dbInsert(array('port_id' => $port['port_id']), 'ports_adsl'); } $port['adsl_update'] = array('port_adsl_updated' => array('NOW()')); foreach ($adsl_db_oids as $oid) { $data = str_replace("\"", "", $this_port[$oid]); // FIXME - do we need this? $port['adsl_update'][$oid] = $data; } dbUpdate($port['adsl_update'], 'ports_adsl', '`port_id` = ?', array($port['port_id'])); if ($this_port['adslAtucCurrSnrMgn'] > "1280") { $this_port['adslAtucCurrSnrMgn'] = "U"; } if ($this_port['adslAturCurrSnrMgn'] > "1280") { $this_port['adslAturCurrSnrMgn'] = "U"; } $rrdupdate = "N"; foreach ($adsl_oids as $oid) { $oid = "adsl" . $oid; $data = str_replace("\"", "", $this_port[$oid]); // Set data to be "unknown" if it's garbled, unexistant or zero if (!is_numeric($data)) { $data = "U"; } $rrdupdate .= ":{$data}"; } if (!is_file($rrdfile)) { rrdtool_create($rrdfile, $rrd_create); } rrdtool_update($rrdfile, $rrdupdate); echo "ADSL (" . $this_port['adslLineCoding'] . "/" . formatRates($this_port['adslAtucChanCurrTxRate']) . "/" . formatRates($this_port['adslAturChanCurrTxRate']) . ")"; }
function humanspeed($speed) { $speed = formatRates($speed); if ($speed == '') { $speed = '-'; } return $speed; }
$in_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100); $out_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100); } if ($port['ifSpeed']) { $port_speed = humanspeed($port['ifSpeed']); } if ($port[ifDuplex] != 'unknown') { $port_duplex = $port['ifDuplex']; } if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') { $port_mac = formatMac($port['ifPhysAddress']); } if ($port['ifMtu'] && $port['ifMtu'] != '') { $port_mtu = $port['ifMtu']; } $tbl->addRow(array($port['ifDescr'], $port['ifOperStatus'], '', formatRates($port['in_rate']), formatRates($port['out_rate']), format_bi($port['ifInUcastPkts_rate']) . 'pps', format_bi($port['ifOutUcastPkts_rate']) . 'pps', $port_speed, $port_duplex, '', $port_mac, $port_mtu)); } //end foreach echo $tbl->getTable(); } else { echo $options['list']; echo "Usage of console-ui.php:\n\n -l What log type we want to see:\n eventlog = Event log messages\n syslog = Syslog messages\n\n -d Specify the device id to filter results\n\n --list What to list\n devices = list devices and device id's\n\n --device-stats Lists the port statistics for a given device\n\n Examples:\n #1 php console-ui.php -l eventlog -d 1\n #2 php console-ui.php --list=devices\n\n "; exit; } } } } //end if echo print $console_color->convert('%rLast update at ' . date('Y-m-d h:i:s') . "%n\n\n"); sleep(5); }
case 'errors': $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); break; case 'speed': $ports = array_sort($ports, 'ifSpeed', SORT_DESC); break; case 'port': $ports = array_sort($ports, 'ifDescr', SORT_ASC); break; case 'media': $ports = array_sort($ports, 'ifType', SORT_ASC); break; case 'descr': $ports = array_sort($ports, 'ifAlias', SORT_ASC); break; case 'device': default: $ports = array_sort($ports, 'hostname', SORT_ASC); } //end switch $csv[] = array('Device', 'Port', 'Speed', 'Down', 'Up', 'Media', 'Description'); foreach ($ports as $port) { if (port_permitted($port['port_id'], $port['device_id'])) { $speed = humanspeed($port['ifSpeed']); $type = humanmedia($port['ifType']); $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); $port = ifLabel($port, $device); $csv[] = array($port['hostname'], fixIfName($port['label']), $speed, $port['in_rate'], $port['out_rate'], $type, $port['ifAlias']); } }
// The Customer is billed based on a pre-paid quota with overage in xB $percent = round($total_data / $bill_data['bill_quota'] * 100, 2); $unit = 'MB'; $total_data = round($total_data, 2); $background = get_percentage_colours($percent); $type = '&ave=yes'; ?> <td> <?php echo format_bytes_billing($total_data); ?> of <?php echo format_bytes_billing($bill_data['bill_quota']) . ' (' . $percent . '%)'; ?> - Average rate <?php echo formatRates($rate_average); ?> </td> <td style="width: 210px;"><?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']); ?> </td> <?php } else { if ($bill_data['bill_type'] == 'cdr') { // The customer is billed based on a CDR with 95th%ile overage $unit = 'kbps'; $cdr = $bill_data['bill_cdr']; $rate_95th = round($rate_95th, 2); $percent = round($rate_95th / $cdr * 100, 2); $type = '&95th=yes';