Modify the Fail2ban Action:
[Definition] actionban = curl -s -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/firewall/access_rules/rules" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: your-global-api-key" -H "Content-Type: application/json" --data '{"mode":"block","configuration":{"target":"ip","value":"<ip>"},"notes":"Fail2ban block"}'
Fail2ban actionunban
[Definition] actionunban = bash -c ' RULE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/firewall/access_rules/rules" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: your-global-api-key" -H "Content-Type: application/json" | jq -r ".result[] | select(.configuration.value == "<ip>") | .id") && curl -s -X DELETE "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/firewall/access_rules/rules/$RULE_ID" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: your-global-api-key" -H "Content-Type: application/json"'
Get the Zone ID for Your Domain:
curl -X GET "https://api.cloudflare.com/client/v4/zones?name=example.com" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: your-global-api-key" -H "Content-Type: application/json"