fix(crowdsec-dashboard): Fix JSON parsing bug in overview cache

grep -c returns exit code 1 when count is 0, which triggered
the `|| echo 0` fallback to also output "0", resulting in:
  "waf_threats_today":0
  0,

This broke JSON parsing and caused the dashboard to show
CrowdSec as "STOPPED" even when running.

Fix: Use `|| :` (no-op) and set defaults with `: "${var:=0}"`

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-03-20 16:16:32 +01:00
parent 1edf7ca7c0
commit 707142c6bb

View File

@ -2541,13 +2541,15 @@ refresh_overview_cache() {
if [ -f "$threats_log" ]; then
local today
today=$(date -u +%Y-%m-%d)
waf_threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null || echo 0)
waf_threats_today=$(grep -c "\"timestamp\": \"$today" "$threats_log" 2>/dev/null || :)
: "${waf_threats_today:=0}"
fi
local autoban_processed=0
local autoban_log="/srv/mitmproxy-in/autoban-processed.log"
if [ -f "$autoban_log" ]; then
autoban_processed=$(wc -l < "$autoban_log" 2>/dev/null || echo 0)
autoban_processed=$(wc -l < "$autoban_log" 2>/dev/null || :)
: "${autoban_processed:=0}"
fi
local cache_timestamp