<?
/*
+-------------------------------------------------------------------------+
-| Copyright (C) 2004 Juan Luis Francés Jiménez |
+| Copyright (C) 2004-2005 Juan Luis Frances Jiminez |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
var $StartDate;
var $EndDate;
var $driver;
+ var $dbs;
+ var $dbs_name;
function Bweb() {
$conf = new Config_File (CONFIG_DIR);
-
-
- $this->dsn[hostspec] = $conf->get(CONFIG_FILE,"DATABASE","host");
- $this->dsn[username] = $conf->get(CONFIG_FILE,"DATABASE","login");
- $this->dsn[password] = $conf->get(CONFIG_FILE,"DATABASE","pass");
- $this->dsn[database] = $conf->get(CONFIG_FILE,"DATABASE","db_name");
- $this->dsn[phptype] = $conf->get(CONFIG_FILE,"DATABASE","db_type"); // mysql, (sqlite, pgsql) -->> Yet not checked
- if ( $conf->get(CONFIG_FILE,"DATABASE","db_port") )
- $this->dsn[port] = $conf->get(CONFIG_FILE,"DATABASE","db_port");
+ $this->dbs = array();
+ $i = 2;
+ $sections = $conf->get(CONFIG_FILE,"DATABASE","host");
+ array_push($this->dbs, "DATABASE");
+ while ( !empty($sections) ) {
+ $sections = $conf->get(CONFIG_FILE,"DATABASE".$i,"host");
+ if ( !empty($sections) )
+ array_push($this->dbs,"DATABASE".$i);
+ $i++;
+ }
+
+ if ( $i < 4)
+ $sec = "DATABASE";
+ else {
+ if ( !empty($_POST['sel_database']) ) {
+ $_SESSION['DATABASE'] = $_POST['sel_database'];
+ $sec = $_POST['sel_database'];
+ } else {
+ if (isset($_SESSION['DATABASE']) )
+ $sec = $_SESSION['DATABASE'];
+ else
+ $sec = "DATABASE";
+ }
+ }
+
+ $this->dsn['hostspec'] = $conf->get(CONFIG_FILE,$sec,"host");
+ $this->dsn['username'] = $conf->get(CONFIG_FILE,$sec,"login");
+ $this->dsn['password'] = $conf->get(CONFIG_FILE,$sec,"pass");
+ $this->dsn['database'] = $conf->get(CONFIG_FILE,$sec,"db_name");
+ $this->dsn['phptype'] = $conf->get(CONFIG_FILE,$sec,"db_type"); // mysql, pgsql
+ if ( $conf->get(CONFIG_FILE,$sec,"db_port") )
+ $this->dsn[port] = $conf->get(CONFIG_FILE,$sec,"db_port");
$this->link =& $this->connect($this->dsn);
die($this->link->getMessage());
$this->driver = $this->dsn[phptype];
register_shutdown_function(array(&$this,'close'));
- }
-
-
+ $this->dbs_name = $this->dsn['database'];
+ }
function close() {
$this->link->disconnect();
- }
+ }
- function CalculateBytesPeriod($server,$StartDate,$EndPeriod) { // Bytes transferred in a period.
+ function CalculateBytesPeriod($server,$StartDate,$EndPeriod) { // Bytes transferred in a period.
$result =& $this->link->query("select SUM(JobBytes) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
or die("classes.inc: Error query: 1");
$return =& $result->fetchRow();
return $return[0];
- }//end function
+ }//end function
- function CalculateFilesPeriod($server,$StartDate,$EndPeriod) { // Number of files transferred in a period.
+ function CalculateFilesPeriod($server,$StartDate,$EndPeriod) { // Number of files transferred in a period.
$result =& $this->link->query("select SUM(JobFiles) from Job WHERE EndTime < '$EndPeriod' and EndTime > '$StartDate' and Name='$server'")
or die("classes.inc: Error query: 2");
$return =& $result->fetchRow();
return $return[0];
- }//end function
+ }//end function
if ($this->driver == "mysql" )
$result = $this->link->query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten,FROM_UNIXTIME(UNIX_TIMESTAMP(Media.LastWritten)+Media.VolRetention ) as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");
else if ($this->driver == "pgsql")
- $result = $this->link->query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten,FROM_UNIXTIME(Media.LastWritten::Timestamp without time zone + Media.VolRetention) as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");
+ $result = $this->link->query("select Media.VolumeName, Media.VolBytes,Media.VolStatus,Pool.Name,Media.MediaType,Media.LastWritten, Media.LastWritten + Media.VolRetention * interval '1 second' as expire from Pool LEFT JOIN Media ON Media.PoolId=Pool.PoolId where Name='$tmp[0]' order by Media.VolumeName");
while ( $tmp1 = $result->fetchRow() ) {
$pos = array_key_exists($tmp[0],$volume);
if ($pos != FALSE)
$dbsize = $this->link->query("show table status")
or die ("classes.inc: Error query: 3");
if ( $dbsize->numRows() ) {
- while ( $res = $dbsize->fetchRow() )
- $database_size += $res[5];
+ while ( $res = $dbsize->fetchRow(DB_FETCHMODE_ASSOC) )
+ $database_size += $res["Data_length"];
}
else
return 0;
}
else if ( $this->driver == "pgsql") {
- $dbsize = $this->link->query("select database_size('bacula')")
+ $dbsize = $this->link->query("select pg_database_size('$this->dbs_name')")
or die ("classes.inc: Error query: 4");
+ if (PEAR::isError($dbsize))
+ die($dbsize->getMessage());
if ( $dbsize->numRows() ) {
while ( $res = $dbsize->fetchRow() )
$database_size += $res[0];
require_once ("external_packages/phplot/phplot.php");
- if ( empty($this->sizex) || empty($this->sizey) ) { //Default size
+ if ( empty($this->sizex) || empty($this->sizey) ) { //Default size
$this->sizex = "600";
$this->sizey = "400";
}
}
$legend = $leyenda;
-// $bgcolor = array(222,206,215); // Background color of graph
+// $bgcolor = array(222,206,215); // Background color of graph
$bgcolor = array(207,231,231);
$fgcolor = array(110,41,57);
$graph->SetXDataLabelAngle(90);
else
$graph->SetXDataLabelAngle(0);
-// $graph->SetNumXTicks(10);
+ $graph->SetNumXTicks(1);
// $graph->SetXDataLabelPos('none');
// $graph->SetXTickLabelPos('plotdown');
if ( $this->Leg == 1 ) {
$this->MarginLeftWithLegend($legend);
$graph->SetMarginsPixels($this->MarginLeft,10,35,$this->MarginBottom);
- $graph->SetLegend($legend);
- }
+ $graph->SetLegend($legend);
+ }
else
$graph->SetMarginsPixels(90,35,35,$this->MarginBottom);
// $graph->SetDataColors(array($fgcolor),array( "black"));
$maxlen = 0;
while (next($clients)) {
- $tmp = strlen (current($clients));
+ $tmp = strlen(current($clients));
if ( $tmp > $maxlen )
$maxlen = $tmp;
}
- $this->MarginLeft = $maxlen * 11;
+ $this->MarginLeft = $maxlen * 9;
}
}//end class
var $derecha;
var $StartDate;
var $EndDate;
- var $elapsed; // Default elapsed time to show complex graphs
+ var $elapsed; // Default elapsed time to show complex graphs
$this->StartDate = "1900-01-01";
$this->EndDate = "4000-01-01";
- $this->elapsed = "86400"; // 24 hours in seconds.
+ $this->elapsed = "86400"; // 24 hours in seconds.
}
$DB_bacula = new Bweb();
$datos = $this->SQLPrepareData($server,$tipo_dato);
- if ( empty($datos) ) { //No data = No stats = Empty graph
+ if ( empty($datos) ) { //No data = No stats = Empty graph
header("Content-type: image/png");
$img= @ImageCreate(200,100) or die ("Cannot intialize GD stream");
$bgc= ImageColorAllocate($img, 0, 255,255);
return;
}
- if ( empty ($xlabel) ) { // If no label, table names like leyends
+ if ( empty ($xlabel) ) { // If no label, table names like leyends
$xlabel=$derecha; $ylabel=$izquierda;
- }
+ }
$this->SetDataType("text-data");
$this->BShowGraph($datos,$title,$xlabel,$ylabel,$this->clientes,$tipo);
- function SQLPrepareData($servidor,$tipo_dato=0) { // Prepare bytes data from database.
+ function SQLPrepareData($servidor,$tipo_dato=0) { // Prepare bytes data from database.
global $DB_bacula;
global $izquierda;
global $derecha;
- if ( $tipo_dato<30 ) { // Simple graph. Only 2 data
+ if ( $tipo_dato<30 ) { // Simple graph. Only 2 data
switch ($tipo_dato)
{
$whole_result[] = $this->array_merge_php4($row["$derecha"],$row[$izquierda]);
}
$result->free();
- } else { // Complex graph. 3 or more data.
+ } else { // Complex graph. 3 or more data.
switch ( $tipo_dato )
{
- case '30': // Unused, at this time.
+ case '30': // Unused, at this time.
$result = $DB_bacula->link->query("select JobBytes,JobFiles,Jobid from Job where Name='$servidor' order by EndTime asc")
or die ("classes.inc: Error at query: 6");
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) )
$whole_result[] = array_merge($row["Jobid"],$row["JobFiles"],$row["JobBytes"]);
$result->free();
break;
- case BACULA_TYPE_BYTES_ENDTIME_ALLJOBS: // Special: Generic graph from all clientes.
- $i = -1; // Counter of number of jobs of one cliente. SP: Contador del número de jobs totales de un cliente.
- $i2 = 0; // Counter of number of keys of array. SP: Contador del número de valores del array.
+ case BACULA_TYPE_BYTES_ENDTIME_ALLJOBS: // Special: Generic graph from all clientes.
+ $i = -1; // Counter of number of jobs of one client. SP: Contador del nmero de jobs totales de un cliente.
+ $i2 = 0; // Counter of number of keys of array. SP: Contador del nmero de valores del array.
+ if ($DB_bacula->driver == "mysql") {
$res = $DB_bacula->link->query("select Name from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed group by Name order by Name desc")
or die ("classes.inc: Error at query: 7");
- if ($DB_bacula->driver == "mysql")
$resdata = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\") from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed group by date_format(EndTime, \"%Y-%m-%d\") order by EndTime")
or die ("classes.inc: Error at query: 8");
- else if ($DB_bacula->driver == "pgsql")
- $resdata = $DB_bacula->link->query("select date_format(EndTime,'%Y-%m-%d') from Job where UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-$this->elapsed group by EndTime order by EndTime")
+ }
+ else if ($DB_bacula->driver == "pgsql") {
+ $res = $DB_bacula->link->query("select Name from Job where EndTime > now() - 1*interval'$this->elapsed s' group by Name order by Name desc")
+ or die ("classes.inc: Error at query: 8");
+ $resdata = $DB_bacula->link->query("select to_char(EndTime,'YY-MM-DD') from Job where EndTime > NOW() - 1*interval'$this->elapsed s' group by EndTime order by EndTime")
or die ("classes.inc: Error at query: 9");
+ }
+ if (PEAR::isError($resdata))
+ die("classes.inc: Error at query: 9.1<br>".$resdata->getMessage());
while ( $tmpdata = $res->fetchRow() )
array_push($this->clientes,$tmpdata[0]);
// echo "</pre>";
- $spr = array(); // Temporal array
- $spr2 = array(); // Temporal array
+ $spr = array(); // Temporal array
+ $spr2 = array(); // Temporal array
$whole_result = array();
while ( $tmpdata = $resdata->fetchRow() ) {
$count++;
array_push($spr,$tmpdata[0]);
if ($DB_bacula->driver == "mysql")
- $result = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\"),SUM(JobBytes),Name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by Name order by Name desc")
+ $result = $DB_bacula->link->query("select date_format(EndTime,\"%Y-%m-%d\"),SUM(JobBytes) as sum,Name as name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by Name order by Name desc")
or die ("classes.inc: Error at query: 10");
- else if ($DB_bacula->driver == "pgsql")
- $result = $DB_bacula->link->query("select date_format(EndTime,'%Y-%m-%d'),SUM(JobBytes),Name,count(Name) as Nname from Job WHERE EndTime like '$tmpdata[0]%' group by EndTime,Name order by Name desc")
+ else if ($DB_bacula->driver == "pgsql") {
+ $query = "select to_char(EndTime,'YY-MM-DD'),SUM(JobBytes) as sum,Name,count(Name) as Nname from Job WHERE EndTime like '%$tmpdata[0]%' group by EndTime,Name order by Name desc";
+ $result = $DB_bacula->link->query($query)
or die ("classes.inc: Error at query: 11");
+ }
while ( $row = $result->fetchRow(DB_FETCHMODE_ASSOC) ) {
- $spr2 = array_merge($spr2,array($row["Name"]=>$row["SUM(JobBytes)"]));
+ $spr2 = array_merge($spr2,array($row["name"]=>$row["sum"]));
$i = $result->numRows();
}
// print_r ($spr2);
// echo "</pre>";
- reset ($this->clientes);
- do {
+ reset ($this->clientes);
+ do {
if ( $spr2[current($this->clientes)] != NULL)
array_push($spr,$spr2[current($this->clientes)]);
else
$spr = array();
$spr2 = array();
}
-
- for ( $i = 0; $i < count($whole_result); $i++ ) { // To equal the arrays so that the graph is not unsquared. SP:Igualamos las matrices para que la gráfica no se descuadre
+
+ for ( $i = 0; $i < count($whole_result); $i++ ) { // To equal the arrays so that the graph is not unsquared. SP:Igualamos las matrices para que la gr�ica no se descuadre
$tmp = count($whole_result[$i]);
- if ( $i2 < $tmp ) // Estupidez?. Check this code later...
+ if ( $i2 < $tmp ) // Estupidez?. Check this code later...
continue;
$tmp = $i2 - $tmp;
for ( $a = 0; $a <= $tmp; $a++ )
- //Conversión de la fecha a Mysql-format para Smarty. THE SAME FUNCTION AT 2 CLASSES. THIS WAY IS BUGGY. TO SOLVE LATER.
+ //Convert date from mysql to smarty. THE SAME FUNCTION AT 2 CLASSES. THIS WAY IS BUGGY. TO SOLVE LATER.
function PrepareDate($StartDateMonth,$StartDateDay,$StartDateYear,$EndDateMonth,$EndDateDay,$EndDateYear){
$this->StartDate = $StartDateYear."-".$StartDateMonth."-".$StartDateDay." 00:00:00";