Nagios – Twitter alerts

This entry will cover how to send nagios alerts to twitter, in the examples to follow using curl.

Firstly edit commands.cfg

And add the two following line:

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$"

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$"

Now define a contact for this twitter service into: 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

Add this contact into your existing contact groups like this (in contacts.cfg):

define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,sms_alert,twitter

Then run a nagios prefly check to ensure you have no syntax errors, and restart nagios.