License
MIT License
v1.0.6 · public · Published 2 months ago
A Sensu check plugin that monitors Cloudflare DNS records for unauthorized or unexpected changes. Automatically discovers all zones for your API tokens and alerts when any DNS record is added, removed, or modified.
On your Sensu backend:
sensuctl asset add SaladStik/cloudflare-dns-monitor
The plugin requires Python 3.7+ and the requests library on each agent that will run the check.
Debian/Ubuntu:
sudo apt-get update && sudo apt-get install -y python3 python3-requests
RHEL/CentOS/Rocky:
sudo yum install -y python3 python3-requests
# or
sudo dnf install -y python3 python3-requests
Alpine:
apk add --no-cache python3 py3-requests
On each Sensu agent that will run this check:
sudo mkdir -p /etc/sensu
sudo tee /etc/sensu/cloudflare.json << 'EOF'
{
"tokens": ["YOUR_CLOUDFLARE_API_TOKEN_HERE"]
}
EOF
sudo chmod 600 /etc/sensu/cloudflare.json
Replace YOUR_CLOUDFLARE_API_TOKEN_HERE with the token you copied.
On your Sensu backend, create the check definition:
cat << 'EOF' | sensuctl create -f -
type: CheckConfig
api_version: core/v2
metadata:
name: cloudflare-dns
namespace: default
spec:
command: check-cloudflare /etc/sensu/cloudflare.json
subscriptions:
- cloudflare
interval: 3600
timeout: 300
publish: true
runtime_assets:
- SaladStik/cloudflare-dns-monitor
EOF
# Check the asset is registered
sensuctl asset list
# After a few minutes, check events
sensuctl event list
# View detailed output
sensuctl event info <AGENT_NAME> cloudflare-dns
To monitor additional Cloudflare accounts or zones, add more tokens to your config:
{
"tokens": [
"token-for-main-account",
"token-for-client-account",
"token-for-another-account"
]
}
Each token automatically discovers all zones it has access to.
After making intentional DNS changes, reset the baseline so the plugin accepts the new state:
# Reset all zones
check-cloudflare /etc/sensu/cloudflare.json reset
# Reset specific zone only
check-cloudflare /etc/sensu/cloudflare.json reset ZONE_ID
type: CheckConfig
api_version: core/v2
metadata:
name: cloudflare-reset
namespace: default
spec:
command: check-cloudflare /etc/sensu/cloudflare.json reset
subscriptions:
- cloudflare
publish: false
timeout: 120
runtime_assets:
- SaladStik/cloudflare-dns-monitor
Then trigger manually when needed:
sensuctl check execute cloudflare-reset
| Field | Description | Default |
|---|---|---|
tokens |
Array of Cloudflare API tokens | Required |
state_dir |
Where to store baseline state files | ~/.cache/sensu-cloudflare |
max_workers |
Parallel zone checks | 10 |
{
"tokens": ["token-1", "token-2"],
"state_dir": "/var/cache/sensu/cloudflare",
"max_workers": 20
}
OK: 2 zones - 0 with changes, 0 errors
[example.com] No changes (15 records)
[example.org] No changes (8 records)
WARNING: 2 zones - 1 with changes, 0 errors
[example.com] 2 added, 1 removed, 1 modified
+ A staging.example.com → 1.2.3.4 (proxied)
+ CNAME api.example.com → backend.example.com
- A old.example.com → 10.0.0.1
~ A www.example.com → 10.0.0.2 (proxied)
content: 10.0.0.1 → 10.0.0.2
[example.org] No changes (8 records)
CRITICAL: [zone-id] API error 401
| Code | Status | Meaning |
|---|---|---|
| 0 | OK | No changes / Reset successful |
| 1 | WARNING | DNS changes detected |
| 2 | CRITICAL | API or connection error |
| 3 | UNKNOWN | Configuration error |
Make sure the asset is listed in runtime_assets in your check definition and Python is installed on the agent.
Your Cloudflare token is invalid or expired. Create a new token.
Your token doesn't have the required permissions. Ensure it has Zone:Read and DNS:Read.
check-cloudflare list YOUR_TOKEN
MIT - Or/bit Solutions
Please describe the reason for reporting this asset. Our moderators will be notified and will disable the asset if it is found to be inappropriate.
×