Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
83 lines (54 sloc) 3.53 KB
Twilio + Nagios = Easy phone based monitoring and alerts
This package contains two pieces of software:
1) A script used as a notification command for nagios, which integrates nagios and twilio
2) A webserver which exposes nagios status files via Twilio XML
Put together, it is possible to wire up nagios such that any host or service check will send notifications via twilio, i.e. call you.
* A current version of twisted python
apt-get install python-twisted or
* Twilio python libraries
* A nagios installation
apt-get install nagios3 or
Nagios Setup
First, you must get nagios working. Included in this package is an example nagios config, which will be enough to get nagios monitoring ping and http on your local interface.
example config: examples/nagios.cfg
After installing nagios, set a cfg_file option to point to the examples/nagios.cfg. The nagios conf is generally located at:
After you add this line, your nagios config will look something like this:
... and so on ...
For the purpose of testing, you should only have one cfg_file option, and no cfg_dir options. Will will restrict the nagios install to just the example nagios.cfg included with this distribution.
The included nagios.cfg requires a few modifications to get fully working. The comments in example/nagios.cfg explain what needs to be changed.
Next, you will need to update scripts/ with your Twilio credentials and phone numbers. Should look something like this:
# Twilio REST API version
API_VERSION = '2008-08-01'
# needs to be registered with twillo
# this needs point to where you run your "twistd twilio_nagios" instance
MONITOR_URL = 'http://localhost:8080'
Assuming you got all the paths setup in the nagios.cfg, you should be able to start nagios now.
Twilio Responder
The second service is what service twilio hits to figure out what to say. This works by parsing the nagios status files, based on the params sent to it via twilio, and generating Twilio XML accordingly.
For testing purposes, you can start it with this command:
twistd -n twilio_nagios -o test/dat/objects.cache -s test/dat/status.dat
Then, navigate to:
And you should see Twilio XML:
<Say>the host production database server is up</Say>
This webserver will need to be ran on a server that is accessible by Twilio. I.e. you will not be able to test this running locally, unless your local machine has a public, internet facing, ipaddress.
How it works
When nagios determines it is the time to send a notification it sends data to the script. This will fire off a request to Twilio, telling it to hit a specific URL for the host that had the problem. Twilio will then hit a url on the twilio_nagios responder, which will parse the nagios config and objects file to look up the current state. It then returns that information in Twilio XML, and the sysadmin gets alerted by a robot voice. Success.