line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Passive::Gearman; |
2
|
1
|
|
|
1
|
|
1266
|
use Moo; |
|
1
|
|
|
|
|
9104
|
|
|
1
|
|
|
|
|
6
|
|
3
|
1
|
|
|
1
|
|
1758
|
use MooX::late; |
|
1
|
|
|
|
|
20331
|
|
|
1
|
|
|
|
|
8
|
|
4
|
1
|
|
|
1
|
|
176
|
use Gearman::Client; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
635
|
use Crypt::Rijndael; |
|
1
|
|
|
|
|
437
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
7
|
use MIME::Base64; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
393
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Nagios::Passive::Base'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'key' => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
isa => 'Str', |
14
|
|
|
|
|
|
|
required => 0, |
15
|
|
|
|
|
|
|
predicate => 'has_key', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has queue => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Str', |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
default => sub { "check_results" }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has gearman => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'Gearman::Client', |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub to_string { |
32
|
4
|
|
|
4
|
0
|
879
|
my $self = shift; |
33
|
4
|
|
|
|
|
7
|
my $template = << 'EOT'; |
34
|
|
|
|
|
|
|
type=%s |
35
|
|
|
|
|
|
|
host_name=%s%s |
36
|
|
|
|
|
|
|
start_time=%i.%i |
37
|
|
|
|
|
|
|
finish_time=%i.%i |
38
|
|
|
|
|
|
|
latency=%i.%i |
39
|
|
|
|
|
|
|
return_code=%i |
40
|
|
|
|
|
|
|
output=%s %s - %s |
41
|
|
|
|
|
|
|
EOT |
42
|
4
|
100
|
|
|
|
87
|
my $result = sprintf $template, |
43
|
|
|
|
|
|
|
'passive', |
44
|
|
|
|
|
|
|
$self->host_name, |
45
|
|
|
|
|
|
|
(defined $self->service_description |
46
|
|
|
|
|
|
|
? sprintf "\nservice_description=%s", $self->service_description |
47
|
|
|
|
|
|
|
: '' ), |
48
|
|
|
|
|
|
|
time,0, |
49
|
|
|
|
|
|
|
time,0, |
50
|
|
|
|
|
|
|
0,0, |
51
|
|
|
|
|
|
|
$self->return_code, |
52
|
|
|
|
|
|
|
$self->check_name, |
53
|
|
|
|
|
|
|
$self->_status_code, |
54
|
|
|
|
|
|
|
$self->_quoted_output; |
55
|
4
|
|
|
|
|
16
|
return $result; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub encrypted_string { |
59
|
2
|
|
|
2
|
0
|
42
|
my $self = shift; |
60
|
2
|
|
|
|
|
6
|
my $payload = $self->to_string; |
61
|
2
|
|
|
|
|
33
|
my $key = $self->key; |
62
|
2
|
|
|
|
|
19
|
$key = substr($key,0,32) . chr(0) x ( 32 - length( $key ) ); |
63
|
2
|
|
|
|
|
26
|
my $crypt = Crypt::Rijndael->new( |
64
|
|
|
|
|
|
|
$key, |
65
|
|
|
|
|
|
|
Crypt::Rijndael::MODE_ECB() # :-( |
66
|
|
|
|
|
|
|
); |
67
|
2
|
|
|
|
|
8
|
$payload = _null_padding($payload,32,'e'); |
68
|
2
|
|
|
|
|
36
|
$crypt->encrypt($payload); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub submit { |
72
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
73
|
0
|
0
|
|
|
|
0
|
my $payload = $self->has_key |
74
|
|
|
|
|
|
|
? $self->encrypted_string |
75
|
|
|
|
|
|
|
: $self->to_string; |
76
|
0
|
0
|
|
|
|
0
|
$self->gearman->dispatch_background($self->queue, encode_base64($payload)) |
77
|
|
|
|
|
|
|
or croak("submitting job failed"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Thanks to Crypt::CBC |
81
|
|
|
|
|
|
|
sub _null_padding { |
82
|
2
|
|
|
2
|
|
5
|
my ($b,$bs,$decrypt) = @_; |
83
|
2
|
50
|
|
|
|
6
|
return unless length $b; |
84
|
2
|
50
|
|
|
|
6
|
$b = length $b ? $b : ''; |
85
|
2
|
50
|
|
|
|
6
|
if ($decrypt eq 'd') { |
86
|
0
|
|
|
|
|
0
|
$b=~ s/\0*$//s; |
87
|
0
|
|
|
|
|
0
|
return $b; |
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
17
|
return $b . pack("C*", (0) x ($bs - length($b) % $bs)); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |