Net/CheckHost.pm

filter: Statementstmt 57.5% 19 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 3 totaltotal 52.0% 25 / 48 CC 3 SCAR 14.8
CC
3
Cov
51%
request
12.0
prepare_request
2.0
BEGIN
1.0
CRAP 4.4
« Nagios/Plugin/CheckHost/Result.pm ↑ Summary Nagios/Plugin/Threshold/Group.pm »
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.05;
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 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 2 my ($class, @args) = @_;
14  
15 2 bless {
16 gateway => 'https://check-host.net/',
17 ua => LWP::UserAgent->new,
18 @args
19 }, $class;
20 }
21  
22 0 ▶sub prepare_request {
Subroutine prepare_request: not called CC=1 SCAR=6.9
Pod undocumented
23 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 0 ▶sub request {
Subroutine request: not called CC=3 SCAR=24.8
Pod undocumented
41 0 my $self = shift;
42  
43 0 my $http_response = $self->{ua}->request($self->prepare_request(@_));
44 0 ▶ Carp::croak($http_response->status_line)
Branch: 1 branch
BranchTrueFalseTotal
unless $http_response->is_success 0 0 0
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
BranchTrueFalseTotal
if ($response->{"error"}) 0 0 0
50 0 my $error = $response->{error};
51 0 Carp::croak("API error $error");
52 }
53  
54 0 $response;
55 }
56  
57 2 1;
« Nagios/Plugin/CheckHost/Result.pm ↑ Summary Nagios/Plugin/Threshold/Group.pm »