61 lines
1.7 KiB
Bash
Executable File
61 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
cd "$(dirname "$0")/.."
|
|
[ -f .env ] || cp .env.example .env
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "docker is required for the full self-test" >&2
|
|
exit 2
|
|
fi
|
|
|
|
echo "[selftest] waiting for dashboard/Suricata"
|
|
i=0
|
|
while [ "$i" -lt 30 ]; do
|
|
if docker compose exec -T ids python3 /opt/ids/scripts/healthcheck.py >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
i=$((i + 1))
|
|
sleep 1
|
|
done
|
|
if [ "$i" -ge 30 ]; then
|
|
echo "[selftest] service did not become healthy" >&2
|
|
docker compose logs --tail=100 ids >&2 || true
|
|
exit 3
|
|
fi
|
|
|
|
START_SIZE="$(docker compose exec -T ids python3 - <<'PY'
|
|
import os
|
|
print(os.path.getsize('/data/logs/suricata/eve.json') if os.path.exists('/data/logs/suricata/eve.json') else 0)
|
|
PY
|
|
)"
|
|
START_SIZE="$(printf '%s' "$START_SIZE" | tr -d '\r\n ')"
|
|
|
|
docker compose exec -T ids python3 /opt/ids/scripts/send_test_tzsp.py --host 127.0.0.1 --count 3
|
|
sleep 3
|
|
|
|
docker compose exec -T -e SELFTEST_START_SIZE="$START_SIZE" ids python3 - <<'PY'
|
|
import json
|
|
import os
|
|
|
|
path = '/data/logs/suricata/eve.json'
|
|
start = int(os.environ.get('SELFTEST_START_SIZE', '0'))
|
|
found = 0
|
|
with open(path, 'r', encoding='utf-8', errors='replace') as handle:
|
|
try:
|
|
handle.seek(start)
|
|
except OSError:
|
|
handle.seek(0)
|
|
for line in handle:
|
|
try:
|
|
event = json.loads(line)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
alert = event.get('alert') or {}
|
|
if alert.get('signature_id') == 1000001:
|
|
found += 1
|
|
if not found:
|
|
raise SystemExit('SELFTEST FAILED: Suricata did not emit reserved SID 1000001')
|
|
print(f'SELFTEST OK: Suricata emitted {found} marked TZSP pipeline test alert(s); UI filtering remains enabled')
|
|
PY
|