| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::CheckHost; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
|
2
|
|
|
|
|
1
|
|
|
|
2
|
|
|
|
|
54
|
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
73
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.04; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use JSON; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
11
|
|
|
9
|
2
|
|
|
2
|
|
1536
|
use LWP::UserAgent; |
|
|
2
|
|
|
|
|
59991
|
|
|
|
2
|
|
|
|
|
50
|
|
|
10
|
2
|
|
|
2
|
|
13
|
use URI; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
338
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
2
|
|
|
2
|
0
|
3
|
my ($class, @args) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
14
|
bless { |
|
16
|
|
|
|
|
|
|
gateway => 'https://check-host.net/', |
|
17
|
|
|
|
|
|
|
ua => LWP::UserAgent->new, |
|
18
|
|
|
|
|
|
|
@args |
|
19
|
|
|
|
|
|
|
}, $class; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub prepare_request { |
|
23
|
0
|
|
|
0
|
0
|
|
my ($self, $request, %args) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $uri = URI->new($self->{gateway}); |
|
26
|
0
|
|
|
|
|
|
$uri->path($uri->path . $request); |
|
27
|
0
|
|
|
|
|
|
$uri->query_form(%args); |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $method = 'GET'; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
HTTP::Request->new( |
|
32
|
|
|
|
|
|
|
'GET' => $uri, [ |
|
33
|
|
|
|
|
|
|
'User-Agent' => 'Nagios::Plugin::CheckHost v' . $VERSION, |
|
34
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
|
35
|
|
|
|
|
|
|
'Accept' => 'application/json', |
|
36
|
|
|
|
|
|
|
] |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub request { |
|
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $http_response = $self->{ua}->request($self->prepare_request(@_)); |
|
44
|
0
|
0
|
|
|
|
|
Carp::croak($http_response->status_line) |
|
45
|
|
|
|
|
|
|
unless $http_response->is_success; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $response = decode_json($http_response->decoded_content); |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($response->{error}) { |
|
50
|
0
|
|
|
|
|
|
my $error = $response->{error}; |
|
51
|
0
|
|
|
|
|
|
Carp::croak("API error $error"); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$response; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |