Alert/Output/SNMP.pm

filter: Statementstmt 41.0% 16 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 4 totaltotal 32.7% 20 / 61 CC 5 SCAR 13.9
CC
5
Cov
34%
__ANON__
6.0
open
6.0
close
6.0
CRAP 4.0
« Alert/Input/Syslogd.pm ↑ Summary Alert/Output/Email.pm »
1 package Transform::Alert::Output::SNMP;
2  
3 5 our $VERSION = '1.00'; # VERSION
4 # ABSTRACT: Transform alerts to SNMP traps (base class)
5  
6 5 ▶use sanity;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use MooX::Types::MooseLike::Base qw(InstanceOf Maybe);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Net::SNMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 with 'Transform::Alert::Output';
13  
14 has _session => (
15 is => 'rw',
16 isa => Maybe[InstanceOf['Net::SNMP']],
17 lazy => 1,
18 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
19 0 my $self = shift;
20 0 my ($session, $err) = Net::SNMP->session( %{$self->connopts} );
21 0 ▶ unless ($session) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session) 0 0 0
22 0 $self->log->error('SNMP Session failed: '.$err);
23 0 return;
24 }
25 0 return $session;
26 },
27 5 predicate => 1,
28 clearer => 1,
29 );
30  
31 0 ▶sub open {
Subroutine open: not called CC=2 SCAR=17.9
Pod undocumented
32 0 my $self = shift;
33 $self->_session ||
34 # maybe+default+error still creates an undef attr, which would pass an 'exists' check on predicate
35 0 ▶ do { $self->_clear_session; return; };
Branch: 1 branch
BranchTrueFalseTotal
$self->_session or do { $self->_clear_session; return } 0 0 0
36 }
37 0 ▶sub opened { shift->_has_session; }
Subroutine opened: not called CC=1 SCAR=6.9
Pod undocumented
38 0 ▶sub send { die "Dummy method send() called for Output::SNMPTrap! This must be overloaded!"; }
Subroutine send: not called CC=1 SCAR=6.9
Pod undocumented
39 0 ▶sub close {
Subroutine close: not called CC=2 SCAR=17.9
Pod undocumented
40 0 my $self = shift;
41  
42 0 ▶ if ($self->_has_session) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_session) 0 0 0
43 0 $self->_session->close;
44 0 $self->_clear_session;
45 }
46  
47 0 return 1;
48 }
49  
50 0 ▶sub _translate_msg {
Subroutine _translate_msg: not called CC=2 SCAR=17.9
51 0 my ($self, $msg) = @_;
52 0 ▶ $msg = $$msg if (ref $msg eq 'SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if ref $msg eq "SCALAR" 0 0 0
53  
54 0 $msg =~ s/^\s+|\s+$//g; # remove leading/trailing ws
55  
56 0 return [ map { split /\s+/, $_, 3 } split /[\r\n]+/, $msg ];
57 }
58  
59 5 42;
60  
61 __END__
« Alert/Input/Syslogd.pm ↑ Summary Alert/Output/Email.pm »