Search code examples
linuxperlsyslogsyslog-ng

syslog-ng perl pipe dropping events


I'm trying to pipe syslogs to a perl script via syslog-ng but not all of the syslog entries make it through - maybe 1 in 3 actually happen.

I've looked all over the place and can't find anyone remotely having the problem that I have. It seems so simple but I can't find the answer!

Here's my syslog-ng setup:

source s_1 { tcp(port(514)); };

destination d_zen { program("/tmp/zen.pl"); }; 

log { source(s_1); destination(d_zen); }; 

and here's my perl script:

#!/usr/bin/perl

use strict;
use warnings;

$|=1

my $filename = "/tmp/zen.log";
open(my $fh, '>>', $filename) or die "could not open file '$filename' $!";

while ( <STDIN> ) {

    print $fh <STDIN>."\n";

};

any thoughts?


Solution

  • I figured out the problem. My while loop wasn't built properly:

    #!/usr/bin/perl
    
    $|=1;
    
    use strict;
    use warnings;
    
    my $filename = "/tmp/zen.log";
    open(my $fh, '>', $filename) or die "could not open file '$filename' $!";
    
    my $my_string;
    
    while( <> ) {
        $my_string .= $_;
        print $fh "$my_string\n";
    };