Alert/Output/Syslog.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 0.0% 0 / 4 totaltotal 38.1% 21 / 55 CC 5 SCAR 20.1
CC
5
Cov
41%
__ANON__
20.0
send
6.0
__ANON__
2.0
CRAP 7.4
« Alert/Input/SNMPTrapd.pm ↑ Summary Alert/Input/Syslogd.pm »
1 package Transform::Alert::Output::Syslog;
2  
3 2 our $VERSION = '1.00'; # VERSION
4 # ABSTRACT: Transform alerts to Syslog alerts
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::Syslog;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 with 'Transform::Alert::Output';
13  
14 has _conn => (
15 is => 'rw',
16 isa => InstanceOf['Net::Syslog'],
17 lazy => 1,
18 0 ▶ default => sub { Net::Syslog->new( %{shift->connopts} ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 2 predicate => 1,
20 );
21  
22 # Net::Syslog is a bit picky about its case-sensitivity
23 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
24 0 my ($orig, $self) = (shift, shift);
25 0 my $hash = shift;
26 0 ▶ $hash = { $hash, @_ } unless ref $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash 0 0 0
27  
28 0 foreach my $keyword (qw{ Name Facility Priority Pid SyslogPort SyslogHost }) {
29 0 ▶ $hash->{connopts}{$keyword} = delete $hash->{connopts}{lc $keyword} if (exists $hash->{connopts}{lc $keyword});
Branch: 1 branch
BranchTrueFalseTotal
if exists $$hash{"connopts"}{lc $keyword} 0 0 0
30 }
31
32 0 $orig->($self, $hash);
33 2 };
34  
35 0 ▶sub open { shift->_conn; }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
36 0 ▶sub opened { shift->_has_conn; }
Subroutine opened: not called CC=1 SCAR=6.9
Pod undocumented
37  
38 0 ▶sub send {
Subroutine send: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my ($self, $msg) = @_;
40 0 my $syslog = $self->_conn;
41
42 0 ▶ unless (eval { $syslog->send($$msg) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $syslog->send($$msg) } }) 0 0 0
43 0 $self->log->error('Error sending Syslog message: '.$@);
44 0 return;
45 }
46 0 return 1;
47 }
48  
49 0 ▶sub close { 1; }
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
50  
51 2 42;
52  
53 __END__
« Alert/Input/SNMPTrapd.pm ↑ Summary Alert/Input/Syslogd.pm »