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