#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEST_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" TMP_DIR="$TEST_ROOT/tmp" # 载入端口变量 if [[ -f "$TEST_ROOT/.env" ]]; then set -a; source "$TEST_ROOT/.env"; set +a fi API_BASE="http://localhost:${MASTER_PORT:-32300}/api/v1/master" HOST_A="dev-yyrshare-nbnyx10-cp2f-pod-0" HOST_B="dev-yyrshare-uuuu10-ep2f-pod-0" HEALTH_A="$TEST_ROOT/private-nodea/argus/agent/$HOST_A/health" HEALTH_B="$TEST_ROOT/private-nodeb/argus/agent/$HOST_B/health" write_health() { local dir="$1"; mkdir -p "$dir" cat > "$dir/log-fluentbit.json" < "$dir/metric-node-exporter.json" </dev/null || true) [[ -z "$resp" ]] && continue echo "$resp" > "$TMP_DIR/node_${id}_detail.json" if python3 - "$TMP_DIR/node_${id}_detail.json" <<'PY' import json,sys node=json.load(open(sys.argv[1])) h=node.get("health",{}) sys.exit(0 if ("log-fluentbit" in h and "metric-node-exporter" in h) else 1) PY then return 0; fi done return 1 } check_health "$ID_A" || { echo "[ERR] health keys not reported for node A" >&2; exit 1; } check_health "$ID_B" || { echo "[ERR] health keys not reported for node B" >&2; exit 1; } NODES_JSON="$TEST_ROOT/private/argus/metric/prometheus/nodes.json" if [[ ! -f "$NODES_JSON" ]]; then echo "[ERR] nodes.json missing at $NODES_JSON" >&2; exit 1 fi python3 - "$NODES_JSON" <<'PY' import json,sys with open(sys.argv[1]) as h: nodes=json.load(h) assert isinstance(nodes,list) assert len(nodes) == 2, f"expected 2 nodes online, got {len(nodes)}" PY echo "[OK] Health reported and nodes.json has 2 online nodes"