]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/cgi/btime.pl
ebl display progress bar only when we have information
[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 qpoolusage qnojob
51                              jclient_groups db_client_groups qclient_groups/);
52 my ($filter1, undef) = $bweb->get_param('pool');
53
54 if (!$arg->{qiso_begin}) {
55    $arg->{qiso_begin} = strftime('\'%F %H:%M:00\'', localtime(time - 60*60*12));
56    $arg->{qiso_end} = strftime('\'%F %H:%M:00\'', localtime(time));
57 }
58 use Digest::MD5 qw(md5_hex);
59 my $md5_rep = md5_hex("$arg->{qiso_begin}:$arg->{qiso_end}:$arg->{qusage}:" . 
60                       "$arg->{jclient_groups}:$arg->{qpoolusage};$arg->{qnojob}") ;
61
62 print CGI::header('text/html');
63 $bweb->display_begin();
64
65 if (!$arg->{qnocache} && $arg->{qiso_begin} && -f "$conf->{fv_write_path}/$md5_rep.png") {
66     $arg->{result} = "/bweb/fv/$md5_rep.png";
67     $bweb->display($arg, 'btime.tpl');
68     
69     $bweb->display_end();
70     exit 0;
71 }
72
73 my $top = new GTime(
74                     debug => $conf->{debug},
75                     xmarge => 200,
76                     type => {
77                         spool =>  1,
78                         despool =>  2,
79                         commit => 4,
80                         waiting => 3,
81                         init => 5,
82                     }) ;
83 my $sec = $bweb->{sql}->{STARTTIME_SEC};
84 $sec =~ s/Job.StartTime/Log.Time/;
85 my $reg = $bweb->{sql}->{MATCH};
86
87
88 my %regs = (
89             end_job => ': Bacula',
90             start_job => ': Start Backup|: D.marrage du ',
91             data_despool_time => ': Despooling elapsed time|: Temps du tran',
92             attr_despool_time => ': Sending spooled attrs|: Transfert des attributs',
93             get_drive => ': Using Device',
94             start_spool => ': Spooling',
95             end_spool => ': User specified spool|: Taille du spool',
96             end_spool2 => ': Committing spooled data to|: Transfert des donn',
97     );
98
99 my %regs_en = (
100             end_job => ': Bacula',
101             start_job => ': Start Backup',
102             data_despool_time => ': Despooling elapsed time',
103             attr_despool_time => ': Sending spooled attrs',
104             get_drive => ': Using Device',
105             start_spool => ': Spooling',
106             end_spool => ': User specified spool',
107             end_spool2 => ': Committing spooled data to',
108             );
109
110
111 my %regs_fr = (
112             end_job => ': Bacula',
113             start_job => ': D.marrage du ',
114             data_despool_time => ': Temps du tran',
115             attr_despool_time => ': Transfert des attributs',
116             get_drive => ': Using Device',
117             start_spool => ': Spooling',
118             end_spool => ': Taille du spool',
119             end_spool2 => ': Transfert des donn',
120             );
121
122 my $filter = join(" OR ", 
123                   map { "Log.LogText $bweb->{sql}->{MATCH} '$_'" } values %regs);
124
125 my $query = "
126 SELECT " . $bweb->dbh_strcat('Job.Name', "'_'", 'Job.Level') . ",
127        $sec,
128        substring(Log.LogText from 8 for 70),
129        Job.JobId,
130        Pool.Name
131
132 FROM  Log INNER JOIN Job USING (JobId) JOIN Pool USING (PoolId)
133 " . ($arg->{jclient_groups}?
134 "     JOIN Client USING (ClientId) 
135       JOIN client_group_member ON (Client.ClientId = client_group_member.clientid) 
136       JOIN client_group USING (client_group_id)
137       WHERE client_group_name IN ($arg->{jclient_groups})
138         AND
139 ":'WHERE') .
140 "
141       Job.StartTime > $arg->{qiso_begin}
142   AND Job.StartTime < $arg->{qiso_end}
143   AND ( $filter )
144   AND Job.Type = 'B'
145   $filter1
146  ORDER BY Job.JobId,Log.LogId,Log.Time  ";
147
148
149 print STDERR $query if (1 || $conf->{debug});
150 my $all = $bweb->dbh_selectall_arrayref($query);
151
152 my $lastid = 0;
153 my $lastspool = 0;
154 my $last_name;
155 my $data = [];
156 my $write = {};
157 my $pool = {};
158 my $drive = "";
159 my $end;
160 my $begin;
161 foreach my $elt (@$all)
162 {
163     if ($lastid && $lastid ne $elt->[3]) {
164         if (!$arg->{qnojob}) {
165             $top->add_job(label => $last_name,
166                           data => $data);
167         }
168         $data = [];
169         $lastspool=0;
170     }
171
172     if ($elt->[2] =~ /$regs{end_job}/) {
173         push @$data, {
174             type  => "commit",
175             begin => $begin,
176             end   => $elt->[1],
177         };
178
179 #    } elsif ($elt->[2] =~ /$regs{attr_despool_time}/) {
180 #
181 #       push @$data, {
182 #           l => $elt->[2],
183 #           type  => "waiting",
184 #           begin => $begin,
185 #           end   => $elt->[1],
186 #       };
187 #
188     } elsif ($elt->[2] =~ /(?:$regs{get_drive}) "([\w\d]+)"/) {
189         $drive = $1;
190
191     } elsif ($elt->[2] =~ /(?:$regs{data_despool_time}).*? = (\d+):(\d+):(\d+)/) {
192         # on connait le temps de despool
193         my $t = $1*60*60+ $2*60 + $3;
194
195         if ($t > 10) {          # en dessous de 10s on affiche pas
196             push @$data, {      # temps d'attente du drive
197 #               l => $elt->[2],
198                 type  => "waiting",
199                 begin => $begin,
200                 end   => parsedate($elt->[1]) - $t,
201             };
202
203             push @$data, {
204 #               l => $elt->[2],
205                 type  => "despool",
206                 begin => parsedate($elt->[1]) - $t,
207                 end   => $elt->[1],
208             };
209
210             push @{$write->{$drive}}, { # display only write time
211                 type  => "despool",
212                 begin => parsedate($elt->[1]) - $t,
213                 end   => $elt->[1],
214             };
215
216             push @{$pool->{"$drive: $elt->[4]"}}, {
217                 type  => "despool",
218                 begin => parsedate($elt->[1]) - $t,
219                 end   => $elt->[1],
220             };
221         } else {
222             push @$data, {
223 #               t => $t,
224 #               l => $elt->[2],
225                 type  => "waiting",
226                 begin => $begin,
227                 end   => $elt->[1],
228             };
229         }
230         
231     } elsif ($elt->[2] =~ /$regs{start_spool}/) {
232
233         if (!$lastspool) {
234             push @$data, {
235                 type  => "init",
236                 begin => $begin,
237                 end   => $elt->[1],
238             };  
239         }
240
241         $lastspool = 1;
242
243     } elsif ($elt->[2] =~ /($regs{end_spool}|$regs{end_spool2})/) {
244         push @$data, {
245 #           l => $elt->[2],
246             type  => "spool",
247             begin => $begin,
248             end   => $elt->[1],
249         };
250
251     } elsif ($elt->[2] =~ /$regs{start_job}/) {
252         1;
253     } else {
254         next;
255     }
256
257     $end = $begin;
258     $begin = $elt->[1];
259     $last_name = $elt->[0];
260     $lastid = $elt->[3];
261 }
262
263 if (!$arg->{qnojob} && $last_name) {
264     $top->add_job(label => $last_name,
265                   data => $data);
266 }
267 if ($arg->{qpoolusage}) {
268     foreach my $d (sort keys %$pool) {
269         $top->add_job(label => $d,
270                       data => $pool->{$d});
271     }
272 }
273
274 if ($arg->{qusage}) {
275     foreach my $d (sort keys %$write) {
276         $top->add_job(label => "drive $d",
277                       data => $write->{$d});
278     }
279 }
280
281 #print STDERR Data::Dumper::Dumper($top);
282
283 $top->finalize();
284
285 open(FP, ">$conf->{fv_write_path}/$md5_rep.png");
286 binmode FP;
287 # Convert the image to PNG and print it on standard output
288 print FP $GTime::gd->png;
289 close(FP);
290
291 $arg->{result} = "/bweb/fv/$md5_rep.png";
292 $bweb->display( $arg, 'btime.tpl');
293 $bweb->display_end();