3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez |
6 | This program is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU General Public License |
8 | as published by the Free Software Foundation; either version 2 |
9 | of the License, or (at your option) any later version. |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 +-------------------------------------------------------------------------+
18 require ("paths.php");
19 require($smarty_path."Smarty.class.php");
20 include "bweb.inc.php";
22 $smarty = new Smarty();
29 $smarty->compile_check = true;
30 $smarty->debugging = false;
31 $smarty->force_compile = true;
33 $smarty->template_dir = "./templates";
34 $smarty->compile_dir = "./templates_c";
35 $smarty->config_dir = "./configs";
38 $smarty->config_load("bacula.conf"); // Load config file
39 $mode = $smarty->get_config_vars("mode");
42 // Getting mode from config file
43 $mode = $dbSql->get_config_param("mode");
47 $smarty->assign( "mode", $mode );
49 // Determine which template to show
50 $indexreport = $dbSql->get_config_param( "IndexReport" );
52 if( $indexreport == 0 ) {
53 $smarty->assign( "last_report", "last_run_report.tpl" );
55 $smarty->assign( "last_report", "report_select.tpl" );
58 // Assign to template catalogs number
59 $smarty->assign( "dbs", $dbSql->Get_Nb_Catalogs() );
63 if ( count($dbSql->dbs) >1 ) {
64 $smarty->assign("dbs", $dbSql->dbs);
65 $smarty->assign("dbs_now", $_SESSION['DATABASE']);
69 // generaldata.tpl & last_run_report.tpl ( Last 24 hours report )
73 // Stored files number
74 $totalfiles = $dbSql->GetStoredFiles();
75 $smarty->assign('files_totales',$totalfiles);
78 $smarty->assign('database_size', $dbSql->GetDbSize());
80 // Overall stored bytes
81 $result = $dbSql->GetStoredBytes( ALL );
82 $smarty->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) );
84 // Total stored bytes since last 24 hours
85 $result = $dbSql->GetStoredBytes( LAST_DAY );
86 $smarty->assign('bytes_totales', $dbSql->human_file_size($result['stored_bytes']) );
89 $nb_clients = $dbSql->Get_Nb_Clients();
90 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
92 // Backup Job list for report.tpl and last_run_report.tpl
93 $smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
95 // Get volumes list (volumes.tpl)
96 $smarty->assign('pools', $dbSql->GetVolumeList() );
98 // Last 24 hours completed jobs number (last_run_report.tpl)
99 $completed_jobs = $dbSql->GetLastJobs();
100 $smarty->assign( 'completed_jobs', $completed_jobs['completed_jobs'] );
102 // Last 24 hours failed jobs number (last_run_report.tpl)
103 $failed_jobs = $dbSql->GetLastErrorJobs();
104 $smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
106 // Last 24 hours elapsed time (last_run_report.tpl)
107 $smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
109 // last_run_report.tpl
110 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
112 // Total Elapsed Time. Only for single Job.
113 if ( $dbSql->driver == "mysql" )
114 $ret = $dbSql->db_link->query("select UNIX_TIMESTAMP(EndTime)-UNIX_TIMESTAMP(StartTime) as elapsed from Job where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-84600")
115 or die ("Error at row 110");
116 if ( $dbSql->driver == "pgsql" )
117 $ret = $dbSql->db_link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
118 or die ("Error at row 113");
119 while ( $res = $ret->fetchRow() ) {
120 if ( $TotalElapsed < 1000000000 ) // Temporal "workaround" ;) Fix later
121 $TotalElapsed += $res[0];
123 if ($TotalElapsed > 86400) // More than 1 day!
124 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
126 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
127 $smarty->assign('TotalElapsed',$TotalElapsed);
132 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
135 if ( $dbSql->driver == "mysql")
136 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
137 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
138 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400
139 order by elapsed "; // Full report array
140 if ( $dbSql->driver == "pgsql")
141 $query = "select (Job.EndTime - Job.StartTime )
142 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
143 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
145 $status = $dbSql->db_link->query($query)
146 or die ("Error: query at row 138");
147 while ( $tmp = $status->fetchRow() ) {
148 $tdate = explode (":",$tmp[0]);
149 if ( $tdate[0] > 300000 ) // Temporal "workaround" ;) Fix later
150 $tmp[0] = "00:00:00";
151 array_push($tmp1,$tmp);
154 $smarty->assign('clients',$tmp1);
158 // Last 24 hours Job status graph
160 $status = array( 'completed', 'completed_errors', 'failed', 'waiting', 'created', 'running', 'error' );
162 foreach( $status as $job_status ) {
163 array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
166 $graph = new BGraph( "graph.png" );
167 $graph->SetData( $data, 'pie', 'text-data-single' );
168 //$graph->SetTitle("Overall jobs status");
169 $graph->SetGraphSize( 400, 230 );
170 //$graph->SetColors( array('green', 'yellow','red','blue','white','green','red') );
173 $smarty->assign('graph_jobs', $graph->Get_Image_file() );
176 // Pool and volumes graph
178 $graph = new BGraph( "graph1.png" );
180 $pools = $dbSql->Get_Pools_List();
182 foreach( $pools as $pool ) {
183 array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
186 $graph->SetData( $data, 'pie', 'text-data-single' );
187 $graph->SetGraphSize( 400, 230 );
190 $smarty->assign('graph_pools', $graph->Get_Image_file() );
192 // Last 7 days stored Bytes graph
194 $graph = new BGraph( "graph2.png" );
197 // Get the last 7 days interval (start and end)
198 for( $c = 6 ; $c >= 0 ; $c-- ) {
199 $today = ( mktime() - ($c * 86400) );
200 array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
203 $days_stored_bytes = array();
205 foreach( $days as $day ) {
206 array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
209 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
210 $graph->SetGraphSize( 400, 230 );
213 $smarty->assign('graph_stored_bytes', $graph->Get_Image_file() );
215 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
216 $smarty->display('full_popup.tpl');
218 $smarty->display('index.tpl');