| 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
| |||||||||||
| 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
| |||||||||||
| 34 | 0 | $self->log->error('Error grabbing SNMP trap: '.$trapd->error); | |||||||||
| 35 | 0 | return; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | ▶ | if ($trap eq '0') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||