Commit 7323580d authored by Vitaly Lipatov's avatar Vitaly Lipatov

router: require jq for route-health.sh, add fatal() to functions

Replace broken sed JSON fallback with epm assure jq. Add fatal() helper to shared functions. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent dd98c05a
......@@ -2,6 +2,7 @@
# --- Shared helpers (used by route-update.sh, route-health.sh) ---
log() { echo "$(date '+%H:%M:%S') $*" ; }
fatal() { log "FATAL: $*" >&2 ; exit 1 ; }
# Read first non-comment non-empty line from a config file
read_value() { grep -v '^#' "$1" 2>/dev/null | grep -m1 . ; }
......
......@@ -35,12 +35,8 @@ if [ -z "$response" ] ; then
fi
# Parse JSON → "gateway packet_loss" lines
if command -v jq >/dev/null 2>&1 ; then
echo "$response" | jq -r '.results[0].series[]? | "\(.tags.gateway) \(.values[0][1])"' > "$HEALTH_DATA"
else
echo "$response" | sed 's/},/}\n/g' | \
sed -n 's/.*"gateway":"\([^"]*\)".*\[\["[^"]*",\([0-9.]*\)\].*/\1 \2/p' > "$HEALTH_DATA"
fi
epm -y assure jq || fatal "jq is required"
echo "$response" | jq -r '.results[0].series[]? | "\(.tags.gateway) \(.values[0][1])"' > "$HEALTH_DATA"
if [ ! -s "$HEALTH_DATA" ] ; then
log "ERROR: No health data from InfluxDB"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment