|Welcome to the Monastery|
Nagios plugin to detect changed IP address of WRT54G router.by blue_cowdawg (Prior)
|on Feb 24, 2006 at 22:58 UTC||Need Help??|
Like a lot of geeks out there I run my own mail server on my Linux box at home. To connect to the Internet I use a Linksys WRT54G router and I'm connected to the Greater Comcat High Speed Internet service via a cable modem.
So far so good.
Add to my levels of complexity the site that hosts my personal web page for me has graciously set me up with a CNAME and an MX record pointing to my home box for my personal domian of berghold.net
swell... except for one thing...
Every once in a great while and sometimes on rare occasion as frequently as thrice in a week the DHCP server at Comcast gets cranky on me and re-assigns my IP addres.
OH NO! What's a geek to do?
Before I had the Linksys router attached to the cable modem, I had the Linux box connected directly to the cable modem I had a Perl script that took the output of
and munged it so I knew what the IP address was right now and I checked that against what I expected it to be and if it changed I would get paged and I knew to send the ever patient with me staff at my hosting provider and have them update my CNAME and MX record.
But now with the Linksys in the way things are a bit dicier. I can't exactly run ifconfig eth?? much less a Perl script from cron on it. I could I suppose if I loaded OpenWRT on my router, but having not totally read up on the subject I'm not even sure about that. Probably not.
Also being the geek that I am I have Nagios running on one of my boxen that keeps track of the rest of my boxen. And it keeps track of my hosted web site and makes sure it is running and a few other odds and ends that I have it doing. I am even working on a sensor that will hook into Nagios and warn me if my freezer stops running. But I digress.
The WRT54G router comes with an administrative web interface that also includes a page showing the status of the router as well as the IP address that its outbound interface has been assigned by the ISP.
If there is a web page... I can load it into memory and parse it!
Now that I can find that, I can compare that to what I expect my IP address to be and from there trigger Nagios if need be.
What is Nagios Looking for?
The Nagios standard calls for the following exit codes from a well behaved plugin:
Without further ado, here is the code:
Integrating this with Nagios
For completeness sake, here is the command definition for the check. There is more than one way of implementing this check, but here is how I did it since I only have one router. If I had more (why would I at home?) then I'd leave the command definition more flexible.
No.. don't think for one second any of those IP addresses or that password are real. Put your own in there!
To further integrate this you have to associated it with a host definition as a service. Here is what my service definition looks like:
That's pretty much it... There are ways I could improve on this, but I'll leave that a) as a project for the reader's intellect and b) as a subject for a future follow up on this. Enjoy!