From 6178a2bcd0e9e1a7c025fda76a756df890aa0637 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Mon, 29 Nov 2010 17:37:46 +0100 Subject: [PATCH] bacula-web: Improved php and html code - New Get_BackupJob_Names function in Bweb classe - New GetLastErrorJobs() and GetLastJobs() function in Bweb classe - Improved Last completed and failed jobs in index.php - Some html and css fixes in last_run_report.tpl --- gui/bacula-web/classes.inc.php | 82 +++++++++++++++++--- gui/bacula-web/config.inc.php | 5 ++ gui/bacula-web/index.php | 60 ++++---------- gui/bacula-web/templates/last_run_report.tpl | 16 +--- 4 files changed, 92 insertions(+), 71 deletions(-) create mode 100644 gui/bacula-web/config.inc.php diff --git a/gui/bacula-web/classes.inc.php b/gui/bacula-web/classes.inc.php index e4241174ee..ec853ecabd 100644 --- a/gui/bacula-web/classes.inc.php +++ b/gui/bacula-web/classes.inc.php @@ -356,30 +356,87 @@ class Bweb extends DB { public function GetLastJobs( $delay = LAST_DAY ) { + $query = ""; + $start_date = ""; + $end_date = ""; + + // Interval calculation + $end_date = mktime(); + $start_date = $end_date - $delay; + + $start_date = date( "Y-m-d H:m:s", $start_date ); + $end_date = date( "Y-m-d H:m:s", $end_date ); + switch( $this->driver ) { case 'mysql': - $query = "SELECT JobId, Name, EndTime, JobStatus "; - $query .= "FROM Job "; - $query .= "WHERE EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400 and JobStatus!='T'"; - break; - case 'pgsql': - $query = "SELECT JobId, Name, EndTime, JobStatus "; - $query .= "FROM Job "; - $query .= "WHERE EndTime <= NOW() and EndTime >NOW() - 86400 * interval '1 second' and JobStatus!= 'T'"; + $query = 'SELECT COUNT(JobId) AS completed_jobs '; + $query .= 'FROM Job '; + $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' "; + $query .= "AND JobStatus = 'T'"; break; } - $lastjobstatus = $this->db_link->query( $query ); + $jobs = $this->db_link->query( $query ); if (PEAR::isError( $lastjobstatus ) ) { - die( "Unable to get last job status from catalog
" . $status->getMessage() ); + die( "Unable to get last completed jobs status from catalog
" . $status->getMessage() ); }else { - //echo "numrows = " . $lastjobstatus->numRows() . "
"; - return $lastjobstatus->numRows(); + return $jobs->fetchRow(); } } // end function GetLastJobStatus() + public function GetLastErrorJobs( $delay = LAST_DAY ) + { + $query = ""; + $start_date = ""; + $end_date = ""; + + // Interval calculation + $end_date = mktime(); + $start_date = $end_date - $delay; + + $start_date = date( "Y-m-d H:m:s", $start_date ); + $end_date = date( "Y-m-d H:m:s", $end_date ); + + //echo "start date: $start_date
"; + //echo "end date: $end_date
"; + + switch( $this->driver ) + { + default: + $query = 'SELECT COUNT(JobId) AS failed_jobs '; + $query .= 'FROM Job '; + $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' "; + $query .= "AND JobStatus = 'f'"; + break; + } + $result = $this->db_link->query( $query ); + + if (PEAR::isError( $result ) ) { + die( "Unable to get last failed jobs status from catalog
query = $query
" . $result->getMessage() ); + }else { + return $result->fetchRow( DB_FETCHMODE_ASSOC ); + } // end if else + } // end function GetLastErrorJobs + + public function Get_BackupJob_Names() + { + $query = "SELECT Name FROM Job GROUP BY Name"; + $backupjobs = array(); + + $result = $this->db_link->query( $query ); + + if (PEAR::isError( $result ) ) { + die("Unable to get BackupJobs list from catalog" ); + }else{ + while( $backupjob = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { + array_push( $backupjobs, $backupjob["Name"] ); + } + return $backupjobs; + } + } + } // end class Bweb class BGraph { @@ -712,3 +769,4 @@ class BCreateGraph extends BGraph { }//end class ?> + diff --git a/gui/bacula-web/config.inc.php b/gui/bacula-web/config.inc.php new file mode 100644 index 0000000000..6d7c74265a --- /dev/null +++ b/gui/bacula-web/config.inc.php @@ -0,0 +1,5 @@ + diff --git a/gui/bacula-web/index.php b/gui/bacula-web/index.php index e3591c2450..538f62b753 100644 --- a/gui/bacula-web/index.php +++ b/gui/bacula-web/index.php @@ -131,66 +131,32 @@ $smarty->assign('clientes_totales',$nb_clients["nb_client"] ); $tmp = $last24bytes->fetchRow(); }*/ -// report_select.tpl & last_run_report.tpl -$res = $dbSql->db_link->query("select Name from Job group by Name"); +// Backup Job list for report.tpl and last_run_report.tpl +$smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() ); + +/*$res = $dbSql->db_link->query("select Name from Job group by Name"); $a_jobs = array(); -while ( $tmp = $res->fetchRow() ) +while( $tmp = $res->fetchRow() ) array_push($a_jobs, $tmp[0]); $smarty->assign('total_name_jobs',$a_jobs); $smarty->assign('time2',( (time())-2678400) ); // Current time - 1 month.