Nagios - Send Alerts to Twitter
Pre-req reading:
Nagios customization: Alerting via SMS, or anything you like!
Making the bird tweet using python or Update twitter in a single line
This entry will cover how to send nagios alerts to twitter, in the examples to follow curl will be used however you can choose to use the python example (link above) in place of this.
Firstly edit /usr/local/nagios/etc/objects/commands.cfg
And add the two following commands.
UPDATE 24/03/2011 Twitter no longer supports basic auth, use my oAuth updater here
define command {
command_name notify-by-twitter
command_line /usr/bin/curl --basic --user "twitteruser:twitterpassword" --data-ascii "status=[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" https://twitter.com/statuses/update.json
}
define command {
command_name host-notify-by-twitter
command_line /usr/bin/curl --basic --user "twitteruser:twitterpassword" --data-ascii "status=[Nagios] $HOSTSTATE$ alert for $HOSTNAME$" https://twitter.com/statuses/update.json
}
Now define a contact for this twitter service
/usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name twitter
service_notification_commands notify-by-twitter
host_notification_commands host-notify-by-twitter
service_notification_period 24x7
host_notification_period 24x7
service_notification_options a
host_notification_options a
}
Choose your own notification options, for my feed I only choose alerts, I also have this send updated to a ‘private feed’ which I then follow.
Add this contact into your existing contact groups, i.e.
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,sms_alert,twitter
}
Then run a nagios-verify to ensure you have no syntax errors, and restart nagios.
Trigger an alert by manually switching a monitored service off or entering a manual result to test.