line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::CheckHost; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
40
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
50
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.05; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
6
|
use JSON; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
6
|
|
9
|
2
|
|
|
2
|
|
1279
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
53196
|
|
|
2
|
|
|
|
|
45
|
|
10
|
2
|
|
|
2
|
|
11
|
use URI; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
326
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
0
|
4
|
my ($class, @args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
7
|
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; |