Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_public_ip.py

Rating
5 votes
Favoured:
2
Current Version
0.3
Last Release Date
2014-01-08
Compatible With
  • Nagios 3.x
Owner
License
GPL
Hits
67677
Files:
FileDescription
check_public_ip.pyv 0.3
ip.phpphp script to be added to remote webserver
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
This python plugin tests if your main internet or backup internet connection is active.

Tested with Nagios Core 3.3.1 and Python 2.7
Update Version 0.3:
This is a lot more robust now, it tries multiple sites, if any are overloaded it can return None, so try the next, if any are down, or don't exist it should catch this IOError and try the next site in the tuple.

There is a line in the script:
site_list = ('http://curlmyip.com','http://icanhazip.com')

You can add your own site to this list, preferably put it first in the above tuple, otherwise 35000 people all issuing GET requests every few minutes to the above sites may overload them.

Copy ip.php to a remote webserver, chown the file to www-data, and add your site to the above tuple:
site_list = ('http://mysite.com/ip.php','http://curlmyip.com','http://icanhazip.com')

Also in the main script replace 1.2.3.4 with your own main public IP, and replace 5.6.7.8 with your backup internet public IP.




Nagios instructions:
Copy check_public_ip.py to your nagios/libexec folder.

add this command to commands.cfg:

define command{
command_name check_failover_internet
command_line $USER1$/check_public_ip.py
}



add this service check to your firewall.cfg host, and change myfirewall to whatever you've named yours:

define service{
use generic-service ;
host_name myfirewall ;
service_description Active Internet Connection ;
check_command check_failover_internet
max_check_attempts 2

}

Reviews (3)
thanks for this

sometime I get a email with this
Notification Type: PROBLEM
State: UNKNOWN

Additional Info:

(Service Check Timed Out)

How can I fix that ?

thanks
Owner's reply

Hmm maybe both connections are down?
Else just run the script from command line and see what it returns.

Also don't rely on icanhazip and curlmyip, add you own ip.php to your own webserver and use that as the first element in the tuple.

Also sorry for late reply, the email ended up in my junk.

The script don't work when the first site is down : here curlmyip.com return connection refused.
We use a proxy here and the Answer is not "None" but a reply from proxy and the script don't test the second site. icanhazip.com
I'll post a new script soon on nagios exchange with regex check and put a topic on my blog with a new url to get ip address like http://www.monlinux.net/whatismyip.

Belgotux
Owner's reply

These sites come and go, you should add you own site as the first in the tuple anyway.

Sorry, we don't use a proxy here, can't help with that one.

byviettrungits, September 8, 2012
1 of 1 people found this review helpful
I received a warning email alert with status information is Null. :(
Owner's reply

When you run the script from command line what do you see? this is what i see:
root@nagios:/usr/local/nagios/libexec# ./check_public.py
Internode Fiber : OK - public ip: '99.121.18.13'