Value driven web development

Nagios 4: notify by twitter

November 5th, 2007

Install Net::Twitter (perl version)

download from search.cpan.org

http://search.cpan.org/~cthom/Net-Twitter/

1
2
3
4
5
6
tar zxvf Net-Twitter-1.06.tar.gz
cd Net-Twitter-1.06
perl Makefile.PL
make
make test
sudo make install

Install other perl package if required(HTML-Tagset, libwww-perl, JSON-Any)

download them from http://search.cpan.org/

The script for twitter notify( change the user_name and password for twitter )

vi /usr/local/nagios/libexec/twitter.pl

1
2
3
4
5
6
7
8
9
#!/usr/bin/perl -w

use strict;
use Net::Twitter;
my $msg = shift;
my $twit = new Net::Twitter(username => "yourname",password => "yourpass");
if (defined($msg) && $msg !~ /^\s*$/) {
  $twit->update($msg);
}

sudo chown nagios:nagios twitter.pl

sudo chmod +x twitter.pl

send the test message to twitter

/usr/local/nagios/libexec/twitter.pl ‘hello world’

Add new command for notify in nagios

sudo vi /usr/local/nagios/etc/objects/commands.cfg
1
2
3
4
define command {
        command_name notify-by-twitter
        command_line /usr/local/nagios/libexec/twitter.pl "$NOTIFICATIONTYPE$ -$HOSTNAME$-$SERVICEDESC$ - $SERVICESTATE$ - $SERVICEOUTPUT$"
}

Then in the contacts.cfg, use this:

service_notification_commands notify-by-twitter

Reference: Twitter as Nagios notification gateway

Sorry, comments are closed for this article.