mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
ports sort done in php
git-svn-id: http://www.observium.org/svn/observer/trunk@3238 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -1,5 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observium
|
||||||
|
*
|
||||||
|
* This file is part of Observium.
|
||||||
|
*
|
||||||
|
* @package observium
|
||||||
|
* @subpackage functions
|
||||||
|
* @author Adam Armstrong <adama@memetic.org>
|
||||||
|
* @copyright (C) 2006 - 2012 Adam Armstrong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
include("../includes/alerts.inc.php");
|
include("../includes/alerts.inc.php");
|
||||||
|
|
||||||
function data_uri($file, $mime)
|
function data_uri($file, $mime)
|
||||||
@@ -9,6 +21,23 @@ function data_uri($file, $mime)
|
|||||||
return ('data:' . $mime . ';base64,' . $base64);
|
return ('data:' . $mime . ';base64,' . $base64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nicecase($item)
|
||||||
|
{
|
||||||
|
switch ($item)
|
||||||
|
{
|
||||||
|
case "dbm":
|
||||||
|
return "dBm";
|
||||||
|
case "mysql":
|
||||||
|
return" MySQL";
|
||||||
|
case "powerdns":
|
||||||
|
return "PowerDNS";
|
||||||
|
case "bind":
|
||||||
|
return "BIND";
|
||||||
|
default:
|
||||||
|
return ucfirst($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function toner2colour($descr, $percent)
|
function toner2colour($descr, $percent)
|
||||||
{
|
{
|
||||||
$colour = get_percentage_colours(100-$percent);
|
$colour = get_percentage_colours(100-$percent);
|
||||||
|
|||||||
@@ -298,46 +298,6 @@ foreach ($vars as $var => $value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($vars['sort'])
|
|
||||||
{
|
|
||||||
case 'traffic':
|
|
||||||
$query_sort = " ORDER BY (I.ifInOctets_rate+I.ifOutOctets_rate) DESC";
|
|
||||||
break;
|
|
||||||
case 'traffic_in':
|
|
||||||
$query_sort = " ORDER BY I.ifInOctets_rate DESC";
|
|
||||||
break;
|
|
||||||
case 'traffic_out':
|
|
||||||
$query_sort = " ORDER BY I.ifOutOctets_rate DESC";
|
|
||||||
break;
|
|
||||||
case 'packets':
|
|
||||||
$query_sort = " ORDER BY (I.ifInUcastPkts_rate+I.ifOutUcastPkts_rate) DESC";
|
|
||||||
break;
|
|
||||||
case 'packets_in':
|
|
||||||
$query_sort = " ORDER BY I.ifInUcastPkts_rate DESC";
|
|
||||||
break;
|
|
||||||
case 'packets_out':
|
|
||||||
$query_sort = " ORDER BY I.ifOutUcastPkts_rate DESC";
|
|
||||||
break;
|
|
||||||
case 'errors':
|
|
||||||
$query_sort = " ORDER BY (I.ifInErrors + I.ifOutErrors) DESC";
|
|
||||||
break;
|
|
||||||
case 'speed':
|
|
||||||
$query_sort = " ORDER BY (I.ifSpeed) DESC";
|
|
||||||
break;
|
|
||||||
case 'port':
|
|
||||||
$query_sort = " ORDER BY (I.ifDescr) ASC";
|
|
||||||
break;
|
|
||||||
case 'media':
|
|
||||||
$query_sort = " ORDER BY (I.ifType) ASC";
|
|
||||||
break;
|
|
||||||
case 'descr':
|
|
||||||
$query_sort = " ORDER BY (I.ifAlias) ASC";
|
|
||||||
break;
|
|
||||||
case 'device':
|
|
||||||
default:
|
|
||||||
$query_sort = " ORDER BY D.hostname, I.ifIndex ASC";
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort;
|
$query = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ".$where." ".$query_sort;
|
||||||
|
|
||||||
$row = 1;
|
$row = 1;
|
||||||
@@ -346,6 +306,61 @@ list($format, $subformat) = explode("_", $vars['format']);
|
|||||||
|
|
||||||
$ports = dbFetchRows($query, $param);
|
$ports = dbFetchRows($query, $param);
|
||||||
|
|
||||||
|
### FIXME - only populate what we need to search at this point, because we shouldn't show *all* ports, as it's silly.
|
||||||
|
|
||||||
|
foreach ($ports as $p)
|
||||||
|
{
|
||||||
|
if ($config['memcached']['enable'])
|
||||||
|
{
|
||||||
|
$oids = array('ifInOctets', 'ifOutOctets', 'ifInUcastPkts', 'ifOutUcastPkts', 'ifInErrors', 'ifOutErrors');
|
||||||
|
foreach ($oids as $oid)
|
||||||
|
{
|
||||||
|
$ports[$port['port_id']][$oid.'_rate'] = $memcache->get('port-'.$port['port_id'].'-'.$oid.'_rate');
|
||||||
|
if ($debug) { echo("MC[".$oid."->".$port[$oid.'_rate']."]"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($vars['sort'])
|
||||||
|
{
|
||||||
|
case 'traffic':
|
||||||
|
$ports = array_sort($ports, 'ifOctets_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
case 'traffic_in':
|
||||||
|
$ports = array_sort($ports, 'ifInOctets_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
case 'traffic_out':
|
||||||
|
$ports = array_sort($ports, 'ifOutOctets_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
case 'packets':
|
||||||
|
$ports = array_sort($ports, 'ifUcastPkts_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
case 'packets_in':
|
||||||
|
$ports = array_sort($ports, 'ifInUcastOctets_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
case 'packets_out':
|
||||||
|
$ports = array_sort($ports, 'ifOutUcastOctets_rate', SORT_DESC);
|
||||||
|
break;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
if(file_exists('pages/ports/'.$format.'.inc.php'))
|
if(file_exists('pages/ports/'.$format.'.inc.php'))
|
||||||
{
|
{
|
||||||
include('pages/ports/'.$format.'.inc.php');
|
include('pages/ports/'.$format.'.inc.php');
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ foreach ($ports as $port)
|
|||||||
$port = ifLabel($port, $device);
|
$port = ifLabel($port, $device);
|
||||||
echo("<tr class='ports'>
|
echo("<tr class='ports'>
|
||||||
<td width=5></td>
|
<td width=5></td>
|
||||||
<td width=200 class=list-bold><a href='" . generate_device_url($port) . "'>".$port['hostname']."</a></td>
|
<td width=200 class=list-bold>".generate_device_link($port, shorthost($port['hostname'], "20"))."</td>
|
||||||
<td width=150 class=list-bold><a class='".$ifclass."'href='" . generate_port_url($port) . "'>".fixIfName($port['label'])." $error_img</td>
|
<td width=150 class=list-bold><a class='".$ifclass."'href='" . generate_port_url($port) . "'>".fixIfName($port['label'])." $error_img</td>
|
||||||
<td width=110 >$speed</td>
|
<td width=110 >$speed</td>
|
||||||
<td width=100 class=green>".$port['in_rate']."</td>
|
<td width=100 class=green>".$port['in_rate']."</td>
|
||||||
|
|||||||
@@ -36,22 +36,39 @@ if ($config['alerts']['email']['enable'])
|
|||||||
include_once($config['install_dir'] . "/includes/phpmailer/class.smtp.php");
|
include_once($config['install_dir'] . "/includes/phpmailer/class.smtp.php");
|
||||||
}
|
}
|
||||||
|
|
||||||
function nicecase($item)
|
function array_sort($array, $on, $order=SORT_ASC)
|
||||||
{
|
{
|
||||||
switch ($item)
|
$new_array = array();
|
||||||
{
|
$sortable_array = array();
|
||||||
case "dbm":
|
|
||||||
return "dBm";
|
if (count($array) > 0) {
|
||||||
case "mysql":
|
foreach ($array as $k => $v) {
|
||||||
return" MySQL";
|
if (is_array($v)) {
|
||||||
case "powerdns":
|
foreach ($v as $k2 => $v2) {
|
||||||
return "PowerDNS";
|
if ($k2 == $on) {
|
||||||
case "bind":
|
$sortable_array[$k] = $v2;
|
||||||
return "BIND";
|
|
||||||
default:
|
|
||||||
return ucfirst($item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$sortable_array[$k] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($order) {
|
||||||
|
case SORT_ASC:
|
||||||
|
asort($sortable_array);
|
||||||
|
break;
|
||||||
|
case SORT_DESC:
|
||||||
|
arsort($sortable_array);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($sortable_array as $k => $v) {
|
||||||
|
$new_array[$k] = $array[$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $new_array;
|
||||||
|
}
|
||||||
|
|
||||||
function mac_clean_to_readable($mac)
|
function mac_clean_to_readable($mac)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ if ($serial && $serial != $device['serial'])
|
|||||||
if ($icon && $icon != $device['icon'])
|
if ($icon && $icon != $device['icon'])
|
||||||
{
|
{
|
||||||
$update_array['icon'] = $icon;
|
$update_array['icon'] = $icon;
|
||||||
log_event("Icon -> ".nicecase($icon), $device, 'system');
|
log_event("Icon -> ".$icon, $device, 'system');
|
||||||
}
|
}
|
||||||
|
|
||||||
echo("\nHardware: ".$hardware." Version: ".$version." Features: ".$features." Serial: ".$serial."\n");
|
echo("\nHardware: ".$hardware." Version: ".$version." Features: ".$features." Serial: ".$serial."\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user