fix(crowdsec-dashboard): Move to Security menu and fix stats display
- Move CrowdSec from Services to Security & Access menu
- Fix get_decisions() to return {"decisions":[]} not {"alerts":[]}
- Fix active_bans to use local_decisions count instead of parsing
unreliable metrics output
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7236449223
commit
fce6307c7e
@ -60,9 +60,9 @@ get_decisions() {
|
||||
local output
|
||||
output=$(run_cscli decisions list -o json)
|
||||
if [ -z "$output" ] || [ "$output" = "null" ]; then
|
||||
echo '{"alerts":[]}'
|
||||
echo '{"decisions":[]}'
|
||||
else
|
||||
echo "{\"alerts\":$output}"
|
||||
echo "{\"decisions\":$output}"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -2233,12 +2233,15 @@ get_overview() {
|
||||
json_add_int "alerts_24h" "${alerts_count:-0}"
|
||||
json_add_int "bouncer_count" "${bouncers_count:-0}"
|
||||
|
||||
# Active bans = local decisions (IPs being actively blocked by local scenarios)
|
||||
# Use local_decisions count which is already calculated above
|
||||
json_add_int "active_bans" "${local_decisions:-0}"
|
||||
|
||||
# Bouncer effectiveness stats (packets/bytes dropped vs processed)
|
||||
local dropped_packets=0
|
||||
local dropped_bytes=0
|
||||
local processed_packets=0
|
||||
local processed_bytes=0
|
||||
local active_bans=0
|
||||
if [ "$cs_running" = "1" ]; then
|
||||
# Parse Total line from Bouncer Metrics table
|
||||
# Format: | Total | 16.00k | 13.72k | 231 | 356.19k | 6.02k |
|
||||
@ -2246,14 +2249,12 @@ get_overview() {
|
||||
totals=$(run_cscli metrics 2>/dev/null | grep -E '^\|.*Total' | sed 's/|//g')
|
||||
if [ -n "$totals" ]; then
|
||||
# Convert k/M suffixes to numbers
|
||||
active_bans=$(echo "$totals" | awk '{gsub(/k$/,"",$2); gsub(/M$/,"",$2); if($2~/\./){$2=$2*1000}; print int($2)}')
|
||||
dropped_bytes=$(echo "$totals" | awk '{v=$3; gsub(/k$/,"",v); gsub(/M$/,"",v); if(v~/\./){v=v*1000}; print v}')
|
||||
dropped_packets=$(echo "$totals" | awk '{print $4}')
|
||||
processed_bytes=$(echo "$totals" | awk '{v=$5; gsub(/k$/,"",v); gsub(/M$/,"",v); if(v~/\./){v=v*1000}; if(v=="-")v=0; print v}')
|
||||
processed_packets=$(echo "$totals" | awk '{v=$6; gsub(/k$/,"",v); gsub(/M$/,"",v); if(v~/\./){v=v*1000}; if(v=="-")v=0; print v}')
|
||||
fi
|
||||
fi
|
||||
json_add_int "active_bans" "${active_bans:-0}"
|
||||
json_add_string "dropped_packets" "${dropped_packets:-0}"
|
||||
json_add_string "dropped_bytes" "${dropped_bytes:-0}"
|
||||
json_add_string "processed_packets" "${processed_packets:-0}"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"admin/secubox/services/crowdsec": {
|
||||
"admin/secubox/security/crowdsec": {
|
||||
"title": "CrowdSec",
|
||||
"order": 10,
|
||||
"action": {
|
||||
@ -9,7 +9,7 @@
|
||||
"acl": ["luci-app-crowdsec-dashboard"]
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/overview": {
|
||||
"admin/secubox/security/crowdsec/overview": {
|
||||
"title": "Overview",
|
||||
"order": 5,
|
||||
"action": {
|
||||
@ -17,7 +17,7 @@
|
||||
"path": "crowdsec-dashboard/overview"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/wizard": {
|
||||
"admin/secubox/security/crowdsec/wizard": {
|
||||
"title": "Setup Wizard",
|
||||
"order": 10,
|
||||
"action": {
|
||||
@ -25,7 +25,7 @@
|
||||
"path": "crowdsec-dashboard/wizard"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/decisions": {
|
||||
"admin/secubox/security/crowdsec/decisions": {
|
||||
"title": "Decisions",
|
||||
"order": 20,
|
||||
"action": {
|
||||
@ -33,7 +33,7 @@
|
||||
"path": "crowdsec-dashboard/decisions"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/alerts": {
|
||||
"admin/secubox/security/crowdsec/alerts": {
|
||||
"title": "Alerts",
|
||||
"order": 30,
|
||||
"action": {
|
||||
@ -41,7 +41,7 @@
|
||||
"path": "crowdsec-dashboard/alerts"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/bouncers": {
|
||||
"admin/secubox/security/crowdsec/bouncers": {
|
||||
"title": "Bouncers",
|
||||
"order": 40,
|
||||
"action": {
|
||||
@ -49,7 +49,7 @@
|
||||
"path": "crowdsec-dashboard/bouncers"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/waf": {
|
||||
"admin/secubox/security/crowdsec/waf": {
|
||||
"title": "WAF/AppSec",
|
||||
"order": 45,
|
||||
"action": {
|
||||
@ -57,7 +57,7 @@
|
||||
"path": "crowdsec-dashboard/waf"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/metrics": {
|
||||
"admin/secubox/security/crowdsec/metrics": {
|
||||
"title": "Metrics",
|
||||
"order": 50,
|
||||
"action": {
|
||||
@ -65,7 +65,7 @@
|
||||
"path": "crowdsec-dashboard/metrics"
|
||||
}
|
||||
},
|
||||
"admin/secubox/services/crowdsec/settings": {
|
||||
"admin/secubox/security/crowdsec/settings": {
|
||||
"title": "Settings",
|
||||
"order": 90,
|
||||
"action": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user