#!/usr/bin/perl use IO::Socket::INET; use Time::HiRes; use strict; $| = 1; # autoflush $SIG{CHLD} = "IGNORE"; sub Main { my ($line, $sock, $pid); $sock = IO::Socket::INET->new( Listen => 5, LocalAddr => '0.0.0.0', LocalPort => 6050, Proto => 'tcp', ReuseAddr => 1 ) or die "socket : $!"; while (my $csock = $sock->accept()) { $pid = fork(); if ($pid < 0) { die "Fork failed : $!"; } elsif ($pid > 0) { print STDERR "Forking child $pid\n"; close($csock); } else { open(REDIS, "|/usr/bin/redis-cli --pipe -h 172.18.0.1"); while ($line = <$csock>) { $line =~ s/(.*)}/$1,"tags":["syslogng"]}/; my $len = length($line); print REDIS "*3\r\n\$5\r\nrpush\r\n\$14\r\nlogstash:redis\r\n\$$len\r\n$line\r\n"; Time::HiRes::usleep(50); } close($csock); exit; } } } Main();