In Syslog-NG.conf
destination twitter { program("/usr/bin/perl /scripts/twitter.pl"); };
log { source(src); destination(twitter); };
Das Perl-Skript
#!/usr/bin/perl
#
# Florian Roth
# 2010
#
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;
use URI::Escape;
my $uname = "meineserver";
my $pass = "passwort123";
my $path = "http://twitter.com/statuses/update.json";
my $ua = new LWP::UserAgent;
my $headers = new HTTP::Headers;
$headers->authorization_basic($uname, $pass);
my $request = new HTTP::Request("POST", $path, $headers);
$request->content_type('application/x-www-form-urlencoded');
while (<>) {
s/[\r\l\n]//g;
s/^[\w]{3}[\ ]{1,2}[0-9]{1,2}[\ ][0-9]+:[0-9]+:[0-9]+[\ ]+//g;
my $twit = uri_escape($_);
$request->content('status='.$twit);
my $response = $ua->request($request);
# Debug
print $response->as_string;
}
Keine Kommentare:
Kommentar veröffentlichen