line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Syslog.pm 579 2005-11-20 22:52:26Z sungo $ |
2
|
|
|
|
|
|
|
package POE::Filter::Syslog; |
3
|
|
|
|
|
|
|
$POE::Filter::Syslog::VERSION = '1.22'; |
4
|
|
|
|
|
|
|
#ABSTRACT: syslog parser |
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
79342
|
use warnings; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
240
|
|
7
|
7
|
|
|
7
|
|
33
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
127
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
668
|
use POE; |
|
7
|
|
|
|
|
36538
|
|
|
7
|
|
|
|
|
34
|
|
10
|
7
|
|
|
7
|
|
48009
|
use Time::ParseDate; |
|
7
|
|
|
|
|
57916
|
|
|
7
|
|
|
|
|
2420
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
25
|
10
|
|
|
10
|
1
|
139
|
return bless { |
26
|
|
|
|
|
|
|
buffer => '', |
27
|
|
|
|
|
|
|
}, shift; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_one_start { |
31
|
6
|
|
|
6
|
1
|
413
|
my $self = shift; |
32
|
6
|
|
|
|
|
43
|
my $input = shift; |
33
|
6
|
|
|
|
|
67
|
$self->{buffer} .= join("",@$input); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get { |
37
|
5
|
|
|
5
|
1
|
4090
|
my $self = shift; |
38
|
5
|
|
|
|
|
7
|
my $incoming = shift; |
39
|
5
|
50
|
33
|
|
|
26
|
return [] unless $incoming and @$incoming; |
40
|
5
|
|
|
|
|
13
|
my $stream = join ("", @$incoming); |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
6
|
my @found; |
43
|
5
|
50
|
33
|
|
|
19
|
if($stream and length $stream) { |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
55
|
while ( $stream =~ s/$SYSLOG_REGEXP//sx ) { |
46
|
4
|
|
66
|
|
|
32
|
my $time = $2 && parsedate("$2 $3 $4:$5:$6"); |
47
|
4
|
|
66
|
|
|
1481
|
$time ||= time(); |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
30
|
my $msg = { |
50
|
|
|
|
|
|
|
time => $time, |
51
|
|
|
|
|
|
|
pri => $1, |
52
|
|
|
|
|
|
|
facility => int($1/8), |
53
|
|
|
|
|
|
|
severity => int($1%8), |
54
|
|
|
|
|
|
|
msg => $7, |
55
|
|
|
|
|
|
|
}; |
56
|
4
|
|
|
|
|
16
|
push @found, $msg; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
5
|
|
|
|
|
12
|
return \@found; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_one { |
64
|
12
|
|
|
12
|
1
|
119
|
my $self = shift; |
65
|
12
|
|
|
|
|
19
|
my $found = 0; |
66
|
12
|
100
|
66
|
|
|
115
|
if($self->{buffer} and length $self->{buffer}) { |
67
|
6
|
50
|
|
|
|
277
|
if ( $self->{buffer} =~ s/$SYSLOG_REGEXP//sx ) { |
68
|
6
|
|
33
|
|
|
108
|
my $time = $2 && parsedate("$2 $3 $4:$5:$6"); |
69
|
6
|
|
|
|
|
5202
|
my $msg = { |
70
|
|
|
|
|
|
|
time => $time, |
71
|
|
|
|
|
|
|
pri => $1, |
72
|
|
|
|
|
|
|
facility => int($1/8), |
73
|
|
|
|
|
|
|
severity => int($1%8), |
74
|
|
|
|
|
|
|
msg => $7, |
75
|
|
|
|
|
|
|
}; |
76
|
6
|
|
|
|
|
13
|
$found = $msg; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
12
|
100
|
|
|
|
34
|
if($found) { |
80
|
6
|
|
|
|
|
43
|
return [ $found ]; |
81
|
|
|
|
|
|
|
} else { |
82
|
6
|
|
|
|
|
25
|
return []; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
0
|
1
|
|
sub put {} # XXX |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# sungo // vim: ts=4 sw=4 noexpandtab |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |