| 1 | package Transform::Alert::Input::Syslogd; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $VERSION = '1.00'; # VERSION | |||||||||
| 4 | # ABSTRACT: Transform alerts from an internal Syslog 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::Syslogd 0.04; | ||||||||
|
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::Syslogd'], | ||||||||||
| 17 | lazy => 1, | ||||||||||
| 18 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 19 | 0 | ▶ | Net::Syslogd->new( %{shift->connopts} ) || die "Syslogd New failed: ".Net::Syslogd->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=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 28 | 0 | my $self = shift; | |||||||||
| 29 | 0 | my $syslogd = $self->_conn; | |||||||||
| 30 | |||||||||||
| 31 | 0 | my $msg = $syslogd->get_message(Timeout => 0); | |||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | unless (defined $msg) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $self->log->error('Error grabbing Syslogd message: '.$syslogd->error); | |||||||||
| 35 | 0 | return; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | ▶ | if ($msg eq '0') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | $self->log->warn('No syslog message in queue during get()'); | |||||||||
| 39 | 0 | return \(''), {}; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # rejoin message parts | ||||||||||
| 43 | 0 | my $txt = $msg->remoteaddr.':'.$msg->remoteport.' - '.$msg->datagram; | |||||||||
| 44 | 0 | $msg->process_message; | |||||||||
| 45 | 0 | return (\$txt, { | |||||||||
| 46 | remoteaddr => $msg->remoteaddr, | ||||||||||
| 47 | remoteport => $msg->remoteport, | ||||||||||
| 48 | |||||||||||
| 49 | priority => $msg->priority, | ||||||||||
| 50 | facility => $msg->facility, | ||||||||||
| 51 | severity => $msg->severity, | ||||||||||
| 52 | time => $msg->time(), | ||||||||||
| 53 | hostname => $msg->hostname, | ||||||||||
| 54 | message => $msg->message, | ||||||||||
| 55 | }); | ||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub eof { | ||||||||
|
Subroutine
eof: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 59 | 0 | my $self = shift; | |||||||||
| 60 | 0 | my $port = $self->_conn->server; | |||||||||
| 61 | |||||||||||
| 62 | # check if a message is waiting | ||||||||||
| 63 | 0 | my $rin = ''; | |||||||||
| 64 | 0 | vec($rin, fileno($port), 1) = 1; | |||||||||
| 65 | 0 | return not select($rin, undef, undef, 0); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub close { 1 } | ||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 69 | |||||||||||
| 70 | 2 | 42; | |||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||