| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||