Alert/Input/SNMPTrapd.pm

filter: Statementstmt 42.1% 16 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 5 totaltotal 32.7% 20 / 61 CC 5 SCAR 20.1
CC
5
Cov
35%
get
20.0
__ANON__
6.0
open
2.0
CRAP 7.4
« Alert/Output/SNMP/Trap.pm ↑ Summary Alert/Output/Syslog.pm »
1 package Transform::Alert::Input::SNMPTrapd;
2  
3 2 our $VERSION = '1.00'; # VERSION
4 # ABSTRACT: Transform alerts from an internal SNMP Trap daemon
5  
6 2 ▶use sanity;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooX::Types::MooseLike::Base qw(InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Net::SNMPTrapd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 with 'Transform::Alert::Input';
13  
14 has _conn => (
15 is => 'rw',
16 isa => InstanceOf['Net::SNMPTrapd'],
17 lazy => 1,
18 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
19 0 ▶ Net::SNMPTrapd->new( %{shift->connopts} ) || die "SNMPTrapd New failed: ".Net::SNMPTrapd->error;
Branch: 1 branch
BranchTrueFalseTotal
"Net::SNMPTrapd"->new(%{(shift())->connopts;}) or die 'SNMPTrapd New failed: ' . "Net::SNMPTrapd"->error 0 0 0
20 },
21 2 predicate => 1,
22 );
23  
24 0 ▶sub open { shift->_conn }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub opened { shift->_has_conn }
Subroutine opened: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 0 ▶sub get {
Subroutine get: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my $self = shift;
29 0 my $trapd = $self->_conn;
30
31 0 my $trap = $trapd->get_trap(Timeout => 0);
32
33 0 ▶ unless (defined $trap) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $trap) 0 0 0
34 0 $self->log->error('Error grabbing SNMP trap: '.$trapd->error);
35 0 return;
36 }
37 0 ▶ if ($trap eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($trap eq 0) 0 0 0
38 0 $self->log->warn('No SNMP trap in queue during get()');
39 0 return \(''), {};
40 }
41
42 # rejoin message parts
43 0 my $txt = $trap->remoteaddr.':'.$trap->remoteport.' - '.$trap->datagram;
44 0 $trap->process_trap;
45 0 ▶ return (\$txt, {
Branch: 1 branch
BranchTrueFalseTotal
$trap->version == 1 ? : 0 0 0
46 remoteaddr => $trap->remoteaddr,
47 remoteport => $trap->remoteport,
48
49 version => $trap->version,
50 community => $trap->community,
51 pdu_type => $trap->pdu_type,
52 varbinds => $trap->varbinds,
53
54 ($trap->version == 1 ? (
55 ent_OID => $trap->ent_OID,
56 agentaddr => $trap->agentaddr,
57 generic_trap => $trap->generic_trap,
58 specific_trap => $trap->specific_trap,
59 timeticks => $trap->timeticks,
60 ) : (
61 request_ID => $trap->request_ID,
62 error_status => $trap->error_status,
63 error_index => $trap->error_index,
64 )),
65 });
66 }
67  
68 0 ▶sub eof {
Subroutine eof: not called CC=1 SCAR=6.9
Pod undocumented
69 0 my $self = shift;
70 0 my $port = $self->_conn->server;
71  
72 # check if a message is waiting
73 0 my $rin = '';
74 0 vec($rin, fileno($port), 1) = 1;
75 0 return not select($rin, undef, undef, 0);
76 }
77  
78 0 ▶sub close { 1 }
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 2 42;
81  
82 __END__
« Alert/Output/SNMP/Trap.pm ↑ Summary Alert/Output/Syslog.pm »