Created
January 14, 2012 00:23
-
-
Save ltudury/1609521 to your computer and use it in GitHub Desktop.
LogglySender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
#--------- | |
# LogglySender v0.1 | |
# Sends log lines from Apache to Loggly via an HTTP input | |
# http://wiki.loggly.com/ | |
#--------- | |
# IMPORTANT: Be sure to make this script executable! | |
# (e.g. "chmod +x logglysender.pl") | |
#--------- | |
use LWP::UserAgent; | |
while ($log = <STDIN>) { my ($host,$date,$url_with_method,$status,$size,$referrer,$agent) = $log =~ | |
m/^(\S+) - - \[(\S+ [\-|\+]\d{4})\] "(\S+ \S+ [^"]+)" (\d{3}) (\d+|-) "(.*?)" "([^"]+)"$/; | |
my ($method, $url, $http) = split /\s+/, $url_with_method; | |
$url =~ s/\?(.*)//; | |
$referrer=~ s/\?(.*)//; | |
my $uri = '<< put your Loggly input HTTP POST url here! >>'; | |
my $json = "{'host':'$host','date':'$date','url':'$url','status':'$status','size':'$size','referrer':'$referrer','agen | |
t':'$agent'}"; | |
my $req = HTTP::Request->new( 'POST', $uri ); | |
$req->header( 'Content-Type' => 'application/json' ); | |
$req->content( $json ); | |
my $lwp = LWP::UserAgent->new; | |
$lwp->request( $req ); | |
} | |
#--------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment