line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
49284
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
2
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
3
|
|
|
|
|
|
|
package Juno::Check::RawCommand; |
4
|
|
|
|
|
|
|
# ABSTRACT: A raw command check for Juno |
5
|
|
|
|
|
|
|
$Juno::Check::RawCommand::VERSION = '0.010'; |
6
|
2
|
|
|
2
|
|
1156
|
use JSON; |
|
2
|
|
|
|
|
22440
|
|
|
2
|
|
|
|
|
10
|
|
7
|
2
|
|
|
2
|
|
272
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
8
|
2
|
|
|
2
|
|
8
|
use Try::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
9
|
2
|
|
|
2
|
|
986
|
use AnyEvent::Util 'fork_call'; |
|
2
|
|
|
|
|
19090
|
|
|
2
|
|
|
|
|
152
|
|
10
|
2
|
|
|
2
|
|
1094
|
use System::Command; |
|
2
|
|
|
|
|
28992
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
1054
|
use Moo; |
|
2
|
|
|
|
|
21736
|
|
|
2
|
|
|
|
|
16
|
|
13
|
2
|
|
|
2
|
|
3518
|
use MooX::Types::MooseLike::Base qw; |
|
2
|
|
|
|
|
9156
|
|
|
2
|
|
|
|
|
150
|
|
14
|
2
|
|
|
2
|
|
1044
|
use namespace::sweep; |
|
2
|
|
|
|
|
29266
|
|
|
2
|
|
|
|
|
10
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Juno::Role::Check'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has cmd => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => Str, |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub check { |
25
|
1
|
|
|
1
|
1
|
2133
|
my $self = shift; |
26
|
1
|
|
|
|
|
42
|
my $cmdattr = $self->cmd; |
27
|
1
|
|
|
|
|
6
|
my @hosts = @{ $self->hosts }; |
|
1
|
|
|
|
|
39
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
11
|
foreach my $host (@hosts) { |
30
|
1
|
50
|
|
|
|
33
|
$self->has_on_before and $self->on_before->( $self, $host ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
fork_call { |
33
|
0
|
|
|
0
|
|
0
|
my $run = $cmdattr; |
34
|
0
|
|
|
|
|
0
|
$run =~ s/%h/$host/g; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
my $cmd = System::Command->new($run); |
37
|
0
|
|
|
|
|
0
|
my $stdoutfh = $cmd->stdout; |
38
|
0
|
|
|
|
|
0
|
my $stderrfh = $cmd->stderr; |
39
|
0
|
|
|
|
|
0
|
my $stdout = do { local $/ = undef; <$stdoutfh>; }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
40
|
0
|
|
|
|
|
0
|
my $stderr = do { local $/ = undef; <$stderrfh>; }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
chomp ( $stdout, $stderr ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
$cmd->close; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# serialize |
47
|
0
|
|
|
|
|
0
|
my $data = { |
48
|
|
|
|
|
|
|
exit => $cmd->exit, |
49
|
|
|
|
|
|
|
stdout => $stdout, |
50
|
|
|
|
|
|
|
stderr => $stderr, |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
return encode_json $data; |
54
|
|
|
|
|
|
|
} sub { |
55
|
|
|
|
|
|
|
# deserialize |
56
|
1
|
|
|
1
|
|
4770
|
my $serialized = shift; |
57
|
1
|
|
|
|
|
8
|
my $data = ''; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
130
|
try { $data = decode_json $serialized } |
60
|
|
|
|
|
|
|
catch { |
61
|
0
|
0
|
|
|
|
0
|
$self->on_fail |
62
|
|
|
|
|
|
|
and $self->on_fail->( $self, $host, $serialized, $_ ); |
63
|
1
|
|
|
|
|
35
|
}; |
64
|
|
|
|
|
|
|
|
65
|
1
|
50
|
|
|
|
44
|
$self->has_on_result and $self->on_result->( $self, $host, $data ); |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
26
|
$data or return; |
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
10
|
if ( $data->{'exit'} == 0 ) { |
70
|
1
|
50
|
|
|
|
17
|
$self->has_on_success |
71
|
|
|
|
|
|
|
and $self->on_success->( $self, $host, $data ); |
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
0
|
|
|
|
0
|
$self->has_on_fail |
74
|
|
|
|
|
|
|
and $self->on_fail->( $self, $host, $data ); |
75
|
|
|
|
|
|
|
} |
76
|
1
|
|
|
|
|
105
|
}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
6718
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |