
Twitter to monitor server from anywhere
The following perl script can be run on a server to monitor error logs via rss feeds on twitter.
#!/usr/bin/perl
# tail.pl
# This script is used to run a tail on a file and sends command to twitter cli which uploads to rss feed.
# This script was created by Terry Topp and can freely be used or modified by anyone.
# the follow line needs to be in /usr/local/bin filename twitter
# curl --basic --user "<username>:<password>" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json"
# libfile-tail-perl module needed to run script
# curl needed to run the CLI command in the twitter file
############################################################################
use warnings;
use strict;
use File::Tail;
my $line;
my $name = "/var/log/apache2/error.log";
my $file=File::Tail->new(name=>$name, maxinterval=>10, adjustafter=>7);
while (defined($line=$file->read)) {
# if ($line){ # uncomment out for custom message
# my $error = "Put your custom message here"; # uncomment out for custom message
system('twitter', "$line"); # replace $line with $error for custom message
# } # uncomment out for custom message
}
# EOF
The file can be modified to either give a custom message or the real error. You can modify the file to fliter using m/// regex to only post wanted error messages. I have included in the header the command used by the script, which is saved in the location mention.
The twitter CLI information was found here:
http://binnyva.blogspot.com/2007/03/using-twitter-part-1-command-line.ht...
or
sudo apt-get install curl
There is also a perl module required, which you have Perl installed all ready and use apt-get the following command :
sudo apt-get install libfile-tail-perl
Then you will need to have a twitter account for each server and be sure to check the box to not make the post public. Once to script is started by typing : perl tail.pl : you can scribe to the feeds to follow your servers and about every 30 seconds the log files are checked. Should you want to download the Perl module from the CPAN by going to:
http://search.cpan.org/~mgrabnar/File-Tail-0.99.3/Tail.pm.
In the download there is a script to monitor several files at once.
Enjoy,
Iamvarr

Nice Idea but...
isn't putting your logs on twitter a bit of a security no no.
It seems a little like free feed back to anyone poking around on your server.
I've heard the guys on pauldotcom.com security talk alot about how gathering infomation is so important when doing pen testing. Version numbers etc.
Tell me I'm wrong but it sounds like a risk.
Spot101.
if used wisly...
This is easily a security risk if not used right. But the script is just monitoring the error log and response in twitter is up to you. The account I use only has me following. I watch who is following and at this time no one has. I have rejected a few bots. But I keep on top of the accounts. Even if you are able to find and friend the message is not the error as well as not being public. Unless I feel like being evil to anyone using twitter and posting fake errors like they are coming from twitter.
My errors that go to my phone are like "Houston box one has a problem". Boy that is helpful to a hacker. Another one is "Green for go" only I know the server who has that error or is it a all clear message? Only I know the meaning. The servers can keep me updated as long as I use it responsibly.
Until anyone can pin test my brain its safe. The only problem is the fact that twitter has been going down often.
Spot101, its not that your wrong or right its all in how you use it.
Also as of this post anyone out there don’t try to track the two messages above because they have been changed. Responsible and paranoid run hand and hand but knowing is half the battle. :)
Agreed
As with most things security we humans are the weakest link.
"The account I use only has me following. I watch who is following and at this time no one has."
Can't I also follow you by just watching your posts on the web page? http://twitter.com/my-server-errors