5 Bweb - A Bacula web interface
6 Bacula® - The Network Backup Solution
8 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
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
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.
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
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.
35 # Do like cross road signal
36 # red wait, green go, despooling blue
42 use Time::ParseDate qw/parsedate/;
43 use POSIX qw/strftime/;
46 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
49 my $bweb = new Bweb(info => $conf);
51 print CGI::header('text/html');
52 $bweb->display_begin();
53 $bweb->can_do('r_view_stat');
55 my $arg = $bweb->get_form(qw/qnocache qiso_begin qiso_end qusage qpools
56 qpoolusage qnojob jclient_groups qbypool
57 qfullname db_client_groups qclient_groups/);
58 my ($filter1, undef) = $bweb->get_param('pool');
60 if (!$arg->{qiso_begin}) {
61 $arg->{qiso_begin} = strftime('\'%F %H:%M:00\'', localtime(time - 60*60*12));
62 $arg->{qiso_end} = strftime('\'%F %H:%M:00\'', localtime(time));
64 use Digest::MD5 qw(md5_hex);
66 my $md5_rep = md5_hex("$arg->{qiso_begin}:$arg->{qiso_end}:$arg->{qusage}:" .
67 "$arg->{jclient_groups}:$arg->{qpoolusage};$arg->{qnojob}") ;
72 && -f "$conf->{fv_write_path}/$md5_rep.png")
74 $arg->{result} = "/bweb/fv/$md5_rep.png";
75 $bweb->display($arg, 'btime.tpl');
82 debug => $conf->{debug},
91 my $sec = $bweb->{sql}->{STARTTIME_SEC};
92 $sec =~ s/Job.StartTime/Log.Time/;
93 my $reg = $bweb->{sql}->{MATCH};
97 end_job => ': Bacula',
98 start_job => ': Start Backup|: D.marrage du ',
99 data_despool_time => ': Despooling elapsed time|: Temps du tran',
100 attr_despool_time => ': Sending spooled attrs|: Transfert des attributs',
101 get_drive => ': Using Device',
102 start_spool => ': Spooling',
103 end_spool => ': User specified spool|: Taille du spool',
104 end_spool2 => ': Committing spooled data to|: Transfert des donn',
108 end_job => ': Bacula',
109 start_job => ': Start Backup',
110 data_despool_time => ': Despooling elapsed time',
111 attr_despool_time => ': Sending spooled attrs',
112 get_drive => ': Using Device',
113 start_spool => ': Spooling',
114 end_spool => ': User specified spool',
115 end_spool2 => ': Committing spooled data to',
120 end_job => ': Bacula',
121 start_job => ': D.marrage du ',
122 data_despool_time => ': Temps du tran',
123 attr_despool_time => ': Transfert des attributs',
124 get_drive => ': Using Device',
125 start_spool => ': Spooling',
126 end_spool => ': Taille du spool',
127 end_spool2 => ': Transfert des donn',
130 my $name = ($arg->{qfullname}) ? 'Job' : 'Name';
132 my $filter = join(" OR ",
133 map { "Log.LogText $bweb->{sql}->{MATCH} '$_'" } values %regs);
136 SELECT " . $bweb->dbh_strcat("Job.$name", "'_'", 'Job.Level') . ",
138 substring(Log.LogText from 8 for 70),
142 FROM Log INNER JOIN Job USING (JobId) JOIN Pool USING (PoolId)
143 " . ($arg->{jclient_groups}?
144 " JOIN Client USING (ClientId)
145 JOIN client_group_member ON (Client.ClientId = client_group_member.clientid)
146 JOIN client_group USING (client_group_id)
147 WHERE client_group_name IN ($arg->{jclient_groups})
151 Job.StartTime > $arg->{qiso_begin}
152 AND Job.StartTime < $arg->{qiso_end}
156 ORDER BY " . ($arg->{qbypool}?"Pool.Name,":""). "Job.JobId,Log.LogId,Log.Time";
159 $bweb->debug($query);
160 my $all = $bweb->dbh_selectall_arrayref($query);
172 foreach my $elt (@$all)
174 # if bypool is used, we display pool usage after each job block
175 if ($arg->{qbypool} && $last_pool ne $elt->[4]) {
176 foreach my $i (sort keys %$pool) {
177 $top->add_job(label => $i,
178 data => $pool->{$i});
182 if ($lastid && $lastid ne $elt->[3]) {
183 if (!$arg->{qnojob}) {
184 $top->add_job(label => $last_name,
191 if ($elt->[2] =~ /$regs{end_job}/) {
198 # } elsif ($elt->[2] =~ /$regs{attr_despool_time}/) {
207 } elsif ($elt->[2] =~ /(?:$regs{get_drive}) "([\w\d\s\-\.]+)"/) {
210 } elsif ($elt->[2] =~ /(?:$regs{data_despool_time}).*? = (\d+):(\d+):(\d+)/) {
211 # on connait le temps de despool
212 my $t = $1*60*60+ $2*60 + $3;
214 if ($t > 3) { # en dessous de 3s on affiche pas
215 push @$data, { # temps d'attente du drive
219 end => parsedate($elt->[1]) - $t,
225 begin => parsedate($elt->[1]) - $t,
229 push @{$write->{$drive}}, { # display only write time
231 begin => parsedate($elt->[1]) - $t,
235 push @{$pool->{"$drive: $elt->[4]"}}, {
237 begin => parsedate($elt->[1]) - $t,
250 } elsif ($elt->[2] =~ /$regs{start_spool}/) {
262 } elsif ($elt->[2] =~ /($regs{end_spool}|$regs{end_spool2})/) {
270 } elsif ($elt->[2] =~ /$regs{start_job}/) {
278 $last_name = $elt->[0];
280 $last_pool = $elt->[4];
283 if (!$arg->{qnojob} && $last_name) {
284 $top->add_job(label => $last_name,
287 if ($arg->{qpoolusage} or $arg->{qbypool}) {
288 foreach my $d (sort keys %$pool) {
289 $top->add_job(label => $d,
290 data => $pool->{$d});
294 if ($arg->{qusage}) {
295 foreach my $d (sort keys %$write) {
296 $top->add_job(label => "drive $d",
297 data => $write->{$d});
304 open(FP, ">$conf->{fv_write_path}/$md5_rep.png");
306 # Convert the image to PNG and print it on standard output
307 print FP $GTime::gd->png;
310 $arg->{result} = "/bweb/fv/$md5_rep.png";
311 $bweb->display( $arg, 'btime.tpl');
312 $bweb->display_end();