Home Assistant: Cloudflare Threat Intelligence Integration
This is a custom integration for Home Assistant and is available via HACS by adding this repository as a custom source.
Welcome to Cloudflare Abuse Monitor!
This custom Home Assistant integration allows you to monitor and manage abusive IPs on your Cloudflare zone. It integrates:
- π Real-time traffic analysis
- π‘οΈ IP reputation lookups via AbuseIPDB
- π Automated updates to your Cloudflare firewall IP lists
- π§ Dynamic recheck logic β every 7 days, can be changed via configuration.
- π¨ Under Attack Mode control β based on request thresholds
- β±οΈ Smart scheduling β runs every custom number of minutes set via scan_interval_minutes
Keep your network protected and your automations smart.
If you found this project helpful, you can buy me a coffee!
- β Automatic Blocking: Block malicious IPs by updating your Cloudflare firewall list.
- π Recheck IPs: Optionally recheck IPs after X days (configurable).
- βοΈ Custom Modes: Choose between
MonitororActivemode for automatic blocking. - π§ Smart Skipping: Avoid rechecking IPs already handled.
- π¨ Cloudflare Under Attack Mode support
- π Traffic Summary: Track HTTP requests via Cloudflare GraphQL API.
- π« Skipped IPs: Track IPs skipped due to existing rules
- π Listed IPs: Track IPs currently in your block list
- β High-Risk IP Detection: IPs with high AbuseIPDB scores are flagged and handled.
- π‘οΈ Under Attack Mode: Indicates whether Cloudflare's Under Attack Mode is currently enabled (on) or disabled (off) for your zone.
Each sensor updates at a configurable interval (default: every minute) and integrates seamlessly with your Home Assistant dashboard.
- Monitor and toggle Cloudflare's "Under Attack Mode" directly from Home Assistant.
- Useful for automating emergency protections when malicious traffic is detected.
- Includes visual state feedback and custom styling for clear alert levels.
- last_request_count tracking in global file β Remembers the previous request count to compare with the current value and detect traffic spikes
- Sensors now expose:
next_update_in: Countdown (in seconds) until the next update.next_run_full_format: Human-readable time of next scheduled run.
- Update intervals can now be controlled from GUI or config file:
/config/cloudflare_abuse_monitor_configuration.json
Example:
{
"scan_interval_minutes": 1,
"last_request_count": 695
}
Listed IPs
High-Risk IPs
Skipped IPs
Traffic Summary
Under Attack Mode
- Sign up at AbuseIPDB
- Generate an API key from your dashboard
- Log in to Cloudflare Dashboard
- Add your domain (Zone)
- Go to Your Accounts > Configurations > Lists
- Create a list named:
block_ips. You can set any name.
---
Select your domain (zone) > In the left sidebar, go to Security > Security Rules
Rule 1: Block IPs in List > Note: If you used a different list name, remember to update it in the rule below.
(ip.src in $block_ips)
Action: Block
Rule 2: Skip by Country
(ip.geoip.country in {"AD" "AE" "AF" "AG" "AI" "AL" "AM" "AO" "AQ" "AR" "AS" "AT" "AU" "AW" "AX" "AZ" "BA" "BB" "BD" "BE" "BF" "BG" "BH" "BI" "BJ" "BL" "BM" "BN" "BO" "BQ" "BR" "BS" "BT" "BV" "BW" "BY" "BZ" "CA" "CC" "CD" "CF" "CG" "CH" "CI" "CK" "CL" "CM" "CN" "CO" "CR" "CU" "CV" "CW" "CX" "CY" "CZ" "DE" "DJ" "DK" "DM" "DO" "DZ" "EC" "EE" "EG" "EH" "ER" "ES" "ET" "FI" "FJ" "FM" "FO" "FR" "GA" "GB" "GD" "GE" "GF" "GG" "GH" "GI" "GL" "GM" "GN" "GP" "GQ" "GR" "GT" "GU" "GW" "GY" "HK" "HM" "HN" "HR" "HT" "HU" "ID" "IE" "IL" "IM" "IN" "IO" "IQ" "IR" "IS" "IT" "JE" "JM" "JO" "JP" "KE" "KG" "KH" "KI" "KM" "KN" "KP" "KR" "KW" "KY" "KZ" "LA" "LB" "LC" "LI" "LK" "LR" "LS" "LT" "LU" "LV" "LY" "MA" "MC" "MD" "ME" "MF" "MG" "MH" "MK" "ML" "MM" "MN" "MO" "MP" "MQ" "MR" "MS" "MT" "MU" "MV" "MW" "MX" "MY" "MZ" "NA" "NC" "NE" "NF" "NG" "NI" "NL" "NO" "NP" "NR" "NU" "NZ" "OM" "PA" "PE" "PF" "PG" "PH" "PK" "PL" "PM" "PN" "PR" "PS" "PT" "PW" "PY" "QA" "RE" "RO" "RS" "RU" "RW" "SA" "SB" "SC" "SD" "SE" "SG" "SH" "SI" "SJ" "SK" "SL" "SM" "SN" "SO" "SR" "SS" "ST" "SV" "SX" "SY" "SZ" "TC" "TD" "TF" "TG" "TH" "TJ" "TK" "TL" "TM" "TN" "TO" "TR" "TT" "TV" "TZ" "UA" "UG" "UM" "US" "UY" "UZ" "VA" "VC" "VE" "VG" "VI" "VN" "VU" "WF" "WS" "YE" "YT" "ZA" "ZM" "ZW"})
Action: Skip
- Go to **HACS **
- Click the three dots menu > Custom repositories
- Add this repository URL: https://github.com/niruse/cloudflare_abuse_monitor/tree/main
- Download the
cloudflare_abuse_monitorfolder - Place inside
/config/custom_components/ - Restart Home Assistant
-
Go to Settings > Devices & Services
-
Click + Add Integration, search for
Cloudflare Abuse Monitor -
Fill in:
- Cloudflare Email
- Global API Key - Cloudflare Global Token
- Log in to the Cloudflare dashboard and go to User Profile in the right corner > API Tokens left side.
- In the API Keys section, scroll down, click View button of Global API Key.
- AbuseIPDB API Key
- AbuseIPDB score threshold under abuse_confidence_score
- Recheck Days β recheck_days (how many days to wait before rechecking the stored IPs)
- Zone ID
- List ID
- Mode is automatically set to "Monitor" by default, but you can change it after completing the configuration
Page for zone id
Page for list id
You can now dynamically adjust key settings directly from the Home Assistant UI.
| Option | Description |
|---|---|
abuse_confidence_score |
Minimum AbuseIPDB score to treat an IP as "high risk". Default: 100 |
mode |
Monitor: Logs only, or Active: Automatically blocks high-risk IPs. |
recheck_days |
Days to wait before rechecking previously flagged IPs. |
under_attack_mode |
Enable or disable Cloudflare Under Attack Mode based on request threshold. |
under_attack_request_threshold |
The number of requests per minute is evaluated based on scan_interval_minutes to determine whether to trigger Under Attack Mode. |
scan_interval_minutes |
How often (in minutes) each sensor should run. |
These options can be changed anytime without restarting Home Assistant. These options are accessible under Configure in the integration settings:
If under_attack_mode is enabled and under_attack_request_threshold = 3000:
- Under Attack Mode is triggered if the number of requests during the scan_interval_minutes period exceeds the defined threshold.
This example Lovelace dashboard uses button-card to show your sensors.
βΉοΈ Make sure to update the entity names to match your actual sensor IDs:
sensor.cloudflare_traffic_summaryβ Replace with your traffic summary sensorsensor.cloudflare_skipped_ipsβ Replace with your skipped IPs sensorsensor.cloudflare_listed_ipsβ Replace with your listed IPs sensorsensor.cloudflare_high_risk_ipsβ Replace with your high-risk IPs sensorsensor.under_attack_modeβ Replace with your under_attack_mode sensor
type: vertical-stack
title: Cloudflare Abuse Monitor
cards:
- type: horizontal-stack
cards:
- type: custom:button-card
name: Traffic Summary
icon: mdi:chart-box-outline
show_state: true
show_icon: true
show_name: true
entity: sensor.cloudflare_traffic_summary
tap_action:
action: more-info
state_display: >
[[[ return "Total requests to Cloudflare zone"; ]]]
- type: custom:button-card
name: Skipped IPs
icon: mdi:minus-circle-outline
show_state: true
entity: sensor.cloudflare_skipped_ips
tap_action:
action: more-info
- type: horizontal-stack
cards:
- type: custom:button-card
name: Listed IPs
icon: mdi:format-list-bulleted
show_state: true
entity: sensor.cloudflare_listed_ips
tap_action:
action: more-info
- type: custom:button-card
name: High-Risk IPs
icon: mdi:alert-outline
show_state: true
entity: sensor.cloudflare_high_risk_ips
state_display: >
[[[
return `${states['sensor.cloudflare_high_risk_ips'].attributes.ips_to_check?.length || 0} / ${states['sensor.cloudflare_high_risk_ips'].attributes.ips_to_block?.length || 0}`;
]]]
tap_action:
action: more-info
- type: custom:button-card
name: Under Attack Mode
icon: mdi:shield-alert
show_state: true
show_icon: true
show_name: true
entity: sensor.under_attack_mode
tap_action:
action: more-info
state_display: |
[[[
if (entity.state === "on") return "ACTIVE";
if (entity.state === "off") return "OFF";
if (entity.state === "unknown") return "Unknown";
if (entity.state === "error") return "Error";
return entity.state;
]]]
styles:
card:
- background-color: |
[[[
if (entity.state === "on") return "rgba(255, 0, 0, 0.2)";
if (entity.state === "off") return "rgba(0, 128, 0, 0.2)";
return "rgba(128, 128, 128, 0.2)";
]]]
- border: 1px solid rgba(255, 255, 255, 0.1)
- border-radius: 12px
- padding: 12px
name:
- font-weight: bold
state:
- font-size: 14px
- font-weight: 500- Checked IPs are stored in
cloudflare_checked_ips.json
We welcome:
- π§ Bug fixes
- π Features
- π§ Suggestions
Submit a PR or open an issue
Protect your Cloudflare zone with real-time threat monitoring β directly in Home Assistant!

