errr-online.com

Tag: python

py-nag A notification script for nagios to nag you in Twitter

by errr on Jan.23, 2010, under Linux

So I have been trying to think of cool things I could do with Twitter. I happen to be a HUGE fan of nagios for monitoring my systems. From time to time some of the systems I monitor go down, and sometimes they are my email servers, so getting a message from nagios about this is kind of out of the question unless I setup alternative email accounts that I would then have to add to the already large number accounts I have… So why not just “tweet” the notice. This way I have an easy way to get the status. This is what prompted me to write py-nag. Its a pretty simple script that you can toss on your system and then define a new command in nagios and easy as pie now you get notices in twitter. Its all python and the only dep needed should be python-twitter And a simple apt-get install python-twitter took care of that for me.

To set this up you can simply place the nagger.py script somewhere on your system. I put it in /usr/local/bin and named it py-nag

#wget -O /usr/local/bin/py-nag https://code.google.com/p/py-nag/source/browse/nagger.py

Note the # this indicates the command needs to be run as root or you can use sudo. Next set the file to be executable

#chmod +x /usr/local/bin/py-nag

Next you need to configure nagios. On my Debian box I will edit the following file like so:

vim /etc/nagios3/commands.cfg

Next we need to add the command definition

define command {
command_name notify-userName-by-tweet
command_line /usr/local/bin/py-nag –twitusr=MYTWITUSER –twitpass=’MYTWITPASS’ –msg=’T: $NOTIFICATIONTYPE$ Hst: $HOSTALIAS$ dt: $LONGDATETIME$’ –dmonly –user=WhoToTweet
}

Next you need to set your contact to use this command like so:

service_notification_commands notify-userName-by-tweet

This is done in your contact confg. service_notification_commands will accept a comma seperated list so this can be one of many commands. Next you need to reload the nagios config. Now you are all ready to get Direct messages from your nagios nagger. If you prefer to not get the notice as a DM you can use the optional –tweetit param instead of the –dmonly If you use the –tweetit param you do not need the –user flag. I sure hope some people find this useful.

  • Share/Bookmark
1 Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...