lib/App/MadEye/Util.pm

filter: Statementstmt 57.3% 39 / 68 Branchbran 12.5% 1 / 8 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 4 totaltotal 47.7% 52 / 109 CC 9 SCAR 25.3
CC
9
Cov
48%
snmp_session
42.0
timeout
6.0
get_schema_from_pod
3.1
CRAP 12.5
« lib/App/MadEye/Plugin/Agent/Gearmand.pm ↑ Summary lib/App/MadEye/Plugin/Agent/DNS.pm »
1 package App::MadEye::Util;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our @EXPORT = qw/timeout get_schema_from_pod context snmp_session/;
7  
8 2 ▶use Sys::Syslog qw/:DEFAULT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Pod::POM ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Time::HiRes qw/gettimeofday/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Net::SNMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub context () { App::MadEye->context } ## no critic.
Subroutine context: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 0 ▶sub timeout($$&) { ## no critic.
Subroutine timeout: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ( $secs, $msg, $code ) = @_;
19  
20 0 context->log(debug => "run timer: '$msg', $secs");;
21  
22 0 my $last_alarm = 0;
23 0 my $err;
24 0 eval {
25 0 ▶ local $SIG{ALRM} = sub { die "Time out error: $msg" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 $last_alarm = alarm $secs;
27  
28 0 my $start_time = gettimeofday();
29 0 $code->();
30 0 context->log('debug' => "stopwatch: " . (gettimeofday() - $start_time));
31 };
32 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
33 0 $err = $@;
34  
35 0 context->log('error' => $err);
36 }
37 0 alarm $last_alarm; # restore
38  
39 0 return $err;
40 }
41  
42 2 ▶sub get_schema_from_pod {
Subroutine get_schema_from_pod: called CC=3 SCAR=11.4
Pod undocumented
43 2 my $target = shift;
44 2 ▶ my $proto = ref $target || $target;
Condition33%1/3
ref $target || $target
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $target || $target
ref $target $target
Truth table33%1/3
A || B
A= ref $targetB= $target
ABresult
1X1
011
000
45  
46 2 my $parser = Pod::POM->new;
47 2 my $pom = $parser->parse(Class::Inspector->resolved_filename($proto));
48 2 ▶ if (my $schema_node = first { $_->title eq 'SCHEMA' } $pom->head1) {
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema_node = &first(sub { $_->title eq 'SCHEMA'; } , $pom->head1)) { } 2 0 2
49 2 my $schema_content = $schema_node->content;
50 2 $schema_content =~ s/^ //gm;
51 2 my $schema = YAML::Load($schema_content);
52 2 return $schema;
53 } else {
54 0 return; # 404 schema not found.
55 }
56 }
57  
58 0 ▶sub snmp_session {
Subroutine snmp_session: not called CC=6 SCAR=37.4
Pod undocumented
59 0 my ($agent, $host, $callback, ) = @_;
60  
61 0 ▶ my $community = $agent->config->{config}->{community} or die "missing community";
Branch: 1 branch
BranchTrueFalseTotal
my $community = $agent->config->{"config"}{"community"} or die "missing community" 0 0 0
62 0 ▶ my $port = $agent->config->{config}->{port} || 161;
Condition0%0/2
$agent->config->{'config'}{'port'} || 161
l!l
00
MC/DC0%0/1
$agent->config->{'config'}{'port'} || 161
$agent->config->{'config'}{'port'}
Truth table0%0/2
A
A= $agent->config->{'config'}{'port'}
Aresult
11
00
63 0 ▶ my $timeout = $agent->config->{config}->{timeout} || 10;
Condition0%0/2
$agent->config->{'config'}{'timeout'} || 10
l!l
00
MC/DC0%0/1
$agent->config->{'config'}{'timeout'} || 10
$agent->config->{'config'}{'timeout'}
Truth table0%0/2
A
A= $agent->config->{'config'}{'timeout'}
Aresult
11
00
64 0 ▶ my $retries = $agent->config->{config}->{retries} || 1;
Condition0%0/2
$agent->config->{'config'}{'retries'} || 1
l!l
00
MC/DC0%0/1
$agent->config->{'config'}{'retries'} || 1
$agent->config->{'config'}{'retries'}
Truth table0%0/2
A
A= $agent->config->{'config'}{'retries'}
Aresult
11
00
65  
66 0 my ($session, $error) = Net::SNMP->session(
67 -hostname => $host,
68 -community => $community,
69 -port => $port,
70 -timeout => $timeout,
71 -retries => $retries,
72 );
73  
74 0 ▶ if (not defined($session)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $session) { } 0 0 0
75 0 die "ERROR: $error.\n";
76 } else {
77 0 my $response = $callback->($session);
78 0 $session->close();
79 0 return $response;
80 }
81 }
82  
83  
84 2 1;
« lib/App/MadEye/Plugin/Agent/Gearmand.pm ↑ Summary lib/App/MadEye/Plugin/Agent/DNS.pm »