remove some crap from graphs setup. fetch device array inside graph file, not in graph.php. mres() in graph.php. try to switch to generic $_GET['id'] for everything (peers and ports undone?)

git-svn-id: http://www.observium.org/svn/observer/trunk@1084 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong 2010-05-02 19:47:09 +00:00
parent 4107118289
commit a40a1244bf
31 changed files with 87 additions and 76 deletions

View File

@ -108,7 +108,7 @@ $config['ports_page_default'] = "details/";
### Which additional features should we enable?
$config['enable_bgp'] = 1; # Enable BGP session collection and display
$config['enable_bgp'] = 1; # Enable BGP session collection and display
$config['enable_syslog'] = 0; # Enable Syslog
$config['enable_billing'] = 0; # Enable Billing
$config['enable_inventory'] = 1; # Enable Inventory

View File

@ -15,22 +15,18 @@ if($_GET['debug']) {
include("../includes/rewrites.php");
include("includes/authenticate.inc.php");
# if(!$_SESSION['authenticated']) { echo("not authenticated"); exit; }
if(!$_SESSION['authenticated']) { echo("not authenticated"); exit; }
if($_GET['device']) {
$device_id = $_GET['device'];
$_GET['id'] = $_GET['device'];
} elseif($_GET['if']) {
$device_id = getifhost($_GET['if']);
$ifIndex = getifindexbyid($_GET['if']);
$_GET['id'] = $_GET['if'];
} elseif($_GET['port']) {
$device_id = getifhost($_GET['port']);
$ifIndex = getifindexbyid($_GET['port']);
$_GET['id'] = $_GET['port'];
} elseif($_GET['peer']) {
$device_id = getpeerhost($_GET['peer']);
$_GET['id'] = $_GET['peer'];
}
if($device_id) { $hostname = gethostbyid($device_id); }
$from = mres($_GET['from']);
$to = mres($_GET['to']);
$width = mres($_GET['width']);
@ -38,6 +34,8 @@ if($_GET['debug']) {
$title = mres($_GET['title']);
$vertical = mres($_GET['vertical']);
$type = mres($_GET['type']);
$legend = mres($_GET['legend']);
$id = mres($_GET['id']);
$graphfile = $config['temp_dir'] . "/" . strgen() . ".png";
@ -62,6 +60,7 @@ if($_GET['debug']) {
if(is_file($graphfile)) {
header('Content-type: image/png');
$fd = fopen($graphfile,'r');fpassthru($fd);fclose($fd);
unlink($graphfile);
} else {
header('Content-type: image/png');
$string = "Graph Generation Error";
@ -74,23 +73,6 @@ if($_GET['debug']) {
}
}
if($graph) {
# header('Content-type: image/png');
# $fd = fopen($graphfile,'r');fpassthru($fd);fclose($fd);
} else {
header('Content-type: image/png');
$string = "Graph Generation Error";
$im = imagecreate($width, $height);
$orange = imagecolorallocate($im, 255, 255, 255);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, $height / 2 - 8, $string, imagecolorallocate($im, 128, 0, 0));
imagepng($im);
imagedestroy($im);
}
unlink($graphfile);
# } // End IF
?>

View File

@ -2,13 +2,9 @@
## Generate a list of ports and then call the multi_bits grapher to generate from the list
if($_GET['device']) {
$device = device_by_id_cache(mres($_GET['device']));
} elseif($_GET['id']) {
$device = device_by_id_cache(mres($_GET['id']));
}
$device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device['device_id']."'");
$query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$id."'");
while($int = mysql_fetch_assoc($query)) {
$ignore = 0;
if(is_array($config['device_traffic_iftype'])) {

View File

@ -1,11 +1,13 @@
<?php
$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".mres($device_id)."'");
$device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".$id."'");
$i=0;
while($proc = mysql_fetch_array($query)) {
$rrd_filename = $config['rrd_dir'] . "/$hostname/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");
if(is_file($rrd_filename)) {

View File

@ -1,5 +1,7 @@
<?php
$device = device_by_id_cache($id);
$unit_text = "Load %";
$units='%';
@ -12,7 +14,7 @@ $scale_max = "100";
$nototal = 1;
include("common.inc.php");
$database = $config['rrd_dir'] . "/" . $hostname . "/powerconnect-cpu.rrd";
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/powerconnect-cpu.rrd";
$rrd_options .= " DEF:load=$database:LOAD:AVERAGE";
$rrd_options .= " DEF:load_max=$database:LOAD:MAX";

View File

@ -1,5 +1,7 @@
<?php
$device = device_by_id_cache($id);
$unit_text = "Load %";
$units='%';
@ -12,7 +14,7 @@ $scale_max = "100";
$nototal = 1;
include("common.inc.php");
$database = $config['rrd_dir'] . "/" . $hostname . "/procurve-cpu.rrd";
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/procurve-cpu.rrd";
$rrd_options .= " DEF:load=$database:LOAD:AVERAGE";
$rrd_options .= " DEF:load_max=$database:LOAD:MAX";

View File

@ -1,11 +1,12 @@
<?php
$query = mysql_query("SELECT * FROM `hrDevice` where `device_id` = '".mres($device_id)."' AND hrDeviceType = 'hrDeviceProcessor'");
$query = mysql_query("SELECT * FROM `hrDevice` where `device_id` = '".$id."' AND hrDeviceType = 'hrDeviceProcessor'");
$device = device_by_id_cache($id);
$i=0;
while($proc = mysql_fetch_array($query)) {
$rrd_filename = $config['rrd_dir'] . "/$hostname/" . safename("hrProcessor-" . $proc['hrDeviceIndex'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/."$device['hostname']."/" . safename("hrProcessor-" . $proc['hrDeviceIndex'] . ".rrd");
if(is_file($rrd_filename)) {

View File

@ -2,10 +2,12 @@
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM fanspeed where device_id = '$device_id'");
$sql = mysql_query("SELECT * FROM fanspeed where device_id = '$id'");
$rrd_options .= " COMMENT:'RPM Cur Min Max\\n'";
while($fanspeed = mysql_fetch_array($sql))
{
@ -36,10 +38,8 @@ while($fanspeed = mysql_fetch_array($sql))
break;
}
$hostname = gethostbyid($fanspeed['device_id']);
$descr = substr(str_pad($fanspeed['fan_descr'], 17),0,17);
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
$fan_id = $fanspeed['fan_id'];
$rrd_options .= " DEF:fan$fan_id=$rrd_filename:fan:AVERAGE";

View File

@ -1,10 +1,12 @@
<?php
$device = device_by_id_cache($id);
$scale_min = "0";
include("common.inc.php");
$database = $config['rrd_dir'] . "/" . $hostname . "/hrSystem.rrd";
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/hrSystem.rrd";
$rrd_options .= " DEF:procs=$database:procs:AVERAGE";
$rrd_options .= " COMMENT:Processes\ \ \ \ Cur\ \ \ \ \ Ave\ \ \ \ \ \ Min\ \ \ \ \ Max\\\\n";

View File

@ -1,10 +1,12 @@
<?php
$device = device_by_id_cache($id);
$scale_min = "0";
include("common.inc.php");
$database = $config['rrd_dir'] . "/" . $hostname . "/hrSystem.rrd";
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/hrSystem.rrd";
$rrd_options .= " DEF:users=$database:users:AVERAGE";
$rrd_options .= " DEF:users_max=$database:users:MAX";

View File

@ -2,7 +2,9 @@
include("common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-icmp.rrd";
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-icmp.rrd";
$rrd_options .= " DEF:icmpInMsgs=$rrd_filename:icmpInMsgs:AVERAGE";
$rrd_options .= " DEF:icmpOutMsgs=$rrd_filename:icmpOutMsgs:AVERAGE";

View File

@ -2,7 +2,9 @@
include('common.inc.php');
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-icmp.rrd";
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-icmp.rrd";
$rrd_options .= " DEF:InSrcQuenchs=$rrd_filename:icmpInSrcQuenchs:AVERAGE";
$rrd_options .= " DEF:OutSrcQuenchs=$rrd_filename:icmpOutSrcQuenchs:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-ip.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip.rrd";
$rrd_options .= " DEF:ipForwDatagrams=$rrd_filename:ipForwDatagrams:AVERAGE";
$rrd_options .= " DEF:ipInDelivers=$rrd_filename:ipInDelivers:AVERAGE";

View File

@ -1,9 +1,10 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename_4 = $config['rrd_dir'] . "/" . $hostname . "/ipSystemStats-ipv4.rrd";
$rrd_filename_6 = $config['rrd_dir'] . "/" . $hostname . "/ipSystemStats-ipv6.rrd";
$rrd_filename_4 = $config['rrd_dir'] . "/" . $device['hostname'] . "/ipSystemStats-ipv4.rrd";
$rrd_filename_6 = $config['rrd_dir'] . "/" . $device['hostname'] . "/ipSystemStats-ipv6.rrd";
$rrd_options .= " DEF:InForwDatagrams_4=$rrd_filename_4:InForwDatagrams:AVERAGE";
$rrd_options .= " DEF:InDelivers_4=$rrd_filename_4:InDelivers:AVERAGE";

View File

@ -1,9 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-ip.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-ip.rrd";
$rrd_options .= " DEF:ipInDelivers=$rrd_filename:ipInDelivers:AVERAGE";
$rrd_options .= " DEF:ipReasmReqds=$rrd_filename:ipReasmReqds:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$database = $config['rrd_dir'] . "/" . $hostname . "/load.rrd";
$database = $config['rrd_dir'] . "/" . $device['hostname'] . "/load.rrd";
$rrd_options .= " DEF:1min=$database:1min:AVERAGE";
$rrd_options .= " DEF:5min=$database:5min:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/ucd_load.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ucd_load.rrd";
$rrd_options .= " DEF:1min=$rrd_filename:1min:AVERAGE";
$rrd_options .= " DEF:5min=$rrd_filename:5min:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/load.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/load.rrd";
$rrd_options .= " DEF:1min=$rrd_filename:1min:AVERAGE";
$rrd_options .= " DEF:5min=$rrd_filename:5min:AVERAGE";

View File

@ -1,6 +1,7 @@
<?php
$query = mysql_query("SELECT * FROM `mempools` where `device_id` = '".mres($device_id)."'");
$device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `mempools` where `device_id` = '".$id."'");
include("common.inc.php");
@ -14,7 +15,7 @@ include("common.inc.php");
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
$descr = substr(str_pad(short_hrDeviceDescr($mempool['mempool_descr']), 28),0,28);
$descr = str_replace(":", "\:", $descr);
$rrd = $config['rrd_dir'] . "/".$hostname."/" . safename("mempool-".$mempool['mempool_type']."-".$mempool['mempool_index'].".rrd");
$rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("mempool-".$mempool['mempool_type']."-".$mempool['mempool_index'].".rrd");
$rrd_options .= " DEF:mempoolfree$i=$rrd:free:AVERAGE ";
$rrd_options .= " DEF:mempoolused$i=$rrd:used:AVERAGE ";
$rrd_options .= " CDEF:mempooltotal$i=mempoolused$i,mempoolused$i,mempoolfree$i,+,/,100,* ";

View File

@ -3,8 +3,9 @@
$scale_min = "0";
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/procurve-mem.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/procurve-mem.rrd";
$rrd_options .= " -b 1024";
$rrd_options .= " DEF:TOTAL=$rrd_filename:TOTAL:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/ucd_mem.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ucd_mem.rrd";
$rrd_options .= " -b 1024";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/mem.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/mem.rrd";
$rrd_options .= " -b 1024";

View File

@ -1,11 +1,12 @@
<?php
$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".mres($device_id)."'");
$device = device_by_id_cache($id);
$query = mysql_query("SELECT * FROM `processors` where `device_id` = '".$id."'");
$i=0;
while($proc = mysql_fetch_array($query)) {
$rrd_filename = $config['rrd_dir'] . "/$hostname/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("processor-" . $proc['processor_type'] . "-" . $proc['processor_index'] . ".rrd");
if(is_file($rrd_filename)) {

View File

@ -5,8 +5,10 @@ $scale_max = "100";
include("common.inc.php");
$device = device_by_id_cache($id);
$iter = "1";
$sql = mysql_query("SELECT * FROM storage where device_id = '$device_id'");
$sql = mysql_query("SELECT * FROM storage where device_id = '$id'");
$rrd_options .= " COMMENT:' Size Used %age\\l'";
while($storage = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
@ -14,7 +16,7 @@ include("common.inc.php");
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
$descr = substr(str_pad($storage[storage_descr], 12),0,12);
$descr = str_replace(":","\:",$descr);
$rrd = $config['rrd_dir'] . "/$hostname/" . safename("storage-".$storage['storage_mib']."-".$storage['storage_descr'].".rrd");
$rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("storage-".$storage['storage_mib']."-".$storage['storage_descr'].".rrd");
$rrd_options .= " DEF:$storage[storage_id]used=$rrd:used:AVERAGE";
$rrd_options .= " DEF:$storage[storage_id]free=$rrd:free:AVERAGE";
$rrd_options .= " CDEF:$storage[storage_id]size=$storage[storage_id]used,$storage[storage_id]free,+";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-tcp.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-tcp.rrd";
$rrd_options .= " DEF:tcpActiveOpens=$rrd_filename:tcpActiveOpens:AVERAGE";
$rrd_options .= " DEF:tcpPassiveOpens=$rrd_filename:tcpPassiveOpens:AVERAGE";

View File

@ -1,11 +1,12 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM temperature where device_id = '$device_id'");
$sql = mysql_query("SELECT * FROM temperature where device_id = '$id'");
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
while($temperature = mysql_fetch_array($sql))
{
@ -37,7 +38,7 @@ while($temperature = mysql_fetch_array($sql))
}
$temperature['temp_descr_fixed'] = substr(str_pad($temperature['temp_descr'], 22),0,22);
$temprrd = $config['rrd_dir'] . "/$hostname/".safename("temp-" . $temperature['temp_descr'] . ".rrd");
$temprrd = $config['rrd_dir'] . "/".$device['hostname']."/".safename("temp-" . $temperature['temp_descr'] . ".rrd");
$rrd_options .= " DEF:temp" . $temperature[temp_id] . "=$temprrd:temp:AVERAGE ";
$rrd_options .= " LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['temp_descr_fixed']))) . "' ";
$rrd_options .= " GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lfC ";

View File

@ -1,11 +1,12 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM toner where device_id = '$device_id'");
$sql = mysql_query("SELECT * FROM toner where device_id = '$id'");
$rrd_options .= " COMMENT:'Toner level Cur Min Max\\n'";
while($toner = mysql_fetch_array($sql))
{
@ -43,7 +44,7 @@ while($toner = mysql_fetch_array($sql))
$hostname = gethostbyid($toner['device_id']);
$descr = substr(str_pad($toner['toner_descr'], 17),0,17);
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("toner-" . $toner['toner_descr'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("toner-" . $toner['toner_descr'] . ".rrd");
$toner_id = $toner['toner_id'];
$rrd_options .= " DEF:toner$toner_id=$rrd_filename:toner:AVERAGE";

View File

@ -1,8 +1,9 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/netstats-udp.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/netstats-udp.rrd";
$rrd_options .= " DEF:udpInDatagrams=$rrd_filename:udpInDatagrams:AVERAGE";
$rrd_options .= " DEF:udpOutDatagrams=$rrd_filename:udpOutDatagrams:AVERAGE";

View File

@ -3,11 +3,12 @@
$scale_min = "0";
include("common.inc.php");
$device = device_by_id_cache($id);
if (is_file($config['rrd_dir'] . "/" . $hostname . "/hrSystem.rrd")) {
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/hrSystem.rrd";
if (is_file($config['rrd_dir'] . "/" . $device['hostname'] . "/hrSystem.rrd")) {
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/hrSystem.rrd";
} else {
$rrd_filename = $config['rrd_dir'] . "/" . $hostname . "/uptime.rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/uptime.rrd";
}
$rrd_options .= " DEF:uptime=$rrd_filename:uptime:AVERAGE";

View File

@ -1,11 +1,12 @@
<?php
include("common.inc.php");
$device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM voltage where device_id = '$device_id'");
$sql = mysql_query("SELECT * FROM voltage where device_id = '$id'");
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
while($voltage = mysql_fetch_array($sql))
{
@ -39,7 +40,7 @@ while($voltage = mysql_fetch_array($sql))
$hostname = gethostbyid($voltage['device_id']);
$descr = substr(str_pad($voltage['volt_descr'], 17),0,17);
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("volt-" . $voltage['volt_descr'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("volt-" . $voltage['volt_descr'] . ".rrd");
$volt_id = $voltage['volt_id'];
$rrd_options .= " DEF:volt$volt_id=$rrd_filename:volt:AVERAGE";

View File

@ -106,7 +106,7 @@ if(isset($_SERVER['HTTPS'])) {
}
### Connect to database
$observer_link = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']);
$observer_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']);
if (!$observer_link) {
echo "<h2>Observer MySQL Error</h2>";
die;