Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vmadman
Created April 27, 2013 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmadman/5472159 to your computer and use it in GitHub Desktop.
Save vmadman/5472159 to your computer and use it in GitHub Desktop.
A PERL UDP client. This client serves (in my usage) as a pipe target for apache logs. After reception, logs are forwarded to logstash. I found this at: http://untergeek.com/2012/10/11/getting-apache-to-output-json-for-logstash/
#!/usr/bin/perl
#udpclient.pl
use IO::Socket::INET;
my $host = $ARGV[0];
my $port = $ARGV[1];
# flush after every write
$| = 1;
my ($socket,$logdata);
# We call IO::Socket::INET->new() to create the UDP Socket
# and bind with the PeerAddr.
$socket = new IO::Socket::INET (
PeerAddr => "$host:$port",
Proto => 'udp'
) or die "ERROR in Socket Creation : $!\n";
while ($logdata = <STDIN>) {
$socket->send($logdata);
}
$socket->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment