$check = dbFetchRow("SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1", array($bill['bill_id'], $datefrom, $dateto)); $period = getPeriod($bill['bill_id'], $datefrom, $dateto); $date_updated = str_replace("-", "", str_replace(":", "", str_replace(" ", "", $check['updated']))); if ($period > 0 && $dateto > $date_updated) { $rate_data = getRates($bill['bill_id'], $datefrom, $dateto); #print_vars($rate_data); # $rate_95th = $rate_data['rate_95th']; # $dir_95th = $rate_data['dir_95th']; # $total_data = $rate_data['total_data']; # $rate_average = $rate_data['rate_average']; if ($bill['bill_type'] == "cdr") { $type = "CDR"; $allowed = $bill['bill_cdr']; $used = $rate_data['rate_95th']; $allowed_text = format_si($allowed) . "bps"; $used_text = format_si($used) . "bps"; $overuse = $used - $allowed; $overuse = $overuse <= 0 ? "0" : $overuse; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); } elseif ($bill['bill_type'] == "quota") { $type = "Quota"; $allowed = $bill['bill_quota']; $used = $rate_data['total_data']; $allowed_text = format_bytes_billing($allowed); $used_text = format_bytes_billing($used); $overuse = $used - $allowed; $overuse = $overuse <= 0 ? "0" : $overuse; $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); } echo strftime("%x @ %X", strtotime($datefrom)) . " to " . strftime("%x @ %X", strtotime($dateto)) . " " . str_pad($type, 8) . " " . str_pad($allowed_text, 10) . " " . str_pad($used_text, 10) . " " . $percent . "%"; if ($i == '0') {
$afi = $afisafi['afi']; $safi = $afisafi['safi']; $this_afisafi = $afi . $safi; $peer['afi'] .= $sep . $afi . "." . $safi; $sep = "<br />"; $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } $graph_type = "bgp_updates"; $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'] . "&width=500&height=150"; $peeraddresslink = "<span class=entity-title><a onmouseover=\"return overlib('<img src=\\'{$peer_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['human_remoteip'] . "</a></span>"; echo '<tr class="' . $peer['html_row_class'] . '">'; echo ' <td style="width: 1px; background-color: ' . $peer['table_tab_colour'] . '; margin: 0px; padding: 0px"></td> <td style="width: 1px;"></td>'; echo " <td>" . $peeraddresslink . "<br />" . $peername . "</td>\n <td><strong>" . $peer['peer_type'] . "</strong></td>\n <td style='font-size: 10px; font-weight: bold; line-height: 10px;'>" . (isset($peer['afi']) ? $peer['afi'] : '') . "</td>\n <td><strong>AS" . $peer['bgpPeerRemoteAs'] . "</strong><br />" . $peer['astext'] . "</td>\n <td><strong><span class='" . $peer['admin_class'] . "'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span class='" . $peer['state_class'] . "'>" . $peer['bgpPeerState'] . "</span></strong></td>\n <td>" . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n Updates <i class='oicon-arrow_down'></i> " . format_si($peer['bgpPeerInUpdates']) . "\n <i class='oicon-arrow_up'></i> " . format_si($peer['bgpPeerOutUpdates']) . "</td>\n </tr>"; unset($invalid); switch ($vars['view']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_vpnv4unicast': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': list(, $afisafi) = explode("_", $vars['view']); if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } // FIXME no break?? // FIXME no break?? case 'updates': $graph_array['type'] = "bgp_" . $vars['view'];
foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { $afi = $afisafi['afi']; $safi = $afisafi['safi']; $this_afisafi = $afi . $safi; $peer['afi'] .= $sep . $afi . '.' . $safi; $sep = '<br />'; $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } unset($sep); echo ' <td></td> <td width=150>' . $localaddresslink . '<br />' . generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')) . '</td> <td width=30><b>»</b></td> <td width=150>' . $peeraddresslink . "</td>\n <td width=50><b>{$peer_type}</b></td>\n <td width=50>" . $peer['afi'] . '</td> <td><strong>AS' . $peer['bgpPeerRemoteAs'] . '</strong><br />' . $peer['astext'] . "</td>\n <td><strong><span style='color: {$admin_col};'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span style='color: {$col};'>" . $peer['bgpPeerState'] . '</span></strong></td> <td>' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n Updates <img src='images/16/arrow_down.png' align=absmiddle /> " . format_si($peer['bgpPeerInUpdates']) . "\n <img src='images/16/arrow_up.png' align=absmiddle /> " . format_si($peer['bgpPeerOutUpdates']) . '</td></tr>'; unset($invalid); switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': list(, $afisafi) = explode('_', $vars['graph']); if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } case 'updates': $graph_array['type'] = 'bgp_' . $vars['graph']; $graph_array['id'] = $peer['bgpPeer_id']; }
/** * @dataProvider providerFormatSi */ public function testFormatSi($value, $round, $sf, $result) { $this->assertSame($result, format_si($value, $round, $sf)); }
$dateto = $day_data['1']; $check = dbFetchRow('SELECT * FROM `bill_history` WHERE bill_id = ? AND bill_datefrom = ? AND bill_dateto = ? LIMIT 1', array($bill['bill_id'], $datefrom, $dateto)); $period = getPeriod($bill['bill_id'], $datefrom, $dateto); $date_updated = str_replace('-', '', str_replace(':', '', str_replace(' ', '', $check['updated']))); if ($period > 0 && $dateto > $date_updated) { $rate_data = getRates($bill['bill_id'], $datefrom, $dateto); $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; $total_data = $rate_data['total_data']; $rate_average = $rate_data['rate_average']; if ($bill['bill_type'] == 'cdr') { $type = 'CDR'; $allowed = $bill['bill_cdr']; $used = $rate_data['rate_95th']; $allowed_text = format_si($allowed) . 'bps'; $used_text = format_si($used) . 'bps'; $overuse = $used - $allowed; $overuse = $overuse <= 0 ? '0' : $overuse; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); } else { if ($bill['bill_type'] == 'quota') { $type = 'Quota'; $allowed = $bill['bill_quota']; $used = $rate_data['total_data']; $allowed_text = format_bytes_billing($allowed); $used_text = format_bytes_billing($used); $overuse = $used - $allowed; $overuse = $overuse <= 0 ? '0' : $overuse; $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); } }
if (is_integer($i / 2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } if ($vsvr['vsvr_state'] == 'up') { $vsvr_class = 'green'; } else { $vsvr_class = 'red'; } echo "<tr bgcolor='{$bg_colour}'>"; echo '<td width=320 class=list-large><a href="' . generate_url($vars, array('vsvr' => $vsvr['vsvr_id'], 'view' => null, 'graph' => null)) . '">' . $vsvr['vsvr_name'] . '</a></td>'; echo '<td width=320 class=list-small>' . $vsvr['vsvr_ip'] . ':' . $vsvr['vsvr_port'] . '</a></td>'; echo "<td width=100 class=list-small><span class='" . $vsvr_class . "'>" . $vsvr['vsvr_state'] . '</span></td>'; echo '<td width=320 class=list-small>' . format_si($vsvr['vsvr_bps_in'] * 8) . 'bps</a></td>'; echo '<td width=320 class=list-small>' . format_si($vsvr['vsvr_bps_out'] * 8) . 'bps</a></td>'; echo '</tr>'; if ($vars['view'] == 'graphs') { echo '<tr class="list-bold" bgcolor="' . $bg_colour . '">'; echo '<td colspan="5">'; $graph_type = 'netscalervsvr_' . $vars['graph']; $graph_array['height'] = '100'; $graph_array['width'] = '213'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $vsvr['vsvr_id']; $graph_array['type'] = $graph_type; include 'includes/print-graphrow.inc.php'; echo ' </td> </tr>'; }
if ($config['debug_port'][$port['port_id']]) { $port_debug = $port['port_id'] . '|' . $polled . '|' . $polled_period . '|' . $this_port['ifHCInOctets'] . '|' . $this_port['ifHCOutOctets']; $port_debug .= '|' . $port['stats']['ifInOctets_rate'] . '|' . $port['stats']['ifOutOctets_rate'] . "\n"; file_put_contents('/tmp/port_debug.txt', $port_debug, FILE_APPEND); echo 'Wrote port debugging data'; } $port['stats']['ifInBits_rate'] = round($port['stats']['ifInOctets_rate'] * 8); $port['stats']['ifOutBits_rate'] = round($port['stats']['ifOutOctets_rate'] * 8); // 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
<?php echo '<table cellspacing="0" cellpadding="5" width="100%">'; $i = 0; foreach (dbFetchRows('SELECT * FROM `packages` WHERE `device_id` = ? ORDER BY `name`', array($device['device_id'])) as $entry) { echo '<tr class="list">'; echo '<td width=200><a href="' . generate_url($vars, array('name' => $entry['name'])) . '">' . $entry['name'] . '</a></td>'; if ($build != '') { $dbuild = '-' . $entry['build']; } else { $dbuild = ''; } echo '<td>' . $entry['version'] . $dbuild . '</td>'; echo '<td>' . $entry['arch'] . '</td>'; echo '<td>' . $entry['manager'] . '</td>'; echo '<td>' . format_si($entry['size']) . '</td>'; echo '</tr>'; $i++; } echo '</table>';
$classes = array('primary', 'success', 'danger'); $legend = '<table class="table table-condensed-more">'; $i = 0; foreach ($totals_array as $type => $dir) { // derp we actually need whole #s here for the graph. muiltiply by 100, yo! $percentIn = $dir["in"] / $totalIn * 100; $percentOut = $dir["out"] / $totalOut * 100; $percent = ($dir["in"] + $dir["out"]) / ($totalIn + $totalOut) * 100; $color = $config['graph_colours']['mixed'][$i]; $class = $classes[$i]; $bars_in .= ' <div class="progress-bar progress-bar-' . $class . '" style="width: ' . $percentIn . '%"><span class="sr-only">' . round($percentIn) . '%' . '</span></div>'; $bars_out .= ' <div class="progress-bar progress-bar-' . $class . '" style="width: ' . $percentOut . '%"><span class="sr-only">' . round($percentOut) . '%' . '</span></div>'; $bars .= ' <div class="progress-bar progress-bar-' . $class . '" style="width: ' . $percent . '%"><span class="sr-only">' . round($percent) . '%' . '</span></div>'; $i++; $legend .= '<tr><td><span class="label label-' . $class . '">' . $type . '</span></td><td><i class="icon-circle-arrow-down green"></i> <small><b>' . format_si($dir['in']) . 'bps</b></small></td> <td><i class="icon-circle-arrow-up" style="color: #323b7c;"></i> <small><b>' . format_si($dir['out']) . 'bps</b></small></td> </tr>'; } $legend .= '</table>'; ?> <table class="table table-condensed"> <tr> <td rowspan="3" width="220"><?php echo $legend; ?> </td> <th width="40"><span class="label label-success"><i class="icon-circle-arrow-up"></i> In</span></th> <td> <div class="progress" style="margin-bottom: 0;"> <?php
break; default: echo $cef['cef_path']; } echo '</td>'; echo '<td>' . format_si($cef['drop']); if ($cef['drop'] > $cef['drop_prev']) { echo " <span style='color:red;'>(" . round(($cef['drop'] - $cef['drop_prev']) / $interval, 2) . '/sec)</span>'; } echo '</td>'; echo '<td>' . format_si($cef['punt']); if ($cef['punt'] > $cef['punt_prev']) { echo " <span style='color:red;'>(" . round(($cef['punt'] - $cef['punt_prev']) / $interval, 2) . '/sec)</span>'; } echo '</td>'; echo '<td>' . format_si($cef['punt2host']); if ($cef['punt2host'] > $cef['punt2host_prev']) { echo " <span style='color:red;'>(" . round(($cef['punt2host'] - $cef['punt2host_prev']) / $interval, 2) . '/sec)</span>'; } echo '</td>'; echo '</tr> '; if ($vars['view'] == 'graphs') { $graph_array['height'] = '100'; $graph_array['width'] = '215'; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $cef['cef_switching_id']; $graph_array['type'] = 'cefswitching_graph'; echo "<tr bgcolor='{$bg_colour}'><td colspan=6>"; include 'includes/print-graphrow.inc.php'; echo '</td></tr>';
break; default: echo $cef['cef_path']; } echo "</td>"; echo "<td>" . format_si($cef['drop']); if ($cef['drop'] > $cef['drop_prev']) { echo " <span style='color:red;'>(" . round(($cef['drop'] - $cef['drop_prev']) / $interval, 2) . "/sec)</span>"; } echo "</td>"; echo "<td>" . format_si($cef['punt']); if ($cef['punt'] > $cef['punt_prev']) { echo " <span style='color:red;'>(" . round(($cef['punt'] - $cef['punt_prev']) / $interval, 2) . "/sec)</span>"; } echo "</td>"; echo "<td>" . format_si($cef['punt2host']); if ($cef['punt2host'] > $cef['punt2host_prev']) { echo " <span style='color:red;'>(" . round(($cef['punt2host'] - $cef['punt2host_prev']) / $interval, 2) . "/sec)</span>"; } echo "</td>"; echo "</tr>\n "; if ($vars['view'] == "graphs") { $graph_array['height'] = "100"; $graph_array['width'] = "215"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $cef['cef_switching_id']; $graph_array['type'] = "cefswitching_graph"; echo "<tr bgcolor='{$bg_colour}'><td colspan=6>"; print_graph_row($graph_array); echo "</td></tr>"; }
if (is_integer($i / 2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } if ($vsvr['vsvr_state'] == "up") { $vsvr_class = "green"; } else { $vsvr_class = "red"; } echo "<tr bgcolor='{$bg_colour}'>"; echo '<td width=320 class=list-large><a href="' . generate_url($vars, array('vsvr' => $vsvr['vsvr_id'], 'view' => NULL, 'graph' => NULL)) . '">' . $vsvr['vsvr_name'] . '</a></td>'; echo "<td width=320 class=list-small>" . $vsvr['vsvr_ip'] . ":" . $vsvr['vsvr_port'] . "</a></td>"; echo "<td width=100 class=list-small><span class='" . $vsvr_class . "'>" . $vsvr['vsvr_state'] . "</span></td>"; echo "<td width=320 class=list-small>" . format_si($vsvr['vsvr_bps_in'] * 8) . "bps</a></td>"; echo "<td width=320 class=list-small>" . format_si($vsvr['vsvr_bps_out'] * 8) . "bps</a></td>"; echo "</tr>"; if ($vars['view'] == "graphs") { echo '<tr class="list-bold" bgcolor="' . $bg_colour . '">'; echo '<td colspan="5">'; $graph_type = "netscalervsvr_" . $vars['graph']; $graph_array['height'] = "100"; $graph_array['width'] = "213"; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $vsvr['vsvr_id']; $graph_array['type'] = $graph_type; include "includes/print-graphrow.inc.php"; echo "\n </td>\n </tr>"; } echo "</td>"; echo "</tr>";
<?php /** * Observium Network Management and Monitoring System * Copyright (C) 2006-2014, Adam Armstrong - http://www.observium.org * * @package observium * @subpackage webui * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ echo '<table class="table table-striped-two table-condensed table-bordered">'; echo "<thead><tr>\n <th>内存池</th>\n <th>MIB</th>\n <th>值</th>\n <th>上限</th>\n <th>下限</th>\n </tr></thead>"; $row = 1; $sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id`"; $sql .= " FROM `sensors`"; $sql .= " LEFT JOIN `sensors-state` ON `sensors`.sensor_id = `sensors-state`.sensor_id"; $sql .= " WHERE `sensor_class` = ? AND `device_id` = ?"; foreach (dbFetchRows($sql, array($vars['metric'], $device['device_id'])) as $sensor) { $graph_array['id'] = $sensor['sensor_id']; $graph_array['type'] = 'sensor_' . $vars['metric']; $sensor_url = "graphs/id=" . $sensor['sensor_id'] . "/type=" . $graph_array['type']; echo "<tr>\n <td width=500 class='entity-title'><a class='entity-title' href='" . $sensor_url . "'>" . $sensor['sensor_descr'] . "</a></td>\n <td>" . nicecase($sensor['sensor_type']) . "</td>\n <td width=75>" . format_si($sensor['sensor_value']) . $config['sensor_types'][$vars['metric']]['symbol'] . "</td>\n <td width=75>" . format_si($sensor['sensor_limit']) . $config['sensor_types'][$vars['metric']]['symbol'] . "</td>\n <td width=75>" . format_si($sensor['sensor_limit_low']) . $config['sensor_types'][$vars['metric']]['symbol'] . "</td>\n </tr>\n"; echo "<tr><td colspan='5'>"; print_graph_row($graph_array); echo "</td></tr>"; $row++; } echo "</table>"; // EOF
* * @package observium * @subpackage graphs * @copyright (C) 2006-2014 Adam Armstrong * */ $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_min = '-100'; $scale_max = '100'; $unit_text = '% of ' . format_si($port['ifSpeed']) . 'b'; $args['nototal'] = 1; $print_total = 0; $nototal = 1; include 'includes/graphs/generic_duplex.inc.php'; // EOF
if ('`' . $lhead . '`' == $order) { $icon = " class='fa fa-chevron-"; if ($by == 'asc') { $bhead = 'desc'; $icon .= 'up'; } else { $icon .= 'down'; } $icon .= "'"; } echo '<th><a href="' . generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'processes', 'order' => $lhead, 'by' => $bhead)) . '"><span' . $icon . '> '; if (!empty($extra)) { echo "<abbr title='{$extra}'>{$head}</abbr>"; } else { echo $head; } echo '</span></a></th>'; } //end foreach echo '</tr></thead><tbody>'; foreach (dbFetchRows('SELECT * FROM `processes` WHERE `device_id` = ? ORDER BY ' . $order . ' ' . $by, array($device['device_id'])) as $entry) { echo '<tr>'; echo '<td>' . $entry['pid'] . '</td>'; echo '<td>' . format_si($entry['vsz'] * 1024) . '</td>'; echo '<td>' . format_si($entry['rss'] * 1024) . '</td>'; echo '<td>' . $entry['cputime'] . '</td>'; echo '<td>' . $entry['user'] . '</td>'; echo '<td>' . $entry['command'] . '</td>'; echo '</tr>'; } echo '</tbody></table></div>';
/** * Display bgp peers. * * Display pages with BGP Peers. * Examples: * print_bgp() - display all bgp peers from all devices * print_bgp(array('pagesize' => 99)) - display 99 bgp peers from all device * print_bgp(array('pagesize' => 10, 'pageno' => 3, 'pagination' => TRUE)) - display 10 bgp peers from page 3 with pagination header * print_bgp(array('pagesize' => 10, 'device' = 4)) - display 10 bgp peers for device_id 4 * * @param array $vars * @return none * */ function print_bgp_table($vars) { // Get bgp peers array $entries = get_bgp_array($vars); //r($entries); if (!$entries['count']) { // There have been no entries returned. Print the warning. print_warning('<h4>No BGP peers found!</h4>'); } else { // Entries have been returned. Print the table. $list = array('device' => FALSE); if ($vars['page'] != 'device') { $list['device'] = TRUE; } switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': case 'macaccounting_bits': case 'macaccounting_pkts': case 'updates': $table_class = 'table-striped-two'; $list['graph'] = TRUE; break; default: $table_class = 'table-striped'; $list['graph'] = FALSE; } $string = generate_box_open(); $string .= '<table class="table ' . $table_class . ' table-hover table-condensed ">' . PHP_EOL; $cols = array(array(NULL, 'class="state-marker"'), array(NULL, 'style="width: 1px;"'), 'device' => array('Local address', 'style="width: 150px;"'), array(NULL, 'style="width: 20px;"'), 'peer_ip' => array('Peer address', 'style="width: 150px;"'), 'type' => array('Type', 'style="width: 50px;"'), array('Family', 'style="width: 50px;"'), 'peer_as' => 'Remote AS', 'state' => 'State', 'Uptime / Updates'); //if (!$list['device']) { unset($cols['device']); } $string .= get_table_header($cols, $vars); $string .= ' <tbody>' . PHP_EOL; foreach ($entries['entries'] as $peer) { $local_dev = device_by_id_cache($peer['device_id']); $local_as = $list['device'] ? ' (AS' . $peer['bgpLocalAs'] . ')' : ''; $local_name = generate_device_link($local_dev, short_hostname($local_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp')); $local_ip = generate_device_link($local_dev, $peer['human_localip'] . $local_as, array('tab' => 'routing', 'proto' => 'bgp')); $peer_as = 'AS' . $peer['bgpPeerRemoteAs']; if ($peer['peer_device_id']) { $peer_dev = device_by_id_cache($peer['peer_device_id']); $peer_name = generate_device_link($peer_dev, short_hostname($peer_dev['hostname'], 18), array('tab' => 'routing', 'proto' => 'bgp')); } else { $peer_name = $peer['reverse_dns']; } $peer_ip = generate_entity_link("bgp_peer", $peer, $peer['human_remoteip']); $peer_afis =& $entries['afisafi'][$peer['device_id']][$peer['bgpPeerRemoteAddr']]; $peer_afis_html = array(); foreach ($peer_afis as $peer_afi) { $peer_afi_html = '<span class="label-group">'; switch ($peer_afi['afi']) { case 'ipv4': case 'ipv4z': $afi_class = 'success'; break; case 'ipv6': case 'ipv6z': $afi_class = 'primary'; break; default: $afi_class = 'default'; } switch ($peer_afi['safi']) { case 'unicast': $safi_class = 'delayed'; break; case 'multicast': $safi_class = 'warning'; break; case 'vpn': $safi_class = 'suppressed'; break; default: $safi_class = 'default'; } $peer_afi_html .= '<span class="label label-' . $afi_class . '">' . $peer_afi['afi'] . '</span>'; $peer_afi_html .= '<span class="label label-' . $safi_class . '">' . $peer_afi['safi'] . '</span>'; $peer_afi_html .= '</span>'; $peer_afis_html[] = $peer_afi_html; } $string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL; $string .= ' <td class="state-marker"></td>' . PHP_EOL; $string .= ' <td></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap" class="entity">' . $local_ip . '<br />' . $local_name . '</td>' . PHP_EOL; $string .= ' <td><span class="text-success"><i class="glyphicon glyphicon-arrow-right"></i></span></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap" class="entity">' . $peer_ip . '<br />' . $peer_name . '</td>' . PHP_EOL; $string .= ' <td><span class="label label-' . $peer['peer_type_class'] . '">' . $peer['peer_type'] . '</span></td>' . PHP_EOL; $string .= ' <td>' . implode('<br />', $peer_afis_html) . '</td>' . PHP_EOL; $string .= ' <td><strong>' . $peer_as . '</strong><br />' . $peer['astext'] . '</td>' . PHP_EOL; $string .= ' <td><strong><span class=" label label-' . $peer['admin_class'] . '">' . $peer['bgpPeerAdminStatus'] . '</span><br /><span class="label label-' . $peer['state_class'] . '">' . $peer['bgpPeerState'] . '</span></strong></td>' . PHP_EOL; $string .= ' <td style="white-space: nowrap">' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . '<br /> Updates: <i class="icon-circle-arrow-down text-success"></i> ' . format_si($peer['bgpPeerInUpdates']) . ' <i class="icon-circle-arrow-up text-primary"></i> ' . format_si($peer['bgpPeerOutUpdates']) . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; // Graphs $peer_graph = FALSE; switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': $afisafi = preg_replace('/prefixes_(ipv[46])(\\w+)/', '$1.$2', $vars['graph']); // prefixes_ipv6unicast ->> ipv6.unicast if (isset($peer_afis[$afisafi]) && $peer['bgpPeer_id']) { $graph_array['type'] = 'bgp_' . $vars['graph']; $graph_array['id'] = $peer['bgpPeer_id']; $peer_graph = TRUE; } break; case 'updates': if ($peer['bgpPeer_id']) { $graph_array['type'] = 'bgp_updates'; $graph_array['id'] = $peer['bgpPeer_id']; $peer_graph = TRUE; } break; case 'macaccounting_bits': case 'macaccounting_pkts': //FIXME. I really still not know it works or not? -- mike // This part copy-pasted from old code as is $acc = dbFetchRow("SELECT * FROM `mac_accounting` AS M\n LEFT JOIN `ip_mac` AS I ON M.mac = I.mac_address\n LEFT JOIN `ports` AS P ON P.port_id = M.port_id\n LEFT JOIN `devices` AS D ON D.device_id = P.device_id\n WHERE I.ip_address = ?", array($peer['bgpPeerRemoteAddr'])); $database = get_rrd_path($device, "cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); if (is_array($acc) && is_file($database)) { $peer_graph = TRUE; $graph_array['id'] = $acc['ma_id']; $graph_array['type'] = $vars['graph']; } break; } if ($peer_graph) { $graph_array['to'] = $config['time']['now']; $string .= ' <tr class="' . $peer['html_row_class'] . '">' . PHP_EOL; $string .= ' <td class="state-marker"></td><td colspan="10" style="white-space: nowrap">' . PHP_EOL; $string .= generate_graph_row($graph_array); $string .= ' </td>' . PHP_EOL . ' </tr>' . PHP_EOL; } else { if ($list['graph']) { // Empty row for correct view class table-striped-two $string .= ' <tr class="' . $peer['html_row_class'] . '"><td class="state-marker"></td><td colspan="10"></td></tr>' . PHP_EOL; } } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; $string .= generate_box_close(); // Print pagination header if ($entries['pagination_html']) { $string = $entries['pagination_html'] . $string . $entries['pagination_html']; } // Print echo $string; } }
$datefrom = $day_data['0']; $dateto = $day_data['1']; # $rate_data = getRates($bill['bill_id'],$datefrom,$dateto); $rate_data = $bill; $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; $total_data = $rate_data['total_data']; $rate_average = $rate_data['rate_average']; if ($bill['bill_type'] == "cdr") { $type = "CDR"; $allowed = format_si($bill['bill_cdr']) . "bps"; $used = format_si($rate_data['rate_95th']) . "bps"; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); $background = get_percentage_colours($percent); $overuse = $rate_data['rate_95th'] - $bill['bill_cdr']; $overuse = $overuse <= 0 ? "-" : "<span style=\"color: #" . $background['left'] . "; font-weight: bold;\">" . format_si($overuse) . "bps</span>"; } elseif ($bill['bill_type'] == "quota") { $type = "Quota"; $allowed = format_bytes_billing($bill['bill_quota']); $used = format_bytes_billing($rate_data['total_data']); $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); $background = get_percentage_colours($percent); $overuse = $rate_data['total_data'] - $bill['bill_quota']; $overuse = $overuse <= 0 ? "-" : "<span style=\"color: #" . $background['left'] . "; font-weight: bold;\">" . format_bytes_billing($overuse) . "</span>"; } $right_background = $background['right']; $left_background = $background['left']; if (!is_integer($i / 2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b;
$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 /> # " . $paidrate_text . " <br /> # " . $total_data . "MB transfered in the current billing cycle. <br /> # " . $rate_average . "Kbps Average during the current billing cycle. </p> # <font face=\"Trebuchet MS, Verdana, Arial, Sans-Serif\" color=" . $bill_color . "><B>" . $rate_95th . "Kbps @ 95th Percentile.</b> (" . $dir_95th . ") (" . $bill_text . ")</font> # </td><td><img src=\"images/billing-key.png\"></td></tr></table> # <br />"); } $lastmonth = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))"); $yesterday = dbFetchCell("SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))"); $rightnow = date(U); if ($vars['view'] == "accurate") { $bi = "<img src='billing-graph.php?bill_id=" . $bill_id . "&bill_code=" . $_GET['bill_code'];
<?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'; ?> <td> <?php echo format_si($rate_95th); ?> of <?php echo format_si($cdr) . 'bps (' . $percent . '%)'; ?> (95th%ile) </td> <td style="width: 210px;"> <?php echo print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']); ?> </td> <?php } } //end if ?> </tr>
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));
function generate_p2pradio_row($radio, $vars) { global $config; $table_cols = 12; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $table_cols++; } // Add a column for device. $row .= '<tr class="' . $radio['row_class'] . '"> <td class="state-marker"></td> <td></td>'; if ($vars['page'] != "device" && $vars['popup'] != TRUE) { $row .= '<td class="entity">' . generate_device_link($radio) . '</td>'; } $row .= ' <td class="entity">' . generate_entity_link('p2pradio', $radio) . '</td> <td width="100"><span class="label">' . strtoupper($radio['radio_modulation']) . '</span></td> <td width="90">' . format_si($radio['radio_cur_capacity']) . 'bps</td> <td width="100">' . format_si($radio['radio_total_capacity']) . 'bps</td> <td width="90">' . format_si($radio['radio_eth_capacity']) . 'bps</td> <td width="70">' . ($radio['radio_e1t1_channels'] ?: "N/A") . '</td> <td width="70"><span class="label label-error">' . $radio['radio_tx_power'] . 'dBm</span></td> <td width="70"><span class="label label-warning">' . $radio['radio_rx_level'] . 'dBm</span></td> <td width="90"><span class="label label-success">' . $radio['radio_tx_freq'] / 1000000 . 'GHz</span></td> <td width="90"><span class="label label-info">' . $radio['radio_rx_freq'] / 1000000 . 'GHz</span></td> '; $row .= '</tr>'; if ($vars['view'] == "graphs") { $graphs = array('capacity', 'power', 'rxlevel', 'gain', 'rmse', 'symbol_rates'); $show_graph_title = TRUE; } elseif (isset($vars['graph'])) { $graphs = explode(",", $vars['graph']); } if (is_array($graphs)) { $row .= '<tr class="' . $radio['row_class'] . '">'; $row .= '<td class="state-marker"></td>'; $row .= '<td colspan=' . $table_cols . '>'; unset($graph_array['height'], $graph_array['width'], $graph_array['legend']); $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $radio['radio_id']; foreach ($graphs as $graph_type) { $graph_array['type'] = 'p2pradio_' . $graph_type; if ($show_graph_title) { $row .= '<h3>' . $config['graph_types']['p2pradio'][$graph_type]['name'] . '</h3>'; } $row .= generate_graph_row($graph_array, TRUE); } $row .= "</td>"; $row .= "</tr>"; } return $row; }
//$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); } } else { print_message("Port Disabled."); } //echo("\n");
$graph_type = "bgp_updates"; $peer_daily_url = "graph.php?id=" . $peer['bgpPeer_id'] . "&type=" . $graph_type . "&from=" . $config['time']['day'] . "&to=" . $config['time']['now'] . "&width=500&height=150"; $peeraddresslink = "<span class=list-large><a href='device/device=" . $peer['device_id'] . "/tab=routing/proto=bgp/' onmouseover=\"return overlib('<img src=\\'{$peer_daily_url}\\'>', LEFT" . $config['overlib_defaults'] . ");\" onmouseout=\"return nd();\">" . $peer['bgpPeerIdentifier'] . "</a></span>"; echo '<tr class="bgp"' . ($peer['alert'] ? ' bordercolor="#cc0000"' : '') . ($peer['disabled'] ? ' bordercolor="#cccccc"' : '') . ">"; unset($sep); foreach (dbFetchRows("SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?", array($peer['device_id'], $peer['bgpPeerIdentifier'])) as $afisafi) { $afi = $afisafi['afi']; $safi = $afisafi['safi']; $this_afisafi = $afi . $safi; $peer['afi'] .= $sep . $afi . "." . $safi; $sep = "<br />"; $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } unset($sep); echo " <td></td>\n <td width=150>" . $localaddresslink . "<br />" . generate_device_link($peer, shorthost($peer['hostname']), array('tab' => 'routing', 'proto' => 'bgp')) . "</td>\n <td width=30><b>»</b></td>\n <td width=150>" . $peeraddresslink . "</td>\n <td width=50><b>{$peer_type}</b></td>\n <td width=50>" . $peer['afi'] . "</td>\n <td><strong>AS" . $peer['bgpPeerRemoteAs'] . "</strong><br />" . $peer['astext'] . "</td>\n <td><strong><span style='color: {$admin_col};'>" . $peer['bgpPeerAdminStatus'] . "</span><br /><span style='color: {$col};'>" . $peer['bgpPeerState'] . "</span></strong></td>\n <td>" . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "<br />\n Updates <img src='images/16/arrow_down.png' align=absmiddle /> " . format_si($peer['bgpPeerInUpdates']) . "\n <img src='images/16/arrow_up.png' align=absmiddle /> " . format_si($peer['bgpPeerOutUpdates']) . "</td></tr>"; unset($invalid); switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': list(, $afisafi) = explode("_", $vars['graph']); if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } case 'updates': $graph_array['type'] = "bgp_" . $vars['graph']; $graph_array['id'] = $peer['bgpPeer_id']; }
if (bill_permitted($bill['bill_id'])) { $datefrom = $bill['bill_datefrom']; $dateto = $bill['bill_dateto']; unset($class); $type = $bill['bill_type']; $percent = $bill['bill_percent']; $dir_95th = $bill['dir_95th']; $rate_95th = format_si($bill['rate_95th']) . 'bps'; $total_data = format_bytes_billing($bill['traf_total']); $background = get_percentage_colours($percent); if ($type == 'CDR') { $allowed = format_si($bill['bill_allowed']) . 'bps'; $used = format_si($bill['rate_95th']) . 'bps'; $in = format_si($bill['rate_95th_in']) . 'bps'; $out = format_si($bill['rate_95th_out']) . 'bps'; $overuse = $bill['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . format_si($bill['bill_overuse']) . 'bps</span>'; } else { if ($type == 'Quota') { $allowed = format_bytes_billing($bill['bill_allowed']); $used = format_bytes_billing($bill['total_data']); $in = format_bytes_billing($bill['traf_in']); $out = format_bytes_billing($bill['traf_out']); $overuse = $bill['bill_overuse'] <= 0 ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . format_bytes_billing($bill['bill_overuse']) . '</span>'; } } $total_data = $type == 'Quota' ? '<b>' . $total_data . '</b>' : $total_data; $rate_95th = $type == 'CDR' ? '<b>' . $rate_95th . '</b>' : $rate_95th; echo "\n <tr>\n <td><a href=\"" . generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $bill['bill_hist_id'])) . '"><span style="font-weight: bold;" class="interface">' . $bill['bill_name'] . '</a></span><br />from ' . strftime('%x', strtotime($datefrom)) . ' to ' . strftime('%x', strtotime($dateto)) . "</td>\n <td>{$type}</td>\n <td>{$allowed}</td>\n <td>{$in}</td>\n <td>{$out}</td>\n <td>{$total_data}</td>\n <td>{$rate_95th}</td>\n <td style=\"text-align: center;\">{$overuse}</td>\n <td>" . print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']) . '</td> </tr>'; } //end if
function pagination(&$vars, $total, $return_vars = FALSE) { $pagesizes = array(10, 20, 50, 100, 500, 1000, 10000, 50000); // Permitted pagesizes if (is_numeric($vars['pagesize'])) { $per_page = (int) $vars['pagesize']; } else { if (isset($_SESSION['pagesize'])) { $per_page = $_SESSION['pagesize']; } else { $per_page = $GLOBALS['config']['web_pagesize']; } } if (!$vars['short']) { // Permit fixed pagesizes only (except $vars['short'] == TRUE) foreach ($pagesizes as $pagesize) { if ($per_page <= $pagesize) { $per_page = $pagesize; break; } } if (isset($vars['pagesize']) && $vars['pagesize'] != $_SESSION['pagesize']) { if ($vars['pagesize'] != $GLOBALS['config']['web_pagesize']) { $_SESSION['pagesize'] = $per_page; // Store pagesize in session only if changed default } else { if (isset($_SESSION['pagesize'])) { unset($_SESSION['pagesize']); // Reset pagesize from session } } } } $vars['pagesize'] = $per_page; // Return back current pagesize $page = (int) $vars['pageno']; $lastpage = ceil($total / $per_page); if ($page < 1) { $page = 1; } else { if (!$return_vars && $lastpage < $page) { $page = (int) $lastpage; } } $vars['pageno'] = $page; // Return back current pageno if ($return_vars) { return ''; } // Silent exit (needed for detect default pagesize/pageno) $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lpm1 = $lastpage - 1; $adjacents = 3; $pagination = ''; if ($total > 99 || $total > $per_page) { if ($total > 9999) { $total_text = format_si($total); } else { $total_text = $total; } $pagination .= '<div class="row">' . PHP_EOL . ' <div class="col-lg-1 col-md-2 col-sm-2" style="display: inline-block;">' . PHP_EOL . ' <div class="box box-solid" style="padding: 4px 12px;">' . $total_text . ' Items</div>' . PHP_EOL . ' </div>' . PHP_EOL . ' <div class="col-lg-10 col-md-8 col-sm-8">' . PHP_EOL . ' <div class="pagination pagination-centered"><ul>' . PHP_EOL; if ($prev) { //$pagination .= ' <li><a href="'.generate_url($vars, array('pageno' => 1)).'">First</a></li>' . PHP_EOL; $pagination .= ' <li><a href="' . generate_url($vars, array('pageno' => $prev)) . '">Prev</a></li>' . PHP_EOL; } if ($lastpage < 7 + $adjacents * 2) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "<li class='active'><a>{$counter}</a></li>"; } else { $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $counter)) . "'>{$counter}</a></li>"; } } } elseif ($lastpage > 5 + $adjacents * 2) { if ($page < 1 + $adjacents * 2) { for ($counter = 1; $counter < 4 + $adjacents * 2; $counter++) { if ($counter == $page) { $pagination .= "<li class='active'><a>{$counter}</a></li>"; } else { $class = ''; //if ($counter > 9) //{ // $class = ' class="hidden-md hidden-sm hidden-xs"'; //} //else if ($counter > 6) //{ // $class = ' class="hidden-sm hidden-xs"'; //} $pagination .= "<li{$class}><a href='" . generate_url($vars, array('pageno' => $counter)) . "'>{$counter}</a></li>"; } } $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $lpm1)) . "'>{$lpm1}</a></li>"; $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $lastpage)) . "'>{$lastpage}</a></li>"; } elseif ($lastpage - $adjacents * 2 > $page && $page > $adjacents * 2) { $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => '1')) . "'>1</a></li>"; $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => '2')) . "'>2</a></li>"; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) { $pagination .= "<li class='active'><a>{$counter}</a></li>"; } else { $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $counter)) . "'>{$counter}</a></li>"; } } $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $lpm1)) . "'>{$lpm1}</a></li>"; $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $lastpage)) . "'>{$lastpage}</a></li>"; } else { $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => '1')) . "'>1</a></li>"; $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => '2')) . "'>2</a></li>"; for ($counter = $lastpage - (2 + $adjacents * 2); $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "<li class='active'><a>{$counter}</a></li>"; } else { $class = ''; //if ($lastpage - $counter > 9) //{ // $class = ' class="hidden-md hidden-sm hidden-xs"'; //} //else if ($lastpage - $counter > 6) //{ // $class = ' class="hidden-sm hidden-xs"'; //} $pagination .= "<li{$class}><a href='" . generate_url($vars, array('pageno' => $counter)) . "'>{$counter}</a></li>"; } } } } if ($page < $counter - 1) { $pagination .= "<li><a href='" . generate_url($vars, array('pageno' => $next)) . "'>Next</a></li>"; # No need for "Last" as we don't have "First", 1, 2 and the 2 last pages are always in the list. #$pagination.= "<li><a href='".generate_url($vars, array('pageno' => $lastpage))."'>Last</a></li>"; } else { if ($lastpage > 1) { $pagination .= "<li class='active'><a>Next</a></li>"; #$pagination.= "<li class='active'><a>Last</a></li>"; } } $pagination .= "</ul></div></div>"; //$values = array('' => array('name')) foreach ($pagesizes as $pagesize) { $value = generate_url($vars, array('pagesize' => $pagesize, 'pageno' => floor($start / $pagesize))); $name = $pagesize == $GLOBALS['config']['web_pagesize'] ? "[ {$pagesize} ]" : $pagesize; $values[$value] = array('name' => $name, 'class' => 'text-center'); } $element = array('type' => 'select', 'id' => 'pagesize', 'name' => '# ' . $per_page, 'width' => '90px', 'onchange' => "window.open(this.options[this.selectedIndex].value,'_top')", 'value' => $per_page, 'data-style' => 'box', 'values' => $values); $pagination .= ' <div class="col-lg-1 col-md-2 col-sm-2"> <form class="pull-right" action="#">'; $pagination .= generate_form_element($element); $pagination .= '</form></div></div>'; } return $pagination; }
function formatRates($rate) { $rate = format_si($rate) . "bps"; return $rate; }
function format_number($value, $base = '1000', $round = 2, $sf = 3) { if ($base == '1000') { return format_si($value, $round, $sf); } else { return format_bi($value, $round, $sf); } }
if (is_integer($i / 2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; } if ($svc['svc_state'] == "up") { $svc_class = "green"; } else { $svc_class = "red"; } echo "<tr bgcolor='{$bg_colour}'>"; echo '<td width=320 class=object-name><a href="' . generate_url($vars, array('svc' => $svc['svc_id'], 'view' => NULL, 'graph' => NULL)) . '">' . $svc['svc_label'] . '</a></td>'; echo "<td width=320>" . $svc['svc_ip'] . ":" . $svc['svc_port'] . "</a></td>"; echo "<td width=100><span class='" . $svc_class . "'>" . $svc['svc_state'] . "</span></td>"; echo "<td width=320>" . format_si($svc['svc_bps_in'] * 8) . "bps</a></td>"; echo "<td width=320>" . format_si($svc['svc_bps_out'] * 8) . "bps</a></td>"; echo "</tr>"; if ($vars['view'] == "graphs") { echo '<tr class="entity" bgcolor="' . $bg_colour . '">'; echo '<td style="padding: 0px;" colspan="5">'; $graph_type = "netscalersvc_" . $vars['graph']; $graph_array['to'] = $config['time']['now']; $graph_array['id'] = $svc['svc_id']; $graph_array['type'] = $graph_type; print_graph_row($graph_array); echo "\n </td>\n </tr>"; } echo "</td>"; echo "</tr>"; $i++; }
function list_bills() { global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $status = 'ok'; $err_msg = ''; $message = ''; $code = 200; $bills = array(); $bill_id = mres($router['bill_id']); $bill_ref = mres($_GET['ref']); $bill_custid = mres($_GET['custid']); if (!empty($bill_custid)) { $sql = '`bill_custid` = ?'; $param = array($bill_custid); } elseif (!empty($bill_ref)) { $sql = '`bill_ref` = ?'; $param = array($bill_ref); } elseif (is_numeric($bill_id)) { $sql = '`bill_id` = ?'; $param = array($bill_id); } else { $sql = ''; $param = array(); } if (count($param) >= 1) { $sql = "WHERE {$sql}"; } foreach (dbFetchRows("SELECT `bills`.*,COUNT(port_id) AS `ports_total` FROM `bills` LEFT JOIN `bill_ports` ON `bill_ports`.`bill_id`=`bills`.`bill_id` {$sql} GROUP BY `bill_name`,`bill_ref` ORDER BY `bill_name`", $param) as $bill) { $rate_data = $bill; $allowed = ''; $used = ''; $percent = ''; $overuse = ''; if ($bill['bill_type'] == "cdr") { $allowed = format_si($bill['bill_cdr']) . "bps"; $used = format_si($rate_data['rate_95th']) . "bps"; $percent = round($rate_data['rate_95th'] / $bill['bill_cdr'] * 100, 2); $overuse = $rate_data['rate_95th'] - $bill['bill_cdr']; $overuse = $overuse <= 0 ? "-" : format_si($overuse); } elseif ($bill['bill_type'] == "quota") { $allowed = format_bytes_billing($bill['bill_quota']); $used = format_bytes_billing($rate_data['total_data']); $percent = round($rate_data['total_data'] / $bill['bill_quota'] * 100, 2); $overuse = $rate_data['total_data'] - $bill['bill_quota']; $overuse = $overuse <= 0 ? "-" : format_bytes_billing($overuse); } $bill['allowed'] = $allowed; $bill['used'] = $used; $bill['percent'] = $percent; $bill['overuse'] = $overuse; $bills[] = $bill; } $count = count($bills); $output = array('status' => $status, 'message' => $message, 'err-msg' => $err_msg, 'count' => $count, 'bills' => $bills); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
$sensor_threshold_low = format_si($sensor['sensor_limit_low']) . $sensor['sensor_symbol']; break; default: $sensor_threshold_low = $sensor['sensor_limit_low'] . $sensor['sensor_symbol']; } } else { $sensor_threshold_low = "∞"; } if ($sensor['sensor_limit'] != NULL) { switch ($sensor['sensor_class']) { case 'frequency': case 'voltage': case 'current': case 'apower': case 'power': $sensor_threshold_high = format_si($sensor['sensor_limit']) . $sensor['sensor_symbol']; break; default: $sensor_threshold_high = $sensor['sensor_limit'] . $sensor['sensor_symbol']; } } else { $sensor_threshold_high = "∞"; } $sensor_misc = $sensor_threshold_low . ' - ' . $sensor_threshold_high; } echo '<tr class="' . $sensor['html_row_class'] . '"> <td class="entity">' . generate_device_link($sensor) . '</td> <td>' . overlib_link($link, htmlentities($sensor['sensor_descr']), $overlib_content) . '</td> <td class="text-right"><i class="' . $alert . '"></i></td> <td>' . $sensor_minigraph . '</td> <td><strong>' . overlib_link($link, '<span class="' . $sensor['state_class'] . '">' . $sensor_value . $sensor['sensor_symbol'] . '</span>', $overlib_content) . '</strong></td>