Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We've been using nagios for some time and have recently decided to change how we receive alerts. To this end, we've installed twurl ( ) and are using it to send alerts. Unfortunately this logs alerts as having been sent, but none get to the monitor's twitter account. twurl uses a pretty standard CLI which looks like this (nagios macros left in tact):

/usr/local/bin/twurl -d "status=d @$CONTACTEMAIL$ $NOTIFICATIONTYPE$: $TIME$ : $HOSTALIAS$ / $SERVICEDESC$ is $SERVICESTATE$ ($SERVICEOUTPUT$)" /1/statuses/update.xml

Here's the notification command:

define command {
    command_name    notify-service-by-twurl
    command_line    PATH="/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/nagios/bin"; HOME="/home/nagios"; /usr/local/bin/twurl -d "status=d @$CONTACTEMAIL$ $NOTIFICATIONTYPE$: $TIME$ : $HOSTALIAS$ / $SERVICEDESC$ is $SERVICESTATE$ ($SERVICEOUTPUT$)" /1/statuses/update.xml &>/tmp/lastcheck
#   command_line    /bin/echo '/usr/local/bin/twurl -d "status=d @$CONTACTEMAIL$ $NOTIFICATIONTYPE$: $TIME$ : $HOSTALIAS$ / $SERVICEDESC$ is $SERVICESTATE$ ($SERVICEOUTPUT$)" /1/statuses/update.xml' > /tmp/foo

Syntax works fine etc, no issues there. 1st line fires off the 2nd command_line line is to output the contents of the macros nagios uses, and returns what would be expected in all cases.

twurl pitfalls we've definitely avoided:

  • we've authed to twitter for nagios's user (su'd in and checked, works fine when done manually).
  • the credentials of the app are correct (again, works fine when using twurl manually)
  • the settings of the twitter app ( on ) are correct (set to read/write direct messages etc)

I can provide any specific pieces of information anyone might need for extra context but for now that's about it. Edit: I'm starting to suspect this is due to a lack of a .profile when nagios itself calls twurl, but I'm not 100% sure and still can't make it "go".

Update: ascertained that the script is not using the .twurlrc from nagios's home directory when nagios executes it. This is a problem I still can't resolve, any other help would be much appreciated.

share|improve this question
up vote 4 down vote accepted

Nagios runs external commands without any ENV. To simulate this, you can try running your manual test via "env -i ". You seem to already know this, because you are explicitly setting PATH and HOME. You should try to avoid this, and just use full paths in any scripts/commands/etc.

You also might need to escape some of the non-alphanumeric characters in your command_line, because the shell may eat them. To test this, you can enable debugging output in nagios.cfg (see 'debug_level' ) or change the command to "echo ... > /tmp/whatisnagiosrunning.txt" or similar.

share|improve this answer
Seems that twurl is asking us to authorise even though .twurlrc contains the right credentials. From commandline, this works fine. Is there a way to make the script include/work from the .twurlrc in nagios's home directory? If so, then it seems there could be an easy fix to this... – jhackett Jan 16 '12 at 13:48
PS, I'd upvote your answer but apparently you need 15 reputation for that, which I don't yet have. Sorry! :( – jhackett Jan 16 '12 at 13:49
I've never used twurl, but maybe there's a way to explicitly tell it which conf file (.twurlrc) to use? – Keith Jan 25 '12 at 17:44
I've looked into this since my last post and it doesn't look like there is. I'm mulling over seeing if I could write such a feature into it. Seems like it might be the easiest option at this point. – jhackett Jan 31 '12 at 10:06

Found a workaround that fixes things (and may also contribute to twurl so this doesn't break other things!).

In rcfile.rb (mine is in /usr/local/lib/ruby/gems/1.8/gems/twurl-0.6.5/lib/twurl/rcfile.rb) make the following change. Below is the original:

    module Twurl
      class RCFile
        FILE = '.tqurlrc'
        @directory ||= ENV['HOME']
        class << self
          attr_accessor :directory

And beneath is the modification:

    module Twurl
      class RCFile
        FILE = '.twurlrc'
        @directory ||= '/home/nagios/'
        class << self
          attr_accessor :directory

This should probably accept user input - something I may contribute to twurl myself at some point in the near future.

Thanks to all who helped :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.