Subject: | [patch] compatibility with syslog-ng(?) |
We have a syslog setup like so:
[ device 1 ] -> [ main syslog server ] -> [ my test box ]
Where the main syslog server is running syslog-ng, and accepts messages from a set of devices, rebroadcasting (some of) them to my test box.
POE::Component::Server::Syslog fails to understand these messages - a simple test script:
#!perl
use POE;
use POE::Component::Server::Syslog;
use Data::Dumper;
POE::Component::Server::Syslog->spawn(Type=>'udp', InputState => \&in)
or die "ARGH!!!";
POE::Kernel->run;
sub in {
print Dumper $_[ARG0];
}
Only prints out the first message.
This appears to be because the embedded message contains a "\n", which confuses POE::Filter::Syslog's SYSLOG_REGEX.
The solution I have tried - and appears to work - is attached.
By handing the /s modifier to the regexes, we treat "\n" as Just Another Character. This has the effect of making ^ and $ mean "start of string" and "end of string" rather than start-of-line. This means that the text-gobbling ".*" eats the whole message, including the \n.
This may have a less than satisfactory result for TCP streams, which I've not tested.
Index: POE-Component-Server-Syslog/lib/POE/Filter/Syslog.pm
===================================================================
RCS file: /cvsroot/upstream/POE-Component-Server-Syslog/lib/POE/Filter/Syslog.pm,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Syslog.pm
--- POE-Component-Server-Syslog/lib/POE/Filter/Syslog.pm 13 Mar 2005 21:08:42 -0000 1.1.1.1
+++ POE-Component-Server-Syslog/lib/POE/Filter/Syslog.pm 14 Nov 2005 17:40:12 -0000
@@ -42,7 +42,7 @@
my @found;
if($stream and length $stream) {
- while ( $stream =~ s/$SYSLOG_REGEXP//x ) {
+ while ( $stream =~ s/$SYSLOG_REGEXP//sx ) {
my $time = $2 && parsedate("$2 $3 $4:$5:$6");
$time ||= time();
@@ -64,7 +64,7 @@
my $self = shift;
my $found = 0;
if($self->{buffer} and length $self->{buffer}) {
- if ( $self->{buffer} =~ s/$SYSLOG_REGEXP//x ) {
+ if ( $self->{buffer} =~ s/$SYSLOG_REGEXP//xs ) {
my $time = $2 && parsedate("$2 $3 $4:$5:$6");
my $msg = {
time => $time,