Files
security-alert-center/docs/runbook-ops.md
T
PTah 415d863b3b feat: SAC daily reports from DB aggregation (notif-32)
- Aggregate report.daily.ssh/rdp from 24h ingest; job and systemd timer

- notify_daily_report bypasses NOTIFY_MIN_SEVERITY; ingest routes agent reports

- HTML templates, env SAC_DAILY_REPORT_*, docs and tests (56 cases)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 16:30:07 +10:00

95 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Runbook: эксплуатация SAC
Краткие процедуры для prod (`sac.kalinamall.ru`, native install в `/opt/security-alert-center`).
## Деплой приложения
```bash
sudo /opt/sac-deploy.sh
```
Скрипт: `git pull` / `reset --hard`, `pip install`, `alembic upgrade head`, `npm run build`, `systemctl restart sac-api`.
Проверка:
```bash
curl -sS https://sac.kalinamall.ru/health | jq .
```
Ожидается `status: ok`, `database: ok`. При устаревших heartbeat агентов — `status: degraded`, поле `hosts_stale` > 0.
## Резервное копирование PostgreSQL
```bash
sudo -u postgres pg_dump -Fc sac > /var/backups/sac-$(date +%Y%m%d).dump
```
Восстановление (на тестовый инстанс):
```bash
sudo -u postgres pg_restore -d sac_test --clean /var/backups/sac-YYYYMMDD.dump
```
Перед restore на prod — остановить API: `sudo systemctl stop sac-api`.
## Retention (очистка БД)
Политика по умолчанию (`config/sac-api.env`):
| Данные | Срок |
|--------|------|
| `events` | 90 дней (`SAC_EVENTS_RETENTION_DAYS`) |
| `problems` со статусом `resolved` | 180 дней (`SAC_PROBLEMS_RETENTION_DAYS`) |
Ручной прогон:
```bash
sudo -u sac bash -c '
set -a; source /opt/security-alert-center/config/sac-api.env; set +a
cd /opt/security-alert-center/backend
.venv/bin/python -m app.jobs.retention
'
```
Установка ежедневного timer (один раз):
```bash
sudo cp /opt/security-alert-center/deploy/systemd/sac-retention.service /etc/systemd/system/
sudo cp /opt/security-alert-center/deploy/systemd/sac-retention.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now sac-retention.timer
systemctl list-timers sac-retention.timer
```
## Суточные отчёты (F-NOT-05)
```bash
sudo cp /opt/security-alert-center/deploy/systemd/sac-daily-report.service /etc/systemd/system/
sudo cp /opt/security-alert-center/deploy/systemd/sac-daily-report.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now sac-daily-report.timer
systemctl list-timers sac-daily-report.timer
# Ручной прогон (игнор часа)
sudo -u sac bash -lc 'cd /opt/security-alert-center/backend && .venv/bin/python -m app.jobs.daily_report --force'
```
Переменные: `SAC_DAILY_REPORT_*` в `config/sac-api.env` (см. `deploy/env.native.example`).
## Health и мониторинг
| Endpoint | Назначение |
|----------|------------|
| `GET /health` | БД, версия, `hosts_stale`, `last_event_received_at` |
| `GET /api/v1/stream/events` | SSE для UI (счётчики + `last_event_id` каждые 5 с) |
Агенты: `GET /health` без JWT. UI Dashboard: блок «Последние события» подгружается при смене `last_event_id` в SSE.
## Типовые проблемы
**События в Telegram есть, в UI нет** — проверить ingest (лог агента `SAC: accepted`), режим `UseSAC`, обновить Dashboard (live ~5 с).
**422 на ingest** — см. `Logs/sac-last-post.json` на Windows-агенте; обновить `Sac-Client.ps1` (RDP) или `sac-client.sh` (Linux).
**Устаревший heartbeat** — увеличить `SAC_HEARTBEAT_STALE_MINUTES` или проверить `agent.heartbeat` на хосте.