Vliegende Pinguins Over vliegen, de pinguins en …

30Mar/101

Twitter….

Twitter, wie heeft het niet ? Nou ik had het niet.... Maar omdat ik graag speel met scriptjes en zo heb ik mijn fail2ban en nagios aan twitter geknoopt.

http://twitter.com/fail2ban en http://twitter.com/tweetnagios

Eigenlijk is het helemaal niet moeilijk. Op http://gabrielcain.com/projects/twitter/ een scriptje gevonden (perl), waar wel een kleine aanpassing in gedaan moest worden (de homedir van de maker stond er hard in).
Er stond in twitter.pl (die ik in /usr/local/bin heb geplaatst):

use strict;
use lib '/home/gabriel/lib/';
use Data::Dumper;
use Getopt::Std;
use Twitter;

en dit moest worden:

use strict;
use lib '/usr/local/bin/';
use Data::Dumper;
use Getopt::Std;
use Twitter;

Dus de files 'twitter.pl' en Twitter.pm' gekopieerd naar /usr/local/bin. Daarna de volgende aanpassingen in fail2ban :

In /etc/fail2ban/action.d/ een nieuwe action gedefinieerd met de file twitter.conf

# Fail2Ban configuration file
#
# Author: Michel van Deventer
#
# $Revision: 100 $
#
[Definition]
# Option:  actionstart
# Notes.:  command executed once at the start of Fail2Ban.
# Values:  CMD
#
actionstart = /usr/local/bin/twitter.pl -f /root/.twitterrc "[Fail2Ban] <name> : started"
# Option:  actionstop
# Notes.:  command executed once at the end of Fail2Ban
# Values:  CMD
#
actionstop = /usr/local/bin/twitter.pl -f /root/.twitterrc "[Fail2Ban] <name> : stopped"
# Option:  actioncheck
# Notes.:  command executed once before each actionban command
# Values:  CMD
#
actioncheck =
# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:      IP address
#            number of failures
#            unix timestamp of the ban time
# Values:  CMD
#
actionban = /usr/local/bin/twitter.pl -f /root/.twitterrc "[Fail2Ban] : <ip> banned , use /usr/bin/whois <ip> for more info"
# Option:  actionunban
# Notes.:  command executed when unbanning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:      IP address
#            number of failures
#            unix timestamp of the ban time
# Values:  CMD
#
actionunban =
[Init]
# Default name of the chain
#
name = default

Bovenstaande config is een voorbeeld 😉

In de file /etc/fail2ban/jail.conf heb ik een regeltje toegevoegd om de meldingen ook naar twitter te laten sturen :

twitter[name=SSH]

onder de 'action'  regel bij [ssh-iptables]

Daarna fail2ban restarten en klaar...

Wil je weten hoe je Nagios laat twitteren ?? Vraag het maar  🙂

Edit : jammer genoeg heeft Twitter de authenticatie methode veranderd, dus mijn scripts werken niet meer en ik heb nog geen gelegenheid gehad om nieuwe te vinden/maken.

Filed under: Algemeen 1 Comment
   

Vliegende Pinguins is Stephen Fry proof thanks to caching by WP Super Cache