rewrote shorthost function, made some php warnings go away (when using 'use strict' equivalent ;)

git-svn-id: http://www.observium.org/svn/observer/trunk@701 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-01-16 23:16:58 +00:00
parent 90c79bd539
commit 96d5c322b3
6 changed files with 21 additions and 27 deletions
+3 -3
View File
@@ -6,13 +6,13 @@
// Array of paths when collectd's rrdtool plugin writes RRDs
$config['datadirs'] = array('/var/lib/collectd/rrd/');
// Width of graph to be generated by rrdgraph
if($_GET['width']) {
if(isset($_GET['width'])) {
$config['rrd_width'] = $_GET['width'];
} else {
$config['rrd_width'] = 270;
}
// Height of graph to be generated by rrdgraph
if($_GET['height']) {
if(isset($_GET['height'])) {
$config['rrd_height'] = $_GET['height'];
} else {
$config['rrd_height'] = 120;
@@ -29,7 +29,7 @@ $config['rrd_interval'] = 10;
// Average rows/rra (currently ignored)
$config['rrd_rows'] = 2400;
// Additional options to pass to rrdgraph
$config['rrd_opts'] = $config['rrdgraph_defaults'];
$config['rrd_opts'] = (isset($config['rrdgraph_defaults']) ? $config['rrdgraph_defaults'] : '');
#$config['rrd_opts'] = array('-E', "-c", "SHADEA#a5a5a5", "-c", "SHADEB#a5a5a5", "-c", "FONT#000000", "-c", "CANVAS#FFFFFF", "-c", "GRID#aaaaaa",
# "-c", "MGRID#FFAAAA", "-c", "FRAME#3e3e3e", "-c", "ARROW#5e5e5e", "-R", "normal");
// Predefined set of colors for use by collectd_draw_rrd()
+12 -18
View File
@@ -72,19 +72,13 @@ function write_dev_attrib($device_id, $attrib_type, $attrib_value) {
}
function shorthost($hostname, $len=16) {
list ($first, $second, $third, $fourth, $fifth) = explode(".", $hostname);
$shorthost = $first;
if(strlen($first.".".$second) < $len && $second) {
$shorthost = $first.".".$second;
if(strlen($shorthost.".".$third) < $len && $third) {
$shorthost = $shorthost.".".$third;
if(strlen($shorthost.".".$fourth) < $len && $fourth) {
$shorthost = $shorthost.".".$fourth;
if(strlen($shorthost.".".$fifth) < $len && $fifth) {
$shorthost = $shorthost.".".$fifth;
}
}
}
$parts = explode(".", $hostname);
$shorthost = $parts[0];
$i=1;
while ($i < count($parts) && strlen($shorthost.'.'.$parts[$i]) < $len)
{
$shorthost = $shorthost.'.'.$parts[$i];
$i++;
}
return ($shorthost);
}
@@ -281,12 +275,12 @@ function geteventicon ($message)
if($icon) { return $icon; } else { return false; }
}
function generateiflink($interface, $text=0,$type)
function generateiflink($interface, $text=0, $type = '')
{
global $twoday; global $now; global $config; global $day; global $month;
$interface = ifNameDescr($interface);
if(!$text) { $text = fixIfName($interface['label']); }
if($type) { $interface['graph_type'] = $type; }
if(isset($type)) { $interface['graph_type'] = $type; }
if(!$interface['graph_type']) { $interface['graph_type'] = 'port_bits'; }
$class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
$graph_url = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&amp;from=$day&amp;to=$now&amp;width=400&amp;height=100&amp;type=" . $interface['graph_type'];
@@ -325,10 +319,10 @@ function device_traffic_image($device, $width, $height, $from, $to)
function devclass($device)
{
if ($device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; }
if ($device['ignore'] == '1') {
if (isset($device['status']) && $device['status'] == '0') { $class = "list-device-down"; } else { $class = "list-device"; }
if (isset($device['ignore']) &&$device['ignore'] == '1') {
$class = "list-device-ignored";
if ($device['status'] == '1') { $class = "list-device-ignored-up"; }
if (isset($device['status']) && $device['status'] == '1') { $class = "list-device-ignored-up"; }
}
return $class;
}
+1 -1
View File
@@ -10,7 +10,7 @@ function ifNameDescr ($interface, $device = NULL) {
global $config;
if(!$device) { $device = device_array($interface['device_id']); }
$os = strtolower($device['os']);
if($config['ifname'][$os]) {
if(isset($config['ifname'][$os])) {
$interface['label'] = $interface['ifDescr'];
} else {
$interface['label'] = $interface['ifName'];