From 8e4f351d038d07cf5e65ca4fea2caa1492f27174 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Tue, 21 Dec 2010 11:55:15 +0100 Subject: [PATCH] bacula-web: Added running jobs in jobs page - Running jobs and last jobs now displayed in jobs page - Removed Failed jobs from this page - Improved design (css and html) --- gui/bacula-web/jobs.php | 97 ++++++++++++++----------------- gui/bacula-web/style/default.css | 6 +- gui/bacula-web/templates/jobs.tpl | 62 ++++++++++---------- 3 files changed, 79 insertions(+), 86 deletions(-) diff --git a/gui/bacula-web/jobs.php b/gui/bacula-web/jobs.php index 1149c9e9f2..e4fe0bfc4b 100644 --- a/gui/bacula-web/jobs.php +++ b/gui/bacula-web/jobs.php @@ -19,33 +19,15 @@ $smarty->compile_dir = "./templates_c"; $smarty->config_dir = "./configs"; - // Get the last 10 failed jobs - $query = ""; - $failed_jobs = array(); + // Running jobs + $running_jobs = array(); + + $query = "SELECT Job.JobId, Job.JobStatus, Status.JobStatusLong, Job.Name, Job.StartTime, Job.Level, Pool.Name AS Pool_name "; + $query .= "FROM Job "; + $query .= "JOIN Status ON Job.JobStatus = Status.JobStatus "; + $query .= "LEFT JOIN Pool ON Job.PoolId = Pool.PoolId "; + $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C','R')"; - switch( $dbSql->driver ) - { - case 'mysql': - $query = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, Job.JobId, Job.Name AS job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS pool_name, Job.JobStatus "; - $query .= "FROM Job "; - $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; - $query .= "WHERE Job.JobStatus = 'f' "; - //$query .= "WHERE Job.EndTime BETWEEN <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 "; - $query .= "ORDER BY Job.EndTime DESC "; - $query .= "LIMIT 10"; - - break; - - case 'pgsql': - $query = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus "; - $query .= "FROM Job "; - $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; - $query .= "WHERE Job.JobStatus = 'f' "; - //$query .= "WHERE EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second' AND "; - $query .= "ORDER BY Job.EndTime DESC"; - $query .= "LIMIT 10"; - break; - } $jobsresult = $dbSql->db_link->query( $query ); if( PEAR::isError( $jobsresult ) ) { @@ -53,43 +35,46 @@ die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() ); }else { while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) { - array_push( $failed_jobs, $job); + $elapsed = 'N/A'; + + if( $job['JobStatus'] == 'R') { + $elapsed = mktime() - strtotime($job['StartTime']); + if( $elapsed > 3600 ) + $elapsed = date( "H:i:s", $elapsed ); + elseif( $elapsed > 86400 ) + $elapsed = date( "d day(s) i:s", $elapsed ); + else + $elapsed = date( "i:s", $elapsed ); + } + $job['elapsed_time'] = $elapsed; + + array_push( $running_jobs, $job); } } - $smarty->assign( 'failed_jobs', $failed_jobs ); - // Get the last completed jobs (last 24 hours) - $query = ""; - $completed_jobs = array(); + $smarty->assign( 'running_jobs', $running_jobs ); - // Interval calculation - $end_date = mktime(); - $start_date = $end_date - LAST_DAY; - - $start_date = date( "Y-m-d H:i:s", $start_date ); - $end_date = date( "Y-m-d H:i:s", $end_date ); + // Get the last jobs list + $query = ""; + $last_jobs = array(); switch( $dbSql->driver ) { case 'mysql': - $query = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, Job.JobId, Job.Name AS job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS pool_name, Job.JobStatus "; - $query .= "FROM Job "; - $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; - $query .= "WHERE Job.JobStatus = 'T' AND "; - $query .= "Job.EndTime BETWEEN '$start_date' AND '$end_date' "; - $query .= "ORDER BY Job.EndTime DESC "; - + $query = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, "; break; - case 'pgsql': - $query = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus "; - $query .= "FROM Job "; - $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; - $query .= "WHERE EndTime BETWEEN '$start_date' and '$end_date' "; - $query .= "ORDER BY Job.EndTime DESC"; + $query = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, "; break; } - + + $query .= "Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong "; + $query .= "FROM Job "; + $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; + $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus "; + $query .= "ORDER BY Job.EndTime DESC "; + $query .= "LIMIT 20"; + $jobsresult = $dbSql->db_link->query( $query ); if( PEAR::isError( $jobsresult ) ) { @@ -97,10 +82,16 @@ die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() ); }else { while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) { - array_push( $completed_jobs, $job); + if( $job['JobStatus'] == 'T' ) + $job['Job_icon'] = "s_ok.gif"; + else + $job['Job_icon'] = "s_error.gif"; + + array_push( $last_jobs, $job); } } - $smarty->assign( 'completed_jobs', $completed_jobs ); + $smarty->assign( 'last_jobs', $last_jobs ); + // Process and display the template $smarty->display('jobs.tpl'); ?> diff --git a/gui/bacula-web/style/default.css b/gui/bacula-web/style/default.css index b8129e2c5a..ef4573b51c 100644 --- a/gui/bacula-web/style/default.css +++ b/gui/bacula-web/style/default.css @@ -156,6 +156,7 @@ a:hover { color: #736F6E } { padding: 2px; font-size: 8pt; + height: 20px; } .box table tr td.label @@ -165,16 +166,19 @@ a:hover { color: #736F6E } /*width: 150px;*/ text-align: left; padding-left: 15px; - padding: 3px; + padding: 5px; margin: 2px; } .box table tr td.info { text-align: center; + vertical-align: middle; /* padding-right: 8em; */ font-weight: bold; background-color: #E0E0E0; + height: auto; + padding: 5px; } .box table tr td.info a { font-size: 8pt;} diff --git a/gui/bacula-web/templates/jobs.tpl b/gui/bacula-web/templates/jobs.tpl index 952cacdb05..c8608898f6 100644 --- a/gui/bacula-web/templates/jobs.tpl +++ b/gui/bacula-web/templates/jobs.tpl @@ -22,37 +22,34 @@
-
-

Last failed jobs (limited to 10)

+

Running jobs

- - - - - - - - - - - {foreach from=$failed_jobs item=job} - - - - - - - - - - - {/foreach} + + + + + + + + + + {foreach from=$running_jobs item=job} + + + + + + + + + + {/foreach}
StatusJob IDBackupJobStart TimeEnd TimeElapsed timeLevelPool
{$job.JobId}{$job.job_name}{$job.StartTime}{$job.EndTime}{$job.elapsed}{$job.Level}{$job.pool_name}
StatusJob IDBackupJobStart TimeElapsed timeLevelPool
{$job.JobStatusLong}{$job.JobId}{$job.Name}{$job.StartTime}{$job.elapsed_time}{$job.Level}{$job.Pool_name}
-
- +
+
-

Last completed jobs

+

Last jobs

@@ -64,20 +61,21 @@ - {foreach from=$completed_jobs item=job} + {foreach from=$last_jobs item=job} - + - + - + {/foreach} -
StatusLevel Pool
{$job.JobId}{$job.job_name}{$job.Job_name} {$job.StartTime} {$job.EndTime} {$job.elapsed} {$job.Level}{$job.pool_name}{$job.Pool_name}
+
+ {include file="footer.tpl"} -- 2.39.5