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