Several customer sites use Nagios for monitoring and alerting. Nagios can send out notifications about problems in a variety of ways, for example using email, pager, SMS and even Twitter. I based my configuration on this post.

Configuring Twitter notifications takes a couple of steps:

  1. Set up a new “Twitter Bot” account to be used for Nagios notifications.
  2. Create a new Nagios contact to send out notifications for your hosts and services.
  3. Define the appropriate notify-by-twitter and host-notify-by-twitter commands.

Setting up the Twitter Bot account

  • Go to and create a new account for your Twitter Bot.
  • Go to Settings, and mark the updates as Private. Otherwise, everyone can see your Nagios status updates.
  • Log on to Twitter with your own account, and “Follow” your new Twitter Bot account.
  • Log on to Twitter with your Twitter Bot account, and accept your own account as follower.

Nagios contact

We need to tell Nagios to send updates for host- and service-problems to your Twitter Bot. Add a Nagios contact for this purpose (in my installation, in /etc/nagios/conf.d/general/contacts.cfg):

    define contact{
        contact_name                    twitter
        alias                           Twitter Bot
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-by-twitter
        host_notification_commands      host-notify-by-twitter

The dummy email address was added to make Nagios happy; it complains if you do not specify an email or pager address.

This new Nagios contact must be added to your standard contact group that is notified in case of trouble:

    define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 ed,twitter

Notification commands

The final step in configuring Nagios is defining the actual notification commands we used for the “twitter” contact. Nagios will happily send out notifications using any method that we define. In /etc/nagios/commands.cfg, add the following commands (command_line should be one long line):

    ### Twitter ###
    define command{
        command_name    host-notify-by-twitter
        command_line    /usr/bin/curl --connect-timeout 30 --max-time 60 -u TwitterBotName:TwitterBotPassword -d status="@YourTwitterName $HOSTALIAS$ is $HOSTSTATE$. $HOSTOUTPUT$. Time: $SHORTDATETIME$"

    define command{
        command_name    notify-by-twitter
        command_line    /usr/bin/curl --connect-timeout 30 --max-time 60 -u TwitterBotName:TwitterBotPassword -d status="@YourTwitterName $SERVICEDESC$ @ $HOSTNAME$ is $SERVICESTATE$. $SERVICEOUTPUT$. Time: $SHORTDATETIME$"

Replace “TwitterBotName” and “TwitterBotPassword” with the username and password for your new account. Replace “YourTwitterName” with your own Twitter username. This way, notifications are sent out as so-called “Mentions”: these are updates that contain your Twitter @username.

Bonus: Push notifications on iPhone

If you have an iPhone, install the Boxcar app and configure it with the Twitter service for your @username. You will now receive push-notifications on your phone for all Nagios status updates. Neat, huh?

Update 2011.08

  • Boxcar is no longer necessary as your Twitter client can send push notifications too.
  • The above script no longer works because Twitter no longer supports basic authentication.
  • Wrote an update to this blog post, Twagios 2.0, replacing curl with a new client that supports OAuth.