New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Script to switch to your backup IP when your main server goes down via CloudFlare API
I made a script awhile ago that monitors your domain and switches it to a backup IP if your main server is down / unreachable via the cloudflare API.
I decided to open source this since someone asked about getting the DNSID awhile back. Hopefully someone finds this useful
https://raw.github.com/blackdotsh/cloudflare-backup/master/cfbkup.sh
Comments
Thank you @black. By the way, another method to achieve the same goal via "monit" can be found here:
http://blog.booru.org/?p=12
Credit goes to @INIZ as he mentioned it in an older thread.
If the link above does not work for you, try google's cache:
http://webcache.googleusercontent.com/search?q=cache:GHKoHAU_-FoJ:blog.booru.org/?p=12+&cd=5&hl=en&ct=clnk&gl=us
Thanks for the post. A quick question though, have you tried this yourself and does it work?
A snippet of his code
action "DIUP" doesn't exist in the cloudflare client API (https://www.cloudflare.com/docs/client-api.html)
To edit a DNS entry, you have to have the DNSID, which is obtained by doing "rec_load_all" I don't see the script doing that.
On a side note note, I made functions so the code should be simple enough to port
Yes I did have success setting it up according to the blog post. I too do not understand why that DIUP method cannot be found in CloudFlare API documents. However I searched on the web and it seems to exist at an earlier time.
Ah sweet! If I knew about this I wouldn't have spent time seeing how I can parse xml results to get the DNSID lol :P
I also searched on archive.org and the DIUP method was last seen in the official API documents in August 2012.
https://web.archive.org/web/20120822010012/http://www.cloudflare.com/docs/client-api.html
The number is 3.3.10.
Interesting. I assume they removed it for a reason so I guess I'll just stick to the DNSID way of doing things. Good to know though
I save a snippet on how to parse json from the commandline
$ wget http://stedolan.github.io/jq/download/linux32/jq (32-bit system)
$ wget http://stedolan.github.io/jq/download/linux64/jq (64-bit system)
$ chmod +x ./jq
$ sudo cp jq /usr/bin
$ cat json.txt | jq ‘.name’