line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Plugin::Syslog; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1738
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: syslog server input plugin for saftpresse |
6
|
|
|
|
|
|
|
our $VERSION = '1.6'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::Plugin'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8801
|
use Time::Piece; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process { |
13
|
0
|
|
|
0
|
1
|
|
my ( $self, $stash ) = @_; |
14
|
0
|
|
|
|
|
|
my $line = $stash->{'message'}; |
15
|
0
|
0
|
|
|
|
|
if( ! defined $line ) { |
16
|
0
|
|
|
|
|
|
return; |
17
|
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
$line =~ s/[\r\n]*$//; |
19
|
0
|
|
|
|
|
|
my $event = $self->parse_rfc3164_line( $line ); |
20
|
0
|
0
|
|
|
|
|
if( defined $event ) { |
21
|
0
|
|
|
|
|
|
$self->incr_one('events', 'by_host', $event->{'host'} ); |
22
|
0
|
|
|
|
|
|
$self->incr_one('events', 'by_program', $event->{'program'} ); |
23
|
0
|
|
|
|
|
|
@$stash{ keys %$event } = values %$event; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has priorities => ( |
30
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef', lazy => 1, |
31
|
|
|
|
|
|
|
default => sub { [ |
32
|
|
|
|
|
|
|
'emerg', |
33
|
|
|
|
|
|
|
'alert', |
34
|
|
|
|
|
|
|
'crit', |
35
|
|
|
|
|
|
|
'error', |
36
|
|
|
|
|
|
|
'warn', |
37
|
|
|
|
|
|
|
'notice', |
38
|
|
|
|
|
|
|
'info', |
39
|
|
|
|
|
|
|
'debug', |
40
|
|
|
|
|
|
|
] }, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has facilities => ( |
44
|
|
|
|
|
|
|
is => 'ro', isa => 'ArrayRef', lazy => 1, |
45
|
|
|
|
|
|
|
default => sub { [ |
46
|
|
|
|
|
|
|
'kernel', |
47
|
|
|
|
|
|
|
'user', |
48
|
|
|
|
|
|
|
'mail', |
49
|
|
|
|
|
|
|
'daemon', |
50
|
|
|
|
|
|
|
'auth', |
51
|
|
|
|
|
|
|
'syslog', |
52
|
|
|
|
|
|
|
'printer', |
53
|
|
|
|
|
|
|
'news', |
54
|
|
|
|
|
|
|
'uucp', |
55
|
|
|
|
|
|
|
'cron', |
56
|
|
|
|
|
|
|
'authpriv', |
57
|
|
|
|
|
|
|
'ftp', |
58
|
|
|
|
|
|
|
'ntp', |
59
|
|
|
|
|
|
|
'audit', |
60
|
|
|
|
|
|
|
'alert', |
61
|
|
|
|
|
|
|
'clock', |
62
|
|
|
|
|
|
|
'local0', |
63
|
|
|
|
|
|
|
'local1', |
64
|
|
|
|
|
|
|
'local2', |
65
|
|
|
|
|
|
|
'local3', |
66
|
|
|
|
|
|
|
'local4', |
67
|
|
|
|
|
|
|
'local5', |
68
|
|
|
|
|
|
|
'local6', |
69
|
|
|
|
|
|
|
'local7', |
70
|
|
|
|
|
|
|
] }, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub parse_rfc3164_line { |
74
|
0
|
|
|
0
|
0
|
|
my ( $self, $line ) = @_; |
75
|
0
|
|
|
|
|
|
my ( $d, $time_str, $host, $proc, $pid, $message ) = |
76
|
|
|
|
|
|
|
$line =~ m/^<(\d+)>([A-Z][a-z]{2} [\d ]\d \d\d:\d\d:\d\d|\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+\+\d\d:\d\d) ([^ ]+) ([^\[]+)(?:\[(\d+)\])?: (.*)$/; |
77
|
0
|
0
|
0
|
|
|
|
if( ! defined $d || ! defined $time_str || ! defined $host || ! defined $proc || ! defined $message ) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
my $priority = $self->priorities->[ $d & 7 ]; |
81
|
0
|
|
|
|
|
|
my $facility = $self->facilities->[ $d >> 3 ]; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $time; |
84
|
0
|
0
|
|
|
|
|
if( $time_str =~ /^\d{4}-\d\d-\d\dT/ ) { # like 2015-05-29T15:15:55.716831+02:00 |
|
|
0
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$time_str =~ s/\.\d{6}//; # remove microseconds |
86
|
0
|
|
|
|
|
|
$time_str =~ s/:(\d\d)$/$1/; # remove : from zone |
87
|
0
|
|
|
|
|
|
eval { $time = Time::Piece->strptime($time_str, "%Y-%m-%dT%H:%M:%S%z"); }; |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} elsif( $time_str =~ /^[A-Z][a-z]{2} / ) { # like May 29 15:27:32 |
89
|
0
|
|
|
|
|
|
eval { $time = Time::Piece->strptime($time_str, "%b %e %H:%M:%S"); }; |
|
0
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $now = Time::Piece->new; |
91
|
|
|
|
|
|
|
# guess year |
92
|
0
|
0
|
|
|
|
|
if( $time->mon > $now->mon ) { |
93
|
|
|
|
|
|
|
# Time::Piece->year is ro :-/ |
94
|
0
|
|
|
|
|
|
$time->[5] = $now->[5] - 1; |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
|
$time->[5] = $now->[5]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
|
|
|
|
|
return; # unknown date format :-/ |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return { |
103
|
0
|
0
|
|
|
|
|
defined $priority ? (priority => $priority) : (), |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
104
|
|
|
|
|
|
|
defined $facility ? (facility => $facility) : (), |
105
|
|
|
|
|
|
|
time => $time, |
106
|
|
|
|
|
|
|
host => $host, |
107
|
|
|
|
|
|
|
program => $proc, |
108
|
|
|
|
|
|
|
defined $pid ? ( pid => $pid ) : (), |
109
|
|
|
|
|
|
|
message => $message, |
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=pod |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=encoding UTF-8 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 NAME |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Log::Saftpresse::Plugin::Syslog - syslog server input plugin for saftpresse |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 VERSION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
version 1.6 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This is free software, licensed under: |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |