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 /*$client = $dbSql->db_link->query("select count(*) from Client")
74 or die ("Error query: 1");*/
75 $totalfiles = $dbSql->db_link->query("select count(FilenameId) from Filename") or die ("Error query: 2");
77 if ( PEAR::isError( $totalfiles ) ) {
78 die( "Unable to get Total Files information from catalog" . $totalfiles->getMessage() );
80 $tmp = $totalfiles->fetchRow();
81 $smarty->assign('files_totales',$tmp[0]);
85 switch( $dbSql->driver )
88 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
91 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'";
94 $query = "select sum(JobBytes),count(*) from Job where Endtime <= NOW() and UNIX_TIMESTAMP(EndTime) > UNIX_TIMESTAMP(NOW())-86400";
98 $last24bytes = $dbSql->db_link->query( $query ) or die ("Failed to get Total Job Bytes from catalog");
100 if ( PEAR::isError( $last24bytes ) ) {
101 die( "Unable to get Total Job Bytes from catalog" . $last24bytes->getMessage() );
103 $tmp = $last24bytes->fetchRow();
105 // Transfered bytes since last 24 hours
106 $smarty->assign('bytes_totales', $dbSql->human_file_size( $tmp[0] ) );
108 $smarty->assign('total_jobs', $tmp[1]);
110 $last24bytes->free();
114 $smarty->assign('database_size', $dbSql->GetDbSize());
116 // Total bytes stored
117 $bytes_stored = $dbSql->db_link->getOne("select SUM(VolBytes) from Media") or die ("Failed to get Total stored Bytes from catalog");
118 $smarty->assign('bytes_stored', $dbSql->human_file_size($bytes_stored) );
121 $nb_clients = $dbSql->Get_Nb_Clients();
122 $smarty->assign('clientes_totales',$nb_clients["nb_client"] );
124 // Backup Job list for report.tpl and last_run_report.tpl
125 $smarty->assign( 'total_name_jobs', $dbSql->Get_BackupJob_Names() );
127 // Get volumes list (volumes.tpl)
128 $smarty->assign('pools',$dbSql->GetVolumeList() );
130 // Last 24 hours completed jobs number (last_run_report.tpl)
131 $completed_jobs = $dbSql->GetLastJobs();
132 $smarty->assign( 'completed_jobs', $completed_jobs['completed_jobs'] );
134 // Last 24 hours failed jobs number (last_run_report.tpl)
135 $failed_jobs = $dbSql->GetLastErrorJobs();
136 $smarty->assign( 'failed_jobs', $failed_jobs['failed_jobs'] );
138 // Last 24 hours elapsed time (last_run_report.tpl)
139 $smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
141 // last_run_report.tpl
142 if ( $mode == "Lite" && $_GET['Full_popup'] == "yes" ) {
144 // Total Elapsed Time. Only for single Job.
145 if ( $dbSql->driver == "mysql" )
146 $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")
147 or die ("Error at row 110");
148 if ( $dbSql->driver == "pgsql" )
149 $ret = $dbSql->db_link->query("select EndTime - StartTime as elapsed from Job where EndTime <= NOW() and EndTime > NOW() - 84600 * interval '1 second'")
150 or die ("Error at row 113");
151 while ( $res = $ret->fetchRow() ) {
152 if ( $TotalElapsed < 1000000000 ) // Temporal "workaround" ;) Fix later
153 $TotalElapsed += $res[0];
155 if ($TotalElapsed > 86400) // More than 1 day!
156 $TotalElapsed = gmstrftime("%d days %H:%M:%S", $TotalElapsed);
158 $TotalElapsed = gmstrftime("%H:%M:%S", $TotalElapsed);
159 $smarty->assign('TotalElapsed',$TotalElapsed);
164 else if ($mode == "Full" || $_GET['Full_popup'] == "yes" ){
167 if ( $dbSql->driver == "mysql")
168 $query = "select SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) )
169 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
170 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400
171 order by elapsed "; // Full report array
172 if ( $dbSql->driver == "pgsql")
173 $query = "select (Job.EndTime - Job.StartTime )
174 as elapsed,Job.Name,Job.StartTime,Job.EndTime,Job.Level,Pool.Name,Job.JobStatus from Job
175 LEFT JOIN Pool ON Job.PoolId=Pool.PoolId where EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second'
177 $status = $dbSql->db_link->query($query)
178 or die ("Error: query at row 138");
179 while ( $tmp = $status->fetchRow() ) {
180 $tdate = explode (":",$tmp[0]);
181 if ( $tdate[0] > 300000 ) // Temporal "workaround" ;) Fix later
182 $tmp[0] = "00:00:00";
183 array_push($tmp1,$tmp);
186 $smarty->assign('clients',$tmp1);
190 // Last 24 hours Job status graph
192 $status = array( 'completed', 'completed_errors', 'failed', 'waiting', 'created', 'running', 'error' );
194 foreach( $status as $job_status ) {
195 array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
198 $graph = new BGraph( "graph.png" );
199 $graph->SetData( $data, 'pie', 'text-data-single' );
200 //$graph->SetTitle("Overall jobs status");
201 $graph->SetGraphSize( 400, 230 );
202 //$graph->SetColors( array('green', 'yellow','red','blue','white','green','red') );
205 $smarty->assign('graph_jobs', $graph->Get_Image_file() );
208 // Pool and volumes graph
210 $graph = new BGraph( "graph1.png" );
212 $pools = $dbSql->Get_Pools_List();
214 foreach( $pools as $pool ) {
215 array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
218 $graph->SetData( $data, 'pie', 'text-data-single' );
219 $graph->SetGraphSize( 400, 230 );
223 $smarty->assign('graph_pools', $graph->Get_Image_file() );
225 if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
226 $smarty->display('full_popup.tpl');
228 $smarty->display('index.tpl');