MMM/Report/Html.pm

filter: Statementstmt 19.0% 16 / 84 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 13.8% 25 / 180 CC 37 SCAR 57.9
CC
37
Cov
10%
body_queue
506.0
footer
240.0
new
6.0
CRAP 327.8
↑ Summary MMM/MirrorTask.pm »
1 package MMM::Report::Html;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use MMM;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base qw(MMM::Report);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use MMM::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 MMM::Report::Html
12  
13 =head1 SYNOPSIS
14  
15 use MMM::Report::Html;
16 my $mmm = MMM::Report::Html->new( configfile => $file );
17 $mmm->run();
18  
19 =head1 DESCRIPTION
20  
21 Produce html report of MMM work done.
22  
23 =head1 SEE ALSO
24  
25 L<MMM>
26 L<MMM::Report>
27 L<MMM::Console>
28  
29 =cut
30  
31 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
32 0 my ( $class, @args ) = @_;
33 0 ▶ my $me = $class->SUPER::new(@args) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $me = $class->SUPER::new(@args) or return 0 0 0
34 0 $me->{cgi} = new CGI;
35 0 bless( $me, $class );
36 0 $me->load;
37 0 $me
38 }
39  
40 0 ▶sub header {
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($self) = @_;
42 print $self->{cgi}->start_html(
43 -title => 'MMM report page',
44 -style => { -verbatim => <<EOF }
45  
46 h3 {
47 border-left-style : solid;
48 border-left-width : 8px;
49 padding-left : 6px;
50 }
51  
52 .ok {
53 border-left-color : #24941a;
54 }
55  
56 .err {
57 border-left-color : #d7282b;
58 }
59  
60 .warn {
61 border-left-color : #f1920c;
62 }
63  
64 pre {
65 background-color : #ffd894;
66 overflow : scroll;
67 }
68  
69 EOF
70 ),
71 0 $self->{cgi}->h1( { align => 'center' }, 'MMM report page' ), "\n";
72 }
73  
74 0 ▶sub footer {
Subroutine footer: not called CC=15 SCAR=54.8
Pod documented
75 0 my ($self) = @_;
76  
77 0 my %loc = ();
78 0 ▶ foreach my $item (@{ $self->{tasks} || [] }) {
Condition0%0/2
$self->{'tasks'} || []
l!l
00
MC/DC0%0/1
$self->{'tasks'} || []
$self->{'tasks'}
Truth table0%0/2
A
A= $self->{'tasks'}
Aresult
11
00
79 0 my $task = $item->[0];
80 0 ▶ my %info = %{ $item->[1] || {} };
Condition0%0/2
$item->[1] || {}
l!l
00
MC/DC0%0/1
$item->[1] || {}
$item->[1]
Truth table0%0/2
A
A= $item->[1]
Aresult
11
00
81 0 ▶ if ($info{success}{url}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{"success"}{"url"}) 0 0 0
82 my $m = MMM::Mirror->new(url => $info{success}{url})
83 0 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
my $m = "MMM::Mirror"->new("url", $info{"success"}{"url"}) or next 0 0 0
84 0 ▶ my $h = $self->{mirrorlist}->find_host($m->hostinfo)
Branch: 1 branch
BranchTrueFalseTotal
my $h = $self->{"mirrorlist"}->find_host($m->hostinfo) or next 0 0 0
85 or next;
86 0 my ($lat, $long) = $h->geo;
87 0 ▶ if (defined($lat) && defined($long)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lat and defined $long) 0 0 0
Condition0%0/3
defined $lat and defined $long
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lat and defined $long
defined $lat defined $long
Truth table0%0/3
A and B
A= defined $latB= defined $long
ABresult
0X0
100
111
88 0 push (@{ $loc{$lat}{$long} }, $task->name);
89 }
90 }
91 }
92  
93 0 ▶ if (keys %loc) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %loc) 0 0 0
94 0 my (@string, @mlist);
95 0 my $num = 0;
96 0 foreach my $lat (sort { $b <=> $a } keys %loc) {
97 0 foreach my $long (sort { $b <=> $a } keys %{ $loc{$lat} }) {
98 0 push(@string, sprintf("name=%d;lat=%s;long=%s", ++$num,
99 $lat, $long));
100 0 push(@mlist, sprintf("%d, %d: %s", $lat, $long, join(", ", @{ $loc{$lat}{$long} })));
101 }
102 }
103 {
104 0 my ($lat, $long) = $self->hostinfo()->geo;
105 0 ▶ if (defined($lat) && defined($long)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lat and defined $long) 0 0 0
Condition0%0/3
defined $lat and defined $long
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lat and defined $long
defined $lat defined $long
Truth table0%0/3
A and B
A= defined $latB= defined $long
ABresult
0X0
100
111
106 0 push(@string, sprintf("name=%s;lat=%s;long=%s",
107 'Me', $lat, $long));
108 }
109 }
110  
111 print
112 '<hr width="20%" align="left">', "\n",
113 $self->{cgi}->img({
114 src => 'http://maps.fallingrain.com/perl/map.cgi?kind=topo;x=600;y=400;' .
115 join(';', @string),
116 }
117 ), "\n",
118 $self->{cgi}->p(
119 sprintf('I am %s (%s, %s)',$self->hostinfo()->hostname,
120 0 ▶ map { $_ || 'N/A' } $self->hostinfo()->geo,
Condition0%0/2
$_ || 'N/A'
l!l
00
MC/DC0%0/1
$_ || 'N/A'
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
121 )
122 ), "\n",
123 0 $self->{cgi}->ol({}, $self->{cgi}->li({}, [ @mlist ])), "\n";
124 }
125  
126 0 my $gtime = scalar( gmtime() );
127 0 print <<EOF;
128 <hr width="20%" align="left">
129 <p>Generated by <a href="http://mmm.zarb.org/">MMM $MMM::VERSION</a> at $gtime</p>
130 EOF
131 0 print $self->{cgi}->end_html(), "\n";
132 }
133  
134 0 ▶sub body_queue {
Subroutine body_queue: not called CC=22 SCAR=62.3
Pod documented
135 0 my ($self, $q, %info) = @_;
136 0 printf('<a name="%s">', $q->name);
137 print $self->{cgi}
138 ->h3(
139 {
140 -class => $info{job}{is_running}
141 ? 'warn'
142 : $info{job}{success}
143 ? 'ok'
144 : $info{job}{start}
145 ? 'err'
146 : $info{job}{end}
147 0 ▶ ? 'err'
Branch: 4 branches
BranchTrueFalseTotal
$info{'job'}{'is_running'} ? : 0 0 0
$info{'job'}{'success'} ? : 0 0 0
$info{'job'}{'start'} ? : 0 0 0
$info{'job'}{'end'} ? : 0 0 0
148 : 'warn',
149 },
150 $q->name()
151 ),
152 "</a>\n";
153  
154 0 ▶ if ( $q->val('announce') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q->val("announce")) 0 0 0
155 0 printf( "<p>%s</p>\n", $q->val('announce') );
156 }
157  
158 0 print $self->{cgi}->start_ul();
159 0 ▶ if ( defined($info{job}{size}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info{"job"}{"size"}) 0 0 0
160 print $self->{cgi}->li(
161 sprintf('Size is %dkB', $info{job}{size})
162 0 ), "\n";
163 }
164 print $self->{cgi}->li(
165 $info{job}{is_running}
166 ? 'Is currently running for ' . fmt_duration(scalar(time), $info{job}{is_running} )
167 : $info{job}{next_run_time} > scalar(time)
168 0 ▶ ? sprintf( 'Will be run in %s', fmt_duration(scalar(time), $q->next_run_time ) )
Branch: 2 branches
BranchTrueFalseTotal
$info{'job'}{'is_running'} ? : 0 0 0
$info{'job'}{'next_run_time'} > scalar time ? : 0 0 0
169 : 'Is waiting next process'
170 );
171 0 ▶ if ( $info{job}{start} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info{'job'}{'start'}) { } 0 0 0
172 print $self->{cgi}->li(
173 sprintf(
174 "Last run: %s at %s (took %s)\n",
175 $info{job}{success}
176 ? '<strong>Successed</strong> ' .
177 ($info{success}{url}
178 ? "from <strong>$info{success}{url}</strong>"
179 : $info{success}{sync_from}
180 ? "from <strong>$info{success}{sync_from}</strong>"
181 : ''
182 )
183 : '<strong>Failed</strong>',
184 scalar( gmtime( $info{job}{end} ) ),
185 0 ▶ fmt_duration($info{job}{start}, $info{job}{end}) ,
Branch: 3 branches
BranchTrueFalseTotal
$info{'job'}{'success'} ? : 0 0 0
$info{'success'}{'url'} ? : 0 0 0
$info{'success'}{'sync_from'} ? : 0 0 0
186 )
187 );
188 0 ▶ if ( ! $info{job}{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info{"job"}{"success"}) 0 0 0
189 print $self->{cgi}->li(
190 sprintf( "last success end at %s",
191 scalar( gmtime( $info{success}{end} ) ) )
192 0 ▶ ), "\n" if($info{success}{end});
Branch: 1 branch
BranchTrueFalseTotal
if $info{"success"}{"end"} 0 0 0
193 print $self->{cgi}->li(sprintf(
194 "it is failing for %s", fmt_duration(
195 $info{success}{end} || $info{success}{first_sync}, scalar(time)
196 )
197 )
198 0 ▶ ), "\n" if($info{success}{end} || $info{success}{first_sync});
Branch: 1 branch
BranchTrueFalseTotal
if $info{"success"}{"end"} or $info{"success"}{"first_sync"} 0 0 0
Condition0%0/6
$info{"success"}{"end"} or $info{"success"}{"first_sync"}
l!l&&r!l&&!r
000
$info{'success'}{'end'} || $info{'success'}{'first_sync'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info{"success"}{"end"} or $info{"success"}{"first_sync"}
$info{"success"}{"end"} $info{"success"}{"first_sync"}
MC/DC0%0/2
$info{'success'}{'end'} || $info{'success'}{'first_sync'}
$info{'success'}{'end'} $info{'success'}{'first_sync'}
Truth table0%0/3
A or B
A= $info{"success"}{"end"}B= $info{"success"}{"first_sync"}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $info{'success'}{'end'}B= $info{'success'}{'first_sync'}
ABresult
1X1
011
000
199 }
200 0 print $self->{cgi}->end_ul();
201 0 ▶ if (!$info{job}{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info{"job"}{"success"}) 0 0 0
202 0 ▶ if (@{ $info{job}{error_log} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$info{"job"}{"error_log"} or [];}) 0 0 0
Condition0%0/2
$info{'job'}{'error_log'} || []
l!l
00
MC/DC0%0/1
$info{'job'}{'error_log'} || []
$info{'job'}{'error_log'}
Truth table0%0/2
A
A= $info{'job'}{'error_log'}
Aresult
11
00
203 0 print "<pre>\n";
204 0 ▶ print map { "$_\n" } @{ $info{job}{error_log} || [] };
Condition0%0/2
$info{'job'}{'error_log'} || []
l!l
00
MC/DC0%0/1
$info{'job'}{'error_log'} || []
$info{'job'}{'error_log'}
Truth table0%0/2
A
A= $info{'job'}{'error_log'}
Aresult
11
00
205 0 print "</pre>\n";
206 }
207 }
208 }
209 else {
210 0 print $self->{cgi}->li("Has been never run yet");
211 0 print $self->{cgi}->end_ul();
212 }
213 0 print "<br />\n";
214 }
215  
216 3 1;
217  
218 =head1 AUTHOR
219  
220 Olivier Thauvin <nanardon@nanardon.zarb.org>
221  
222 =head1 COPYRIGHT AND LICENSE
223  
224 Copyright (C) 2006 Olivier Thauvin
225  
226 This program is free software; you can redistribute it and/or
227 modify it under the terms of the GNU General Public License
228 as published by the Free Software Foundation; either version 2
229 of the License, or (at your option) any later version.
230  
231 This program is distributed in the hope that it will be useful,
232 but WITHOUT ANY WARRANTY; without even the implied warranty of
233 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234 GNU General Public License for more details.
235  
236 You should have received a copy of the GNU General Public License
237 along with this program; if not, write to the Free Software
238 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
239  
240 =cut
↑ Summary MMM/MirrorTask.pm »