| 1 | # $Id: Syslog.pm 579 2005-11-20 22:52:26Z sungo $ | ||||||||||||||||||||||||||||
| 2 | package POE::Filter::Syslog; | ||||||||||||||||||||||||||||
| 3 | 11 | $POE::Filter::Syslog::VERSION = '1.22'; | |||||||||||||||||||||||||||
| 4 | #ABSTRACT: syslog parser | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Time::ParseDate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | our $SYSLOG_REGEXP = q| | |||||||||||||||||||||||||||
| 13 | ^<(\d+)> # priority -- 1 | ||||||||||||||||||||||||||||
| 14 | (?: | ||||||||||||||||||||||||||||
| 15 | (\S{3})\s+(\d+) # month day -- 2, 3 | ||||||||||||||||||||||||||||
| 16 | \s | ||||||||||||||||||||||||||||
| 17 | (\d+):(\d+):(\d+) # time -- 4, 5, 6 | ||||||||||||||||||||||||||||
| 18 | )? | ||||||||||||||||||||||||||||
| 19 | \s* | ||||||||||||||||||||||||||||
| 20 | (.*) # text -- 7 | ||||||||||||||||||||||||||||
| 21 | $ | ||||||||||||||||||||||||||||
| 22 | |; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 10 | return bless { | |||||||||||||||||||||||||||
| 26 | buffer => '', | ||||||||||||||||||||||||||||
| 27 | }, shift; | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6 | ▶ | sub get_one_start { | ||||||||||||||||||||||||||
|
Subroutine
get_one_start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 6 | my $input = shift; | |||||||||||||||||||||||||||
| 33 | 6 | $self->{buffer} .= join("",@$input); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=8 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 5 | my $incoming = shift; | |||||||||||||||||||||||||||
| 39 | 5 | ▶ | return [] unless $incoming and @$incoming; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$incoming and @$incoming
MC/DC0%0/2
$incoming and @$incoming
$incoming
@$incoming
Truth table33%1/3
A and B
A= $incomingB= @$incoming
| |||||||||||||||||||||||||||||
| 40 | 5 | my $stream = join ("", @$incoming); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | my @found; | |||||||||||||||||||||||||||
| 43 | 5 | ▶ | if($stream and length $stream) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$stream and length $stream
MC/DC0%0/2
$stream and length $stream
$stream
length $stream
Truth table33%1/3
A and B
A= $streamB= length $stream
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 5 | ▶ | while ( $stream =~ s/$SYSLOG_REGEXP//sx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 4 | ▶ | my $time = $2 && parsedate("$2 $3 $4:$5:$6"); | ||||||||||||||||||||||||||
|
Condition66%2/3
$2 && parsedate("$2 $3 $4:$5:$6")
MC/DC50%1/2
$2 && parsedate("$2 $3 $4:$5:$6")
$2
parsedate("$2 $3 $4:$5:$6")
Truth table66%2/3
A && B
A= $2B= parsedate("$2 $3 $4:$5:$6")
| |||||||||||||||||||||||||||||
| 47 | 4 | ▶ | $time ||= time(); | ||||||||||||||||||||||||||
|
Condition100%2/2
$time ||= time
MC/DC100%1/1
$time ||= time
$time
Truth table100%2/2
A
A= $time
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | my $msg = { | |||||||||||||||||||||||||||
| 50 | time => $time, | ||||||||||||||||||||||||||||
| 51 | pri => $1, | ||||||||||||||||||||||||||||
| 52 | facility => int($1/8), | ||||||||||||||||||||||||||||
| 53 | severity => int($1%8), | ||||||||||||||||||||||||||||
| 54 | msg => $7, | ||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | 4 | push @found, $msg; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 5 | return \@found; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 12 | ▶ | sub get_one { | ||||||||||||||||||||||||||
|
Subroutine
get_one: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 12 | my $found = 0; | |||||||||||||||||||||||||||
| 66 | 12 | ▶ | if($self->{buffer} and length $self->{buffer}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"buffer"} and length $self->{"buffer"}
MC/DC50%1/2
$self->{"buffer"} and length $self->{"buffer"}
$self->{"buffer"}
length $self->{"buffer"}
Truth table66%2/3
A and B
A= $self->{"buffer"}B= length $self->{"buffer"}
| |||||||||||||||||||||||||||||
| 67 | 6 | ▶ | if ( $self->{buffer} =~ s/$SYSLOG_REGEXP//sx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 6 | ▶ | my $time = $2 && parsedate("$2 $3 $4:$5:$6"); | ||||||||||||||||||||||||||
|
Condition33%1/3
$2 && parsedate("$2 $3 $4:$5:$6")
MC/DC0%0/2
$2 && parsedate("$2 $3 $4:$5:$6")
$2
parsedate("$2 $3 $4:$5:$6")
Truth table33%1/3
A && B
A= $2B= parsedate("$2 $3 $4:$5:$6")
| |||||||||||||||||||||||||||||
| 69 | 6 | my $msg = { | |||||||||||||||||||||||||||
| 70 | time => $time, | ||||||||||||||||||||||||||||
| 71 | pri => $1, | ||||||||||||||||||||||||||||
| 72 | facility => int($1/8), | ||||||||||||||||||||||||||||
| 73 | severity => int($1%8), | ||||||||||||||||||||||||||||
| 74 | msg => $7, | ||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | 6 | $found = $msg; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 12 | ▶ | if($found) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 6 | return [ $found ]; | |||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||
| 82 | 6 | return []; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub put {} # XXX | ||||||||||||||||||||||||||
|
Subroutine
put: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 11 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # sungo // vim: ts=4 sw=4 noexpandtab | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||