A PHP web hook to handle down notifications from uptimerobot. If a DOWN notification is received, it'll change the A record of a domain on cloudflare to a backup IP set by you.
License: MIT
Dependencies: Web Server, PHP, php-curl lib
Setup:
- I suggest you rename the php file to something obscure.
- Add / change the global vars section. It consists of credentials and other information that needs to be modified to your needs.
- Upload this script to the desired server, make sure the script is accessible via the internet.
- On Cloudflare:
if there's any client filtering in your API token settings, make sure you add your server's IP that's running this script to the whitelist. - On uptimeRobot:
Create a new alert contact and select web hook. For url, put in the url to the php script and add "?key=YourKeySetInThePHPScript&".
If my $key was set to HelloWorld and I renamed my script to monitorUP.php which is accessible via 127.0.0.1, then for the url I would put
http://127.0.0.1/monitorUP.php?key=HelloWorld& Make sure you have the & at the end. - Add this alert type to your websites. It's recommended that you have more than the PHP hook as an alert type (such as email notification), so you can switch it back to the primary server once it's up. This should be done manually (login to cloudflare and change the IP) because there might be inconsistencies between the primary and the backup server, which requires manual intervention.
With this setup, a website shouldn't have a downtime of more than ~6 minutes, assuming your DNS provider does not cache queries.
You can reach me on twitter .
If you're looking for StatusCake + Cloudflare, you can find it here .