]> git.sur5r.net Git - bacula/bacula/blob - gui/bacula-web/index.php
bacula-web: Enabled catalog selection in header template
[bacula/bacula] / gui / bacula-web / index.php
1 <?php
2 /* 
3 +-------------------------------------------------------------------------+
4 | Copyright (C) 2004 Juan Luis Francés Jiménez                            |
5 |                                                                         |
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.                  |
10 |                                                                         |
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 +-------------------------------------------------------------------------+ 
16 */
17 session_start();
18 include_once( 'config.inc.php' );
19
20 $dbSql = new Bweb();
21
22 // Assign to template catalogs number
23 //$dbSql->tpl->assign( "dbs", $dbSql->bwcfg->Count_Catalogs() );
24 // Assign dbs
25 /*
26 if ( count($dbSql->dbs) >1 ) {
27   $smarty->assign("dbs", $dbSql->dbs);
28   $smarty->assign("dbs_now", $_SESSION['DATABASE']);
29 }
30 */
31 // Catalog count
32 $catalog_nb = $dbSql->catalog_nb;
33 $dbSql->tpl->assign( 'catalog_nb', $catalog_nb );
34
35 // Stored files number 
36 $totalfiles = $dbSql->GetStoredFiles( ALL );
37 $dbSql->tpl->assign('stored_files',$totalfiles);
38   
39 // Database size
40 $dbSql->tpl->assign('database_size', $dbSql->GetDbSize());
41
42 // Overall stored bytes
43 $result = $dbSql->GetStoredBytes( ALL );
44 $dbSql->tpl->assign('stored_bytes', $dbSql->human_file_size($result['stored_bytes']) );
45
46 // Total stored bytes since last 24 hours
47 $result = $dbSql->GetStoredBytes( LAST_DAY );
48 $dbSql->tpl->assign('bytes_last', $dbSql->human_file_size($result['stored_bytes']) );
49
50 // Total stored files since last 24 hours
51 $files_last = $dbSql->GetStoredFiles( LAST_DAY );
52 $dbSql->tpl->assign('files_last', $files_last );
53
54
55 // Number of clients
56 $nb_clients = $dbSql->Get_Nb_Clients();
57 $dbSql->tpl->assign('clientes_totales',$nb_clients["nb_client"] );
58
59 // Backup Job list for report.tpl and last_run_report.tpl
60 $dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
61
62 // Get volumes list (volumes.tpl)
63 $dbSql->tpl->assign('pools', $dbSql->GetVolumeList() );
64
65 // Last 24 hours completed jobs number
66 $dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
67
68 // Last 24 hours failed jobs number
69 $dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
70
71 // Last 24 hours waiting jobs number
72 $dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
73
74 // Last 24 hours elapsed time (last_run_report.tpl)
75 //$smarty->assign( 'elapsed_jobs', $dbSql->Get_ElapsedTime_Job() );
76
77 // Last 24 hours Job Levels
78 $dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
79 $dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
80 $dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
81
82 // Last 24 hours Job status graph
83 $data   = array();  
84 $status = array( 'completed', 'terminated_errors', 'failed', 'waiting', 'created', 'running', 'error' );
85
86 foreach( $status as $job_status ) {
87         array_push( $data, $dbSql->GetJobsStatistics( $job_status ) );
88 }
89
90 $graph = new BGraph( "graph.png" );
91 $graph->SetData( $data, 'pie', 'text-data-single' );
92 $graph->SetGraphSize( 400, 230 );
93
94 $graph->Render();
95 $dbSql->tpl->assign('graph_jobs', $graph->Get_Image_file() );
96 unset($graph);
97
98 // Pool and volumes graph
99 $data = array();
100 $graph = new BGraph( "graph1.png" );
101
102 $pools = $dbSql->Get_Pools_List();
103
104 foreach( $pools as $pool ) {
105         array_push( $data, $dbSql->GetPoolsStatistics( $pool ) );
106 }
107
108 $graph->SetData( $data, 'pie', 'text-data-single' );
109 $graph->SetGraphSize( 400, 230 );
110
111 $graph->Render();
112 $dbSql->tpl->assign('graph_pools', $graph->Get_Image_file() );
113
114 // Last 7 days stored Bytes graph
115 $data  = array();
116 $graph = new BGraph( "graph2.png" );
117 $days  = array();
118
119 // Get the last 7 days interval (start and end)
120 for( $c = 6 ; $c >= 0 ; $c-- ) {
121         $today = ( mktime() - ($c * LAST_DAY) );
122         array_push( $days, array( 'start' => date( "Y-m-d 00:00:00", $today ), 'end' => date( "Y-m-d 23:59:00", $today ) ) );
123 }
124
125 $days_stored_bytes = array();
126
127 foreach( $days as $day ) {
128   array_push( $days_stored_bytes, $dbSql->GetStoredBytesByInterval( $day['start'], $day['end'] ) );
129 }
130
131 $graph->SetData( $days_stored_bytes, 'bars', 'text-data' );
132 $graph->SetGraphSize( 400, 230 );
133
134 $graph->Render();
135 $dbSql->tpl->assign('graph_stored_bytes', $graph->Get_Image_file() );
136
137 // Last 15 used volumes
138 $vol_list = array();
139
140 $query  = "SELECT DISTINCT Media.Volumename, Media.Lastwritten, Media.VolStatus, Job.JobId FROM Job ";
141 $query .= "LEFT JOIN JobMedia ON Job.JobId = JobMedia.JobId ";
142 $query .= "LEFT JOIN Media ON JobMedia.MediaId = Media.MediaId ";
143 $query .= "ORDER BY Job.JobId DESC ";
144 $query .= "LIMIT 10 ";
145
146 $result = $dbSql->db_link->query( $query );
147
148 if ( PEAR::isError( $result ) )
149         die( "Unable to get last used volumes from catalog \n " . $result->getMessage() );
150 else {
151         while ( $vol = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) 
152                 array_push( $vol_list, $vol );
153 }
154 $dbSql->tpl->assign( 'volume_list', $vol_list );        
155
156 //if ($_GET['Full_popup'] == "yes" || $_GET['pop_graph1'] == "yes" || $_GET['pop_graph2'] == "yes")
157 //        $smarty->display('full_popup.tpl');
158 //else
159
160 // Render template
161 $dbSql->tpl->display('index.tpl');
162 ?>