From: Juan Luis Francis Date: Thu, 26 Jan 2006 17:12:24 +0000 (+0000) Subject: - (0000019,0000021) Fixed psql querys. X-Git-Tag: Release-1.38.6~39 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4b7c71b142955919bce84760d7a936926b789765;p=bacula%2Fbacula - (0000019,0000021) Fixed psql querys. - Fixed XTicks (Graphs). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2771 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/gui/bacula-web/ChangeLog b/gui/bacula-web/ChangeLog index e939e2e2e1..295de189ae 100644 --- a/gui/bacula-web/ChangeLog +++ b/gui/bacula-web/ChangeLog @@ -1,4 +1,8 @@ -- - - - Bacula web 1.2 +26-01-2006 Bacula-web 1.3 + - (0000019,0000021) Fixed psql querys. + - Fixed XTicks (Graphs). + +06-10-2005 Bacula web 1.2 - Human redable Y-axis of graphs - Updated French translation - Initial support for PostgreSQL (thanks to Dan Langille) diff --git a/gui/bacula-web/classes.inc b/gui/bacula-web/classes.inc index 1f0cc9fa25..ec57f26f71 100644 --- a/gui/bacula-web/classes.inc +++ b/gui/bacula-web/classes.inc @@ -35,6 +35,7 @@ class Bweb extends DB { var $EndDate; var $driver; var $dbs; + var $dbs_name; @@ -70,7 +71,7 @@ class Bweb extends DB { $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, (sqlite, pgsql) -->> Yet not checked + $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"); @@ -80,6 +81,7 @@ class Bweb extends DB { die($this->link->getMessage()); $this->driver = $this->dsn[phptype]; register_shutdown_function(array(&$this,'close')); + $this->dbs_name = $this->dsn['database']; } function close() { @@ -153,8 +155,10 @@ class Bweb extends DB { 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]; @@ -221,7 +225,7 @@ class BGraph { $graph->SetXDataLabelAngle(90); else $graph->SetXDataLabelAngle(0); -// $graph->SetNumXTicks(10); + $graph->SetNumXTicks(1); // $graph->SetXDataLabelPos('none'); // $graph->SetXTickLabelPos('plotdown'); @@ -373,7 +377,7 @@ class BCreateGraph extends BGraph { $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 nmero de jobs totales de un cliente. + $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") { @@ -383,12 +387,14 @@ class BCreateGraph extends BGraph { or die ("classes.inc: Error at query: 8"); } else if ($DB_bacula->driver == "pgsql") { - $res = $DB_bacula->link->query("select Name from Job where EndTime > now() - interval '$this->elapsed seconds' group by Name order by Name desc") + $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 date(EndTime) from Job where EndTime > NOW() - interval '$this->elapsed seconds' group by EndTime order by EndTime") + $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
".$resdata->getMessage()); while ( $tmpdata = $res->fetchRow() ) array_push($this->clientes,$tmpdata[0]); @@ -405,13 +411,15 @@ class BCreateGraph extends BGraph { $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(EndTime),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(); } @@ -421,7 +429,7 @@ class BCreateGraph extends BGraph { // echo ""; reset ($this->clientes); - do { + do { if ( $spr2[current($this->clientes)] != NULL) array_push($spr,$spr2[current($this->clientes)]); else @@ -437,7 +445,7 @@ class BCreateGraph extends BGraph { $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�ica no se descuadre $tmp = count($whole_result[$i]); if ( $i2 < $tmp ) // Estupidez?. Check this code later... @@ -463,7 +471,7 @@ class BCreateGraph extends BGraph { - //Conversi� 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"; diff --git a/gui/bacula-web/configs/bacula.conf b/gui/bacula-web/configs/bacula.conf index 7d37a8ab6e..a48d3e7580 100644 --- a/gui/bacula-web/configs/bacula.conf +++ b/gui/bacula-web/configs/bacula.conf @@ -83,5 +83,5 @@ db_type = mysql #host = 192.168.20.40 #login = bacula #pass = -#dbname = bacula +#db_name = bacula #db_type= pgsql diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index b1c869d647..1e74863581 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -60,13 +60,16 @@ $tmp = $client->fetchRow(); $smarty->assign('clientes_totales',$tmp[0]); $tmp = $last24bytes->fetchRow(); -if ( empty($tmp[0]) ) { // No data for last 24, search last 48 +/*if ( empty($tmp[0]) ) { // No data for last 24, search last 48 if ( $dbSql->driver == "mysql" ) $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-172800" ); if ( $dbSql->driver == "pgsql") - $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800" ); + $last24bytes = $dbSql->link->query("select sum(JobBytes) from Job where Endtime <= NOW() and EndTime > NOW()-172800 * interval '1 second'" ) + or die ("Error query: 4.1"); $smarty->assign('when',"yesterday"); -} + $tmp = $last24bytes->fetchRow(); +}*/ + $smarty->assign('bytes_totales',$tmp[0]); $smarty->assign('total_jobs', $tmp[1]); @@ -78,6 +81,7 @@ $totalfiles->free(); $last24bytes->free(); + // report_select.tpl & last_run_report.tpl $res = $dbSql->link->query("select Name from Job group by Name"); $a_jobs = array(); @@ -136,7 +140,7 @@ else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){ LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 order by elapsed "; // Full report array if ( $dbSql->driver == "pgsql") - $query = "select Job.EndTime - Job.StartTime ) + $query = "select (Job.EndTime - Job.StartTime ) as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second' order by elapsed "; diff --git a/gui/bacula-web/templates/volumes.tpl b/gui/bacula-web/templates/volumes.tpl index ef40edb0a6..c99b02083f 100644 --- a/gui/bacula-web/templates/volumes.tpl +++ b/gui/bacula-web/templates/volumes.tpl @@ -23,7 +23,7 @@ {t}Volume Bytes{/t} {t}Media Type{/t} {t}When expire?{/t} - {t}Last Written{/t} + {t}Last Written{/t} {t}Volume Status{/t} {/if}