Twagios – Use Twitter for Nagios notifications

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 twitter.com 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
        email                           dummy@example.com
 }

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$" http://twitter.com/statuses/update.xml
    }

    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$" http://twitter.com/statuses/update.xml
    }

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.

Dropbox Tip: Automatic Transmission

I’ve been using Dropbox for quite some time now. Their 2GB of free online storage is increasingly being used in new and innovative ways.

One of the first things I set up was 1Password Sync using Dropbox. But wait, there is more! ;-)

I use BitTorrent downloads, mainly for large DVD downloads (the CentOS 5.5 DVD’s are only available through BitTorrent). My Mac Mini is always on, and it runs the Transmission BitTorrent client. Before Dropbox, I had to log on to the Transmission Web interface and upload the .torrent file.

With Dropbox, there is a more elegant solution: “Automatic Transmission”.

  1. Create a “Torrents” directory in your Dropbox
  2. Configure Transmission (Preferences > Transfers) to look for .torrent files in your Dropbox > Torrents directory

Transmission - Watch for TorrentsYou can now start a download from any computer by downloading the .torrent file into your Dropbox > Torrents directory.

If you have the “Trash original torrent files” option selected like me, you’ll get a notification from Dropbox immediately after Transmission sees the new torrent file.

This indicates that Transmission has seen your .torrent and has started the download.

BBQ!

BBQOok dit jaar hebben we weer een gezellige dag gehad met onze zomerse BBQ. En ook dit jaar ging er weer het een en ander mis ;-)

Vorig jaar hield de koelkast ermee op, dit jaar was het zelfs zo heet dat onze ijsblokjes-leverancier de handdoek in de ring had gegooid! Er was in heel Eindhoven geen ijsblokje meer te vinden. Kortom: paniek, want wie wil er nu warm bier drinken?

Gelukkig had Yfke haar Sligro-pasje bij zich, en was er daar nog ijs in overvloed. Met tegen de 40kg ijs kwamen we tegen half vijf (net op tijd om het vuur aan te steken) weer thuis.

Ondanks de voorspellingen bleef het weer ons goed gezind; er vielen een paar spatjes regen, maar we mogen zeker niet klagen!

Nagenieten van de BBQGelukkig brachten de ijsklontjes ons de nodige verkoeling. Yfke heeft zich weer opgeofferd en heeft de hele dag achter de hete barbecue gestaan – wat een luxe is dat toch, je eigen BBQ kok ;-)

Bedankt voor het gezelschap en de kadootjes – Annemarie en ik hebben een hele leuke dag gehad!

Wat zal er volgend jaar mis gaan? De diesel-generator, koelcel en reserve-lucifers hebben we al op ons lijstje staan ;-)

Configuring SELinux for WordPress

I recently installed WordPress 2.9.2 on my webservers.

Since these servers are obviously connected to the Internet, they run with SELinux enabled. This means that you cannot use the standard FTP functionality in the WordPress admin panel to manage your themes and plugins.

If you configure SELinux properly, you can enjoy the comforts of WordPress without compromising security.

Continue reading “Configuring SELinux for WordPress”