| 1 | package Net::CheckHost; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = 0.04; | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | sub new { | ||||||||||
| 13 | 2 | ▶ | my ($class, @args) = @_; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 14 | |||||||||||
| 15 | 2 | bless { | |||||||||
| 16 | gateway => 'https://check-host.net/', | ||||||||||
| 17 | ua => LWP::UserAgent->new, | ||||||||||
| 18 | @args | ||||||||||
| 19 | }, $class; | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | sub prepare_request { | ||||||||||
| 23 | 0 | ▶ | my ($self, $request, %args) = @_; | ||||||||
|
Subroutine
prepare_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
request: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 42 | |||||||||||
| 43 | 0 | my $http_response = $self->{ua}->request($self->prepare_request(@_)); | |||||||||
| 44 | 0 | ▶ | Carp::croak($http_response->status_line) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | unless $http_response->is_success; | ||||||||||
| 46 | |||||||||||
| 47 | 0 | my $response = decode_json($http_response->decoded_content); | |||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | if ($response->{error}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | my $error = $response->{error}; | |||||||||
| 51 | 0 | Carp::croak("API error $error"); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | $response; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | 1; | |||||||||