From 08952e40c61fc47caccafedd73b828591eec1dea Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Mon, 9 Apr 2012 23:00:31 +0000 Subject: [PATCH] show toner on device overview (beta), minor fixes git-svn-id: http://www.observium.org/svn/observer/trunk@3014 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/includes/functions.inc.php | 15 ++++ html/includes/graphs/device/toner.inc.php | 61 ++++++++-------- html/includes/graphs/toner/usage.inc.php | 19 ++--- html/pages/device/overview.inc.php | 9 +-- html/pages/device/overview/toner.inc.php | 69 +++++++++++++++++++ .../discovery/cisco-entity-sensor.inc.php | 2 +- includes/discovery/entity-sensor.inc.php | 2 +- includes/functions.php | 5 +- 8 files changed, 129 insertions(+), 53 deletions(-) create mode 100644 html/pages/device/overview/toner.inc.php diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 538ca56e5c..ca77e1ba69 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -1,5 +1,20 @@ '.$text.''; diff --git a/html/includes/graphs/device/toner.inc.php b/html/includes/graphs/device/toner.inc.php index a614a78c59..2781448d54 100644 --- a/html/includes/graphs/device/toner.inc.php +++ b/html/includes/graphs/device/toner.inc.php @@ -10,40 +10,39 @@ $iter = "1"; $rrd_options .= " COMMENT:'Toner level Cur Min Max\\n'"; foreach (dbFetchRows("SELECT * FROM toner where device_id = ?", array($id)) as $toner) { - # FIXME generic colour function - switch ($iter) + $colour = toner2colour($toner['toner_descr']); + + if ($colour == NULL) { - case "1": - $colour= "000000"; - break; - case "2": - $colour= "008C00"; - break; - case "3": - $colour= "4096EE"; - break; - case "4": - $colour= "73880A"; - break; - case "5": - $colour= "D01F3C"; - break; - case "6": - $colour= "36393D"; - break; - case "7": - default: - $colour= "FF0000"; - unset($iter); - break; + # FIXME generic colour function + switch ($iter) + { + case "1": + $colour= "000000"; + break; + case "2": + $colour= "008C00"; + break; + case "3": + $colour= "4096EE"; + break; + case "4": + $colour= "73880A"; + break; + case "5": + $colour= "D01F3C"; + break; + case "6": + $colour= "36393D"; + break; + case "7": + default: + $colour= "FF0000"; + unset($iter); + break; + } } - if (stripos($toner['toner_descr'],"cyan" ) !== false || substr($toner['toner_descr'],-1) == 'C') { $colour = "55D6D3"; } - if (stripos($toner['toner_descr'],"magenta") !== false || substr($toner['toner_descr'],-1) == 'M') { $colour = "F24AC8"; } - if (stripos($toner['toner_descr'],"yellow" ) !== false || substr($toner['toner_descr'],-1) == 'Y' || stripos($toner['toner_descr'],"giallo" ) !== false) { $colour = "FFF200"; } - if (stripos($toner['toner_descr'],"black" ) !== false || substr($toner['toner_descr'],-1) == 'K' || stripos($toner['toner_descr'],"nero" ) !== false) { $colour = "000000"; } - - $hostname = gethostbyid($toner['device_id']); $descr = substr(str_pad($toner['toner_descr'], 16),0,16); diff --git a/html/includes/graphs/toner/usage.inc.php b/html/includes/graphs/toner/usage.inc.php index 3eaa5f7546..fd6e989f79 100755 --- a/html/includes/graphs/toner/usage.inc.php +++ b/html/includes/graphs/toner/usage.inc.php @@ -4,20 +4,12 @@ $scale_max = "100"; include("includes/graphs/common.inc.php"); -$iter = "1"; +$rrd_options .= " COMMENT:' Cur Max\\n'"; -$rrd_options .= " COMMENT:' Cur Max\\n'"; +$colour = toner2colour($toner['toner_descr']); +if ($colour == NULL) { $colour="CC0000"; } -if ($iter=="1") { $colour="CC0000"; } elseif ($iter=="2") { $colour="008C00"; } elseif ($iter=="3") { $colour="4096EE"; } -elseif ($iter=="4") { $colour="73880A"; } elseif ($iter=="5") { $colour="D01F3C"; } elseif ($iter=="6") { $colour="36393D"; } -elseif ($iter=="7") { $colour="FF0084"; unset($iter); } - -$descr = substr(str_pad($toner['toner_descr']),0,28); - -if (stripos($toner['toner_descr'],"cyan" ) !== false || substr($toner['toner_descr'],-1) == 'C') { $colour = "55D6D3"; } -if (stripos($toner['toner_descr'],"magenta") !== false || substr($toner['toner_descr'],-1) == 'M') { $colour = "F24AC8"; } -if (stripos($toner['toner_descr'],"yellow" ) !== false || substr($toner['toner_descr'],-1) == 'Y') { $colour = "FFF200"; } -if (stripos($toner['toner_descr'],"black" ) !== false || substr($toner['toner_descr'],-1) == 'K') { $colour = "000000"; } +$descr = substr(str_pad($toner['toner_descr'],26),0,26); $background = get_percentage_colours(100-$toner['toner_current']); @@ -26,8 +18,7 @@ $rrd_options .= " DEF:toner" . $toner['toner_id'] . "=".$rrd_filename.":toner:AV $rrd_options .= " LINE1:toner" . $toner['toner_id'] . "#" . $colour . ":'" . $descr . "' "; $rrd_options .= " AREA:toner" . $toner['toner_id' ] . "#" . $background['right'] . ":"; -$rrd_options .= " GPRINT:toner" . $toner['toner_id'] . ":AVERAGE:'%5.0lf%%'"; -$rrd_options .= " GPRINT:toner" . $toner['toner_id'] . ":MIN:'%5.0lf%%'"; +$rrd_options .= " GPRINT:toner" . $toner['toner_id'] . ":LAST:'%5.0lf%%'"; $rrd_options .= " GPRINT:toner" . $toner['toner_id'] . ":MAX:%5.0lf%%\\\\l"; ?> diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index fc9c1ae270..394dce5e5d 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -48,10 +48,10 @@ if ($services['total']) foreach (dbFetchRows("SELECT * FROM services WHERE device_id = ? ORDER BY service_type", array($device['device_id'])) as $data) { - if ($data[service_status] == "0" && $data[service_ignore] == "1") { $status = "grey"; } - if ($data[service_status] == "1" && $data[service_ignore] == "1") { $status = "green"; } - if ($data[service_status] == "0" && $data[service_ignore] == "0") { $status = "red"; } - if ($data[service_status] == "1" && $data[service_ignore] == "0") { $status = "blue"; } + if ($data['service_status'] == "0" && $data['service_ignore'] == "1") { $status = "grey"; } + if ($data['service_status'] == "1" && $data['service_ignore'] == "1") { $status = "green"; } + if ($data['service_status'] == "0" && $data['service_ignore'] == "0") { $status = "red"; } + if ($data['service_status'] == "1" && $data['service_ignore'] == "0") { $status = "blue"; } echo("$break" . strtolower($data[service_type]) . ""); $break = ", "; } @@ -86,6 +86,7 @@ include("overview/storage.inc.php"); if(is_array($entity_state['group']['c6kxbar'])) { include("overview/c6kxbar.inc.php"); } +include("overview/toner.inc.php"); include("overview/sensors/temperatures.inc.php"); include("overview/sensors/humidity.inc.php"); include("overview/sensors/fanspeeds.inc.php"); diff --git a/html/pages/device/overview/toner.inc.php b/html/pages/device/overview/toner.inc.php new file mode 100644 index 0000000000..9ad298a9e7 --- /dev/null +++ b/html/pages/device/overview/toner.inc.php @@ -0,0 +1,69 @@ +"); + echo("

"); + echo(''); + echo(" Toner

"); + echo(""); + $toner_rows = '0'; + + foreach ($toners as $toner) + { + if (is_integer($toner_rows/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + $percent = round($toner['toner_current'], 0); + $total = formatStorage($toner['toner_size']); + $free = formatStorage($toner['toner_free']); + $used = formatStorage($toner['toner_used']); + + $background['left'] = toner2colour($toner['toner_descr']); + unset($background['right']); + for ($i = 0;$i < strlen($background['left']); $i++) + { + $new = dechex(hexdec("0x" . $background['left'][$i])+1); + if (strlen($new) != 1) { $new = 'F'; } + $background['right'] .= $new; + } + + $graph_array = array(); + $graph_array['height'] = "100"; + $graph_array['width'] = "210"; + $graph_array['to'] = $now; + $graph_array['id'] = $toner['toner_id']; + $graph_array['type'] = $graph_type; + $graph_array['from'] = $day; + $graph_array['legend'] = "no"; + + $link_array = $graph_array; + $link_array['page'] = "graphs"; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); + + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $toner['toner_descr']); + + $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = $graph_colour; + + $minigraph = generate_graph_tag($graph_array); + + echo(" + + + + "); + + $toner_rows++; + } + + echo("
".overlib_link($link, $toner['toner_descr'], $overlib_content)."".overlib_link($link, $minigraph, $overlib_content)."".overlib_link($link, print_percentage_bar (200, 20, $percent, NULL, "ffffff", $background['left'], $percent . "%", "ffffff", $background['right']), $overlib_content)." +
"); + echo(""); +} + +unset ($toner_rows); + +?> diff --git a/includes/discovery/cisco-entity-sensor.inc.php b/includes/discovery/cisco-entity-sensor.inc.php index ba3f35bdd1..7415e314af 100644 --- a/includes/discovery/cisco-entity-sensor.inc.php +++ b/includes/discovery/cisco-entity-sensor.inc.php @@ -5,7 +5,7 @@ if ($device['os_group'] == "cisco") echo(" CISCO-ENTITY-SENSOR: "); $oids = array(); - echo(" Caching OIDs: "); + echo("Caching OIDs:"); if (!is_array($entity_array)) { diff --git a/includes/discovery/entity-sensor.inc.php b/includes/discovery/entity-sensor.inc.php index 811f746231..b062d69787 100644 --- a/includes/discovery/entity-sensor.inc.php +++ b/includes/discovery/entity-sensor.inc.php @@ -2,7 +2,7 @@ echo(" ENTITY-SENSOR: "); -echo("\nCaching OIDs:"); +echo("Caching OIDs:"); if (!is_array($entity_array)) { diff --git a/includes/functions.php b/includes/functions.php index 133ad9a51e..9e402bdb1a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -159,13 +159,14 @@ function delete_device($id) $device_tables = array('entPhysical', 'devices_attribs', 'devices_perms', 'bgpPeers', 'vlans', 'vrfs', 'storage', 'alerts', 'eventlog', 'syslog', 'ports', 'services', 'alerts', 'toner', 'frequency', 'current', 'sensors'); - foreach ($device_tables as $table) { + foreach ($device_tables as $table) + { dbDelete($table, "`device_id` = ?", array($id)); } shell_exec("rm -rf ".trim($config['rrd_dir'])."/$host"); - $ret = "Removed Device $host\n"; + $ret = "Removed device $host\n"; return $ret; }