]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/btime.pl
bweb: Update some GPL2 notice to AGPL
[bacula/bacula] / gui / bweb / cgi / btime.pl
1 #!/usr/bin/perl -w
2
3 =head1 LICENSE
4
5    Bweb - A Bacula web interface
6    Bacula® - The Network Backup Solution
7
8    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
9
10    The main author of Bweb is Eric Bollengier.
11    The main author of Bacula is Kern Sibbald, with contributions from
12    many others, a complete list can be found in the file AUTHORS.
13    This program is Free Software; you can redistribute it and/or
14    modify it under the terms of version three of the GNU Affero General Public
15    License as published by the Free Software Foundation and included
16    in the file LICENSE.
17
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    Affero General Public License for more details.
22
23    You should have received a copy of the GNU Affero General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26    02110-1301, USA.
27
28    Bacula® is a registered trademark of Kern Sibbald.
29    The licensor of Bacula is the Free Software Foundation Europe
30    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31    Switzerland, email:ftf@fsfeurope.org.
32
33 =cut
34
35 use strict;
36 use GTime;
37 use Getopt::Long ;
38 use Bweb;
39 use Time::ParseDate qw/parsedate/;
40 use POSIX qw/strftime/;
41 use CGI;
42
43 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
44 $conf->load();
45
46 my $bweb = new Bweb(info => $conf);
47
48 print CGI::header('text/html');
49 $bweb->display_begin();
50 $bweb->can_do('r_view_stat');
51
52 my $arg = $bweb->get_form(qw/qnocache qiso_begin qiso_end qusage qpools 
53                              qpoolusage qnojob jclient_groups qbypool
54                              qfullname db_client_groups qclient_groups/);
55 my ($filter1, undef) = $bweb->get_param('pool');
56
57 if (!$arg->{qiso_begin}) {
58    $arg->{qiso_begin} = strftime('\'%F %H:%M:00\'', localtime(time - 60*60*12));
59    $arg->{qiso_end} = strftime('\'%F %H:%M:00\'', localtime(time));
60 }
61 use Digest::MD5 qw(md5_hex);
62
63 my $md5_rep = md5_hex("$arg->{qiso_begin}:$arg->{qiso_end}:$arg->{qusage}:" . 
64                       "$arg->{jclient_groups}:$arg->{qpoolusage};$arg->{qnojob}") ;
65
66 if ( 0 
67     &&  !$arg->{qnocache} 
68     && $arg->{qiso_begin} 
69     && -f "$conf->{fv_write_path}/$md5_rep.png") 
70 {
71     $arg->{result} = "/bweb/fv/$md5_rep.png";
72     $bweb->display($arg, 'btime.tpl');
73     
74     $bweb->display_end();
75     exit 0;
76 }
77
78 my $top = new GTime(
79                     debug => $conf->{debug},
80                     xmarge => 200,
81                     type => {
82                         spool =>  1,
83                         despool =>  2,
84                         commit => 4,
85                         waiting => 3,
86                         init => 5,
87                     }) ;
88 my $sec = $bweb->{sql}->{STARTTIME_SEC};
89 $sec =~ s/Job.StartTime/Log.Time/;
90 my $reg = $bweb->{sql}->{MATCH};
91
92
93 my %regs = (
94             end_job => ': Bacula',
95             start_job => ': Start Backup|: D.marrage du ',
96             data_despool_time => ': Despooling elapsed time|: Temps du tran',
97             attr_despool_time => ': Sending spooled attrs|: Transfert des attributs',
98             get_drive => ': Using Device',
99             start_spool => ': Spooling',
100             end_spool => ': User specified spool|: Taille du spool',
101             end_spool2 => ': Committing spooled data to|: Transfert des donn',
102     );
103
104 my %regs_en = (
105             end_job => ': Bacula',
106             start_job => ': Start Backup',
107             data_despool_time => ': Despooling elapsed time',
108             attr_despool_time => ': Sending spooled attrs',
109             get_drive => ': Using Device',
110             start_spool => ': Spooling',
111             end_spool => ': User specified spool',
112             end_spool2 => ': Committing spooled data to',
113             );
114
115
116 my %regs_fr = (
117             end_job => ': Bacula',
118             start_job => ': D.marrage du ',
119             data_despool_time => ': Temps du tran',
120             attr_despool_time => ': Transfert des attributs',
121             get_drive => ': Using Device',
122             start_spool => ': Spooling',
123             end_spool => ': Taille du spool',
124             end_spool2 => ': Transfert des donn',
125             );
126
127 my $name = ($arg->{qfullname}) ? 'Job' : 'Name';
128
129 my $filter = join(" OR ", 
130                   map { "Log.LogText $bweb->{sql}->{MATCH} '$_'" } values %regs);
131
132 my $query = "
133 SELECT " . $bweb->dbh_strcat("Job.$name", "'_'", 'Job.Level') . ",
134        $sec,
135        substring(Log.LogText from 8 for 70),
136        Job.JobId,
137        Pool.Name
138
139 FROM  Log INNER JOIN Job USING (JobId) JOIN Pool USING (PoolId)
140 " . ($arg->{jclient_groups}?
141 "     JOIN Client USING (ClientId) 
142       JOIN client_group_member ON (Client.ClientId = client_group_member.clientid) 
143       JOIN client_group USING (client_group_id)
144       WHERE client_group_name IN ($arg->{jclient_groups})
145         AND
146 ":'WHERE') .
147 "
148       Job.StartTime > $arg->{qiso_begin}
149   AND Job.StartTime < $arg->{qiso_end}
150   AND ( $filter )
151   AND Job.Type = 'B'
152   $filter1
153  ORDER BY " . ($arg->{qbypool}?"Pool.Name,":""). "Job.JobId,Log.LogId,Log.Time";
154
155
156 $bweb->debug($query);
157 my $all = $bweb->dbh_selectall_arrayref($query);
158
159 my $lastid = 0;
160 my $lastspool = 0;
161 my $last_name;
162 my $data = [];
163 my $write = {};
164 my $pool = {};
165 my $drive = "";
166 my $end;
167 my $begin;
168 my $last_pool='';
169 foreach my $elt (@$all)
170 {
171     # if bypool is used, we display pool usage after each job block
172     if ($arg->{qbypool} && $last_pool ne $elt->[4]) {
173         foreach my $i (sort keys %$pool) {
174             $top->add_job(label => $i,
175                           data => $pool->{$i});
176         }
177         $pool = {};
178     }
179     if ($lastid && $lastid ne $elt->[3]) {
180         if (!$arg->{qnojob}) {
181             $top->add_job(label => $last_name,
182                           data => $data);
183         }
184         $data = [];
185         $lastspool=0;
186     }
187
188     if ($elt->[2] =~ /$regs{end_job}/) {
189         push @$data, {
190             type  => "commit",
191             begin => $begin,
192             end   => $elt->[1],
193         };
194
195 #    } elsif ($elt->[2] =~ /$regs{attr_despool_time}/) {
196 #
197 #       push @$data, {
198 #           l => $elt->[2],
199 #           type  => "waiting",
200 #           begin => $begin,
201 #           end   => $elt->[1],
202 #       };
203 #
204     } elsif ($elt->[2] =~ /(?:$regs{get_drive}) "([\w\d\s-\.]+)"/) {
205         $drive = $1;
206
207     } elsif ($elt->[2] =~ /(?:$regs{data_despool_time}).*? = (\d+):(\d+):(\d+)/) {
208         # on connait le temps de despool
209         my $t = $1*60*60+ $2*60 + $3;
210
211         if ($t > 3) {           # en dessous de 3s on affiche pas
212             push @$data, {      # temps d'attente du drive
213 #               l => $elt->[2],
214                 type  => "waiting",
215                 begin => $begin,
216                 end   => parsedate($elt->[1]) - $t,
217             };
218
219             push @$data, {
220 #               l => $elt->[2],
221                 type  => "despool",
222                 begin => parsedate($elt->[1]) - $t,
223                 end   => $elt->[1],
224             };
225
226             push @{$write->{$drive}}, { # display only write time
227                 type  => "despool",
228                 begin => parsedate($elt->[1]) - $t,
229                 end   => $elt->[1],
230             };
231
232             push @{$pool->{"$drive: $elt->[4]"}}, {
233                 type  => "despool",
234                 begin => parsedate($elt->[1]) - $t,
235                 end   => $elt->[1],
236             };
237         } else {
238             push @$data, {
239 #               t => $t,
240 #               l => $elt->[2],
241                 type  => "waiting",
242                 begin => $begin,
243                 end   => $elt->[1],
244             };
245         }
246         
247     } elsif ($elt->[2] =~ /$regs{start_spool}/) {
248
249         if (!$lastspool) {
250             push @$data, {
251                 type  => "init",
252                 begin => $begin,
253                 end   => $elt->[1],
254             };  
255         }
256
257         $lastspool = 1;
258
259     } elsif ($elt->[2] =~ /($regs{end_spool}|$regs{end_spool2})/) {
260         push @$data, {
261 #           l => $elt->[2],
262             type  => "spool",
263             begin => $begin,
264             end   => $elt->[1],
265         };
266
267     } elsif ($elt->[2] =~ /$regs{start_job}/) {
268         1;
269     } else {
270         next;
271     }
272
273     $end = $begin;
274     $begin = $elt->[1];
275     $last_name = $elt->[0];
276     $lastid = $elt->[3];
277     $last_pool = $elt->[4];
278 }
279
280 if (!$arg->{qnojob} && $last_name) {
281     $top->add_job(label => $last_name,
282                   data => $data);
283 }
284 if ($arg->{qpoolusage} or $arg->{qbypool}) {
285     foreach my $d (sort keys %$pool) {
286         $top->add_job(label => $d,
287                       data => $pool->{$d});
288     }
289 }
290
291 if ($arg->{qusage}) {
292     foreach my $d (sort keys %$write) {
293         $top->add_job(label => "drive $d",
294                       data => $write->{$d});
295     }
296 }
297
298 $bweb->debug($top);
299 $top->finalize();
300
301 open(FP, ">$conf->{fv_write_path}/$md5_rep.png");
302 binmode FP;
303 # Convert the image to PNG and print it on standard output
304 print FP $GTime::gd->png;
305 close(FP);
306
307 $arg->{result} = "/bweb/fv/$md5_rep.png";
308 $bweb->display( $arg, 'btime.tpl');
309 $bweb->display_end();