| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
*/
-// Last Err: 11
-define('CONFIG_DIR', "configs");
-define('CONFIG_FILE', "bacula.conf");
-define('BACULA_TYPE_BYTES_FILES', 1);
-define('BACULA_TYPE_FILES_JOBID', 2);
-define('BACULA_TYPE_BYTES_ENDTIME_ALLJOBS', 69);
-
require_once "paths.php";
require_once "DB.php"; // Pear DB
require_once "config.inc.php";
}
// Media used bytes in a human format
$media['volbytes'] = $this->human_file_size( $media['volbytes'] );
- //echo "volume " . $media['volumename'] . 'vol bytes' .$media['volbytes'] . '<br />';
} else {
$media['lastwritten'] = "N/A";
$media['expire'] = "N/A";
$media['volbytes'] = "0 KB";
}
+
+ // Odd or even row
+ if( count( $volumes[ $pool['name'] ] ) % 2)
+ $media['class'] = 'odd';
+
// Add the media in pool array
array_push( $volumes[ $pool['name']], $media);
}
return $volumes;
} // end function GetVolumeList()
- public function CountLastJobs( $delay = LAST_DAY, $status )
+ public function CountJobs( $delay = LAST_DAY, $status = 'any' )
{
- $query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
+ $query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
+ $where_delay = "";
+ $where_status = "";
// Interval condition for SQL query
- $end_date = mktime();
- $start_date = $end_date - $delay;
+ if( $delay != ALL ) {
+ $end_date = mktime();
+ $start_date = $end_date - $delay;
- $start_date = date( "Y-m-d H:i:s", $start_date );
- $end_date = date( "Y-m-d H:i:s", $end_date );
+ $start_date = date( "Y-m-d H:i:s", $start_date );
+ $end_date = date( "Y-m-d H:i:s", $end_date );
- $query .= "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+ $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+ }
- // Job Status for SQL query
- switch( $status )
- {
- case 'completed':
- $query .= "AND JobStatus = 'T' ";
- break;
- case 'failed':
- $query .= "AND JobStatus = 'f' ";
- break;
- } // end switch
+ if( $status != 'any' ) {
+ switch( $status )
+ {
+ case 'completed':
+ $where_status = "JobStatus = 'T' ";
+ break;
+ case 'failed':
+ $where_status = "JobStatus IN ('f','E') ";
+ break;
+ case 'canceled':
+ $where_status = "JobStatus = 'A' ";
+ break;
+ case 'waiting':
+ $where_status = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+ break;
+ } // end switch
+ }
+ if( !empty($where_delay) )
+ $query = $query . $where_delay . 'AND ' . $where_status;
+ else {
+ if( !empty($where_status) )
+ $query = $query . 'WHERE ' . $where_status;
+ }
+
$jobs = $this->db_link->query( $query );
if (PEAR::isError( $jobs ) ) {
- die( "Unable to get last $status jobs number from catalog <br />" . $status->getMessage() );
+ die( "Unable to get last $status jobs number from catalog <br />" . $jobs->getMessage() );
}else {
- return $jobs->fetchRow( DB_FETCHMODE_ASSOC );
+ $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC );
+ return $jobs['job_nb'];
}
}
}
}
+ // Return elasped time string for a job
+ function Get_ElapsedTime( $start_time, $end_time )
+ {
+ $diff = $end_time - $start_time;
+
+ $daysDiff = sprintf("%02d", floor($diff/60/60/24) );
+ $diff -= $daysDiff*60*60*24;
+
+ $hrsDiff = sprintf("%02d", floor($diff/60/60) );
+ $diff -= $hrsDiff*60*60;
+
+ $minsDiff = sprintf("%02d", floor($diff/60) );
+ $diff -= $minsDiff*60;
+ $secsDiff = sprintf("%02d", $diff );
+
+ if( $daysDiff > 0 )
+ return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff;
+ else
+ return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff;
+ }
+
public function Get_ElapsedTime_Job( $delay = LAST_DAY )
{
$query = "";
$total_elapsed += $time['elapsed'];
}
// Verify if elapsed time is more than 1 day
- if ( $total_elapsed > 86400 ) {
+ if ( $total_elapsed > LAST_DAY ) {
return date("%d days H:i:s", $total_elapsed );
}else {
return date("H:i:s", $total_elapsed );
$where = "AND JobStatus = 'T' ";
$label = "Completed";
break;
- case 'completed_errors':
- $where = "AND JobStatus = 'E' ";
- $label = "Completed with errors";
+ case 'terminated_errors':
+ $where = $interval_where . "JobStatus = 'E' ";
+ $label = "Terminated with errors";
break;
case 'failed':
$where = "AND JobStatus = 'f' ";
return array( $day, $stored_bytes );
}
}
+
+ public function GetStoredBytesByJob( $jobname, $start_date, $end_date )
+ {
+ $query = "SELECT SUM(JobBytes) as stored_bytes, EndTime FROM Job ";
+ $query .= "WHERE ( EndTime BETWEEN '$start_date' AND '$end_date' ) AND ";
+ $query .= "Name = '$jobname'";
+
+ echo 'query ' . $query . '<br />';
+
+ $result = $this->db_link->query( $query );
+
+ if( PEAR::isError( $result ) ) {
+ die( "Unable to get Job Bytes from catalog" );
+ }else{
+ $stored_bytes = 0;
+ $tmp = $result->fetchRow( DB_FETCHMODE_ASSOC );
+
+ $day = date( "D d", strtotime($end_date) );
+
+ if( isset( $tmp['stored_bytes'] ) ) {
+ $hbytes = $this->human_file_size( $tmp['stored_bytes'], 3, 'GB');
+ $hbytes = explode( " ", $hbytes );
+ $stored_bytes = $hbytes[0];
+ }
+
+ return array( $day, $stored_bytes );
+ }
+ }
} // end class Bweb
?>