Using the Cloudflare API to change DNS records to maximize uptime
Find a file
2023-10-01 10:15:52 -05:00
.github Merge pull request #36 from slashtechno/dependabot/github_actions/docker/build-push-action-5.0.0 2023-10-01 10:15:52 -05:00
.deepsource.toml ci: Update .deepsource.toml 2023-03-26 20:43:36 +00:00
.dockerignore Check number of servers online by pinging 2022-11-05 13:54:45 -05:00
.gitignore Allow workflow_dispatch for Docker workflow 2022-12-01 19:15:37 -06:00
dependabot.yml Added API call to retrieve user email 2022-10-14 20:10:08 -05:00
Dockerfile Check number of servers online by pinging 2022-11-05 13:54:45 -05:00
go.mod Bump github.com/prometheus-community/pro-bing from 0.1.0 to 0.3.0 2023-08-01 14:48:06 +00:00
go.sum Bump github.com/prometheus-community/pro-bing from 0.1.0 to 0.3.0 2023-08-01 14:48:06 +00:00
LICENSE Inital commit 2022-10-14 20:04:57 -05:00
main.go Format code with gofumpt 2022-12-02 01:27:26 +00:00
README.md Removed "Badges" heading from README.md 2022-12-01 19:16:54 -06:00

API-Failover

Continuous Integration MIT License Create and publish a Docker image
Using the Cloudflare API to change DNS records to maximize uptime

Usage/Examples

Necessary data can be passed via environment vairables or CLI flags

api-failover --primary 0.0.0.0,0.0.0.1,0.0.0.2 --backup 0.0.0.3,0.0.0.4,0.0.0.5 --cloudflareapitoken token --cloudflarezoneid CLOUDFLAREZONEID --recordname RECORDNAME
# Is equivalent to 
CLOUDFLARE_API_TOKEN="token" CLOUDFLARE_ZONE_ID="zoneid" RECORD_NAME="RECORDNAME" PRIMARY_IPs="0.0.0.0,0.0.0.1,0.0.0.2" BACKUP_IPs="0.0.0.3,0.0.0.4,0.0.0.5" api-failover
# and
docker run -e CLOUDFLARE_API_TOKEN="token" -e CLOUDFLARE_ZONE_ID="zoneid" -e RECORD_NAME="RECORDNAME" -e PRIMARY_IPs="0.0.0.0,0.0.0.1,0.0.0.2" -e BACKUP_IPs="0.0.0.3,0.0.0.4,0.0.0.5" -it --rm ghcr.io/slashtechno/api-failover

For full flag usage, run:
api-failover --help

Pinging on Linux

In some cases, an error may be thrown when the program attempts to ping the specified hosts. The simplest way to alleviate this is to run the program as root or in Docker.
For more information, check the Linux section in the pro-bing README

Installation

Precompiled releases

Precompiled releases are build automatically by Github Actions and can be downloaded from the releases page
After downloading for the appropriate platform, the program can be run directly

Docker

Docker images can either be built locally, or pulled from the Github Container Registry
An advantage to running with Docker is that the software is isolated which can reduce the possiblity of errors. In addition, it can increase security. To pull and run, the following commands can be used:

docker pull ghcr.io/slashtechno/api-failover:latest 
# If the image isn't pulled manually, the following command will pull it automatically before running
docker run -e CLOUDFLARE_API_TOKEN="token" -e CLOUDFLARE_ZONE_ID="zoneid" -e RECORD_NAME="RECORDNAME" -e PRIMARY_IPs="0.0.0.0,0.0.0.1,0.0.0.2" -e BACKUP_IPs="0.0.0.3,0.0.0.4,0.0.0.5" -it --rm ghcr.io/slashtechno/api-failover

Compiling locally

In order to compile locally, Go must be installed

git clone https://github.com/slashtechno/api-failover/
cd api-failover
go install

Roadmap

  • Add support for CNAME records