line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Report::YAML; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
28
|
use v5.12.5; |
|
2
|
|
|
|
|
7
|
|
8
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
94
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use Rex; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
9
|
|
13
|
2
|
|
|
2
|
|
50
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
122
|
|
14
|
2
|
|
|
2
|
|
19
|
use Rex::Report::Base; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
32
|
|
15
|
|
|
|
|
|
|
require Rex::Commands; |
16
|
2
|
|
|
2
|
|
90
|
use YAML; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
158
|
|
17
|
2
|
|
|
2
|
|
19
|
use base qw(Rex::Report::Base); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1017
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $REPORT_PATH = "./reports"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $report_name_generator = sub { |
22
|
|
|
|
|
|
|
my $str = time(); |
23
|
|
|
|
|
|
|
return $str; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub set_report_name { |
27
|
1
|
|
|
1
|
0
|
62
|
my ( $class, $code ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
1
|
50
|
|
|
|
9
|
if ( ref $class eq "CODE" ) { |
30
|
0
|
|
|
|
|
0
|
$code = $class; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
4
|
if ( ref $code ne "CODE" ) { |
34
|
0
|
|
|
|
|
0
|
die "Rex::Report::YAML->set_report_name(\$code_ref) wrong arguments."; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
35
|
$report_name_generator = $code; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
1
|
|
|
1
|
0
|
4
|
my $that = shift; |
42
|
1
|
|
33
|
|
|
10
|
my $proto = ref($that) || $that; |
43
|
1
|
|
|
|
|
17
|
my $self = $proto->SUPER::new(@_); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
bless( $self, $proto ); |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
2
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub write_report { |
51
|
2
|
|
|
2
|
0
|
6
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
50
|
|
|
23
|
$REPORT_PATH = Rex::Commands::get('report_path') || "reports"; |
54
|
|
|
|
|
|
|
|
55
|
2
|
100
|
|
|
|
60
|
if ( !-d $REPORT_PATH ) { |
56
|
1
|
50
|
|
|
|
116
|
mkdir $REPORT_PATH or die( $! . ": $REPORT_PATH" ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
16
|
my $server_name = Rex::Commands::connection()->server; |
60
|
2
|
50
|
|
|
|
15
|
if ( $server_name eq "" ) { |
61
|
2
|
|
|
|
|
5
|
$server_name = "_local_"; |
62
|
|
|
|
|
|
|
} |
63
|
2
|
100
|
|
|
|
47
|
if ( !-d $REPORT_PATH . "/" . $server_name ) { |
64
|
1
|
|
|
|
|
63
|
mkdir "$REPORT_PATH/$server_name"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
open( |
67
|
2
|
50
|
|
|
|
44
|
my $fh, |
68
|
|
|
|
|
|
|
">", |
69
|
|
|
|
|
|
|
"$REPORT_PATH/$server_name/" |
70
|
|
|
|
|
|
|
. $report_name_generator->($server_name) . ".yml" |
71
|
|
|
|
|
|
|
) or die($!); |
72
|
2
|
|
|
|
|
252
|
print $fh Dump( $self->{__reports__} ); |
73
|
2
|
|
|
|
|
14954
|
close($fh); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
25
|
$self->{__reports__} = {}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# $self->report({ |
79
|
|
|
|
|
|
|
# command => $export, |
80
|
|
|
|
|
|
|
# module => "Rex::Commands::$mod", |
81
|
|
|
|
|
|
|
# start_time => $start_time, |
82
|
|
|
|
|
|
|
# end_time => time, |
83
|
|
|
|
|
|
|
# data => [ @_ ], |
84
|
|
|
|
|
|
|
# success => 1, |
85
|
|
|
|
|
|
|
# changed => 1, |
86
|
|
|
|
|
|
|
# message => "", |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |