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