]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: Added running jobs in jobs page
authorDavide Franco <bacula-dev@dflc.ch>
Tue, 21 Dec 2010 10:55:15 +0000 (11:55 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:43:34 +0000 (14:43 +0200)
 - 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
gui/bacula-web/style/default.css
gui/bacula-web/templates/jobs.tpl

index 1149c9e9f2a60789406fe53cbc09127665b07003..e4fe0bfc4b290f49e30169796bbcd3cc7f411d65 100644 (file)
   $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 ) ) {
          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 ) ) {
          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');
 ?>
index b8129e2c5a6bc67dcca9bb9b639fc782ea724b15..ef4573b51ce6844012e2f88ca7b7b3b9931da202 100644 (file)
@@ -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;}
index 952cacdb05a19fd6778167820574295d5e7d4773..c8608898f6ed55b03f077f2f38bd6cca6e780377 100644 (file)
 </div>
 
 <div id="main_center">
-  <!-- Failed jobs -->  
   <div class="box">
-       <p class="title">Last failed jobs (limited to 10)</p>
+       <p class="title">Running jobs</p>
        <table class="list">
-         <tr>
-               <td class="info">Status</td>
-               <td class="info">Job ID</td>
-               <td class="info">BackupJob</td>
-               <td class="info">Start Time</td>
-               <td class="info">End Time</td>
-               <td class="info">Elapsed time</td>
-               <td class="info">Level</td>
-               <td class="info">Pool</td>
-         </tr>
-         {foreach from=$failed_jobs item=job}
-         <tr>
-               <td> <img width="20" src="style/images/s_error.gif" alt=""/> </td>
-               <td>{$job.JobId}</td>
-               <td>{$job.job_name}</td>
-               <td>{$job.StartTime}</td>
-               <td>{$job.EndTime}</td>
-               <td>{$job.elapsed}</td>
-               <td align="center">{$job.Level}</td>
-               <td>{$job.pool_name}</td>
-         </tr>
-         {/foreach}
+               <tr>
+                       <td class="info">Status</td>
+                       <td class="info">Job ID</td>
+                       <td class="info">BackupJob</td>
+                       <td class="info">Start Time</td>
+                       <td class="info">Elapsed time</td>
+                       <td class="info">Level</td>
+                       <td class="info">Pool</td>
+               </tr>
+               {foreach from=$running_jobs item=job}
+               <tr>
+                       <td>{$job.JobStatusLong}</td>
+                       <td>{$job.JobId}</td>
+                       <td>{$job.Name}</td>
+                       <td>{$job.StartTime}</td>
+                       <td>{$job.elapsed_time}</td>
+                       <td>{$job.Level}</td>
+                       <td>{$job.Pool_name}</td>
+               </tr>
+               {/foreach}
        </table>
-  </div>
-  <!-- Completed jobs --> 
+  </div> <!-- end div box -->
+  <!-- Failed jobs -->  
   <div class="box">
-       <p class="title">Last completed jobs</p>
+       <p class="title">Last jobs</p>
        <table class="list">
          <tr>
                <td class="info">Status</td>
                <td class="info">Level</td>
                <td class="info">Pool</td>
          </tr>
-         {foreach from=$completed_jobs item=job}
+         {foreach from=$last_jobs item=job}
          <tr>
-               <td> <img width="20px" src="style/images/s_ok.gif" alt=""/> </td>
+               <td> <img width="20" src="style/images/{$job.Job_icon}" alt="" title="{$job.JobStatusLong}" /> </td>
                <td>{$job.JobId}</td>
-               <td>{$job.job_name}</td>
+               <td>{$job.Job_name}</td>
                <td>{$job.StartTime}</td>
                <td>{$job.EndTime}</td>
                <td>{$job.elapsed}</td>
                <td align="center">{$job.Level}</td>
-               <td>{$job.pool_name}</td>
+               <td>{$job.Pool_name}</td>
          </tr>
          {/foreach}
-       </table>        
+       </table>
   </div>
+
 </div>
 
 {include file="footer.tpl"}