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 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.
39 use Time::ParseDate qw/parsedate/;
40 use POSIX qw/strftime/;
43 my $conf = new Bweb::Config(config_file => $Bweb::config_file);
46 my $bweb = new Bweb(info => $conf);
48 print CGI::header('text/html');
49 $bweb->display_begin();
50 $bweb->can_do('r_view_stat');
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');
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));
61 use Digest::MD5 qw(md5_hex);
63 my $md5_rep = md5_hex("$arg->{qiso_begin}:$arg->{qiso_end}:$arg->{qusage}:" .
64 "$arg->{jclient_groups}:$arg->{qpoolusage};$arg->{qnojob}") ;
69 && -f "$conf->{fv_write_path}/$md5_rep.png")
71 $arg->{result} = "/bweb/fv/$md5_rep.png";
72 $bweb->display($arg, 'btime.tpl');
79 debug => $conf->{debug},
88 my $sec = $bweb->{sql}->{STARTTIME_SEC};
89 $sec =~ s/Job.StartTime/Log.Time/;
90 my $reg = $bweb->{sql}->{MATCH};
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',
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',
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',
127 my $name = ($arg->{qfullname}) ? 'Job' : 'Name';
129 my $filter = join(" OR ",
130 map { "Log.LogText $bweb->{sql}->{MATCH} '$_'" } values %regs);
133 SELECT " . $bweb->dbh_strcat("Job.$name", "'_'", 'Job.Level') . ",
135 substring(Log.LogText from 8 for 70),
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})
148 Job.StartTime > $arg->{qiso_begin}
149 AND Job.StartTime < $arg->{qiso_end}
153 ORDER BY " . ($arg->{qbypool}?"Pool.Name,":""). "Job.JobId,Log.LogId,Log.Time";
156 $bweb->debug($query);
157 my $all = $bweb->dbh_selectall_arrayref($query);
169 foreach my $elt (@$all)
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});
179 if ($lastid && $lastid ne $elt->[3]) {
180 if (!$arg->{qnojob}) {
181 $top->add_job(label => $last_name,
188 if ($elt->[2] =~ /$regs{end_job}/) {
195 # } elsif ($elt->[2] =~ /$regs{attr_despool_time}/) {
204 } elsif ($elt->[2] =~ /(?:$regs{get_drive}) "([\w\d\s-\.]+)"/) {
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;
211 if ($t > 3) { # en dessous de 3s on affiche pas
212 push @$data, { # temps d'attente du drive
216 end => parsedate($elt->[1]) - $t,
222 begin => parsedate($elt->[1]) - $t,
226 push @{$write->{$drive}}, { # display only write time
228 begin => parsedate($elt->[1]) - $t,
232 push @{$pool->{"$drive: $elt->[4]"}}, {
234 begin => parsedate($elt->[1]) - $t,
247 } elsif ($elt->[2] =~ /$regs{start_spool}/) {
259 } elsif ($elt->[2] =~ /($regs{end_spool}|$regs{end_spool2})/) {
267 } elsif ($elt->[2] =~ /$regs{start_job}/) {
275 $last_name = $elt->[0];
277 $last_pool = $elt->[4];
280 if (!$arg->{qnojob} && $last_name) {
281 $top->add_job(label => $last_name,
284 if ($arg->{qpoolusage} or $arg->{qbypool}) {
285 foreach my $d (sort keys %$pool) {
286 $top->add_job(label => $d,
287 data => $pool->{$d});
291 if ($arg->{qusage}) {
292 foreach my $d (sort keys %$write) {
293 $top->add_job(label => "drive $d",
294 data => $write->{$d});
301 open(FP, ">$conf->{fv_write_path}/$md5_rep.png");
303 # Convert the image to PNG and print it on standard output
304 print FP $GTime::gd->png;
307 $arg->{result} = "/bweb/fv/$md5_rep.png";
308 $bweb->display( $arg, 'btime.tpl');
309 $bweb->display_end();