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