abdulbasitha/aldar-incident-monitoring

GitHub: abdulbasitha/aldar-incident-monitoring

一个结合大语言模型多智能体工作流与实时 Web 看板的事件自动响应平台,旨在通过自动化定级、分析、代码修复建议及工单创建来加速生产故障的处理。

Stars: 0 | Forks: 0

# Aldar 事件监控平台 基于 AI 的事件响应 pipeline,配备实时监控 dashboard。基于 FastAPI + LangGraph (Python) 和 Next.js 14 (TypeScript) 构建。 ``` agent_monitoring/ ├── agents/ # FastAPI backend + LangGraph pipeline └── dashboard/ # Next.js monitoring dashboard ``` ## 架构 ``` Datadog Webhook → FastAPI → LangGraph StateGraph │ ┌────────────────────┼────────────────────┐ ▼ ▼ ▼ triage_agent rag_agent lookup_agent (P1–P5 classify) (ChromaDB search) (resolution hint) │ P1/P2 only ──► analysis_agent (RCA) │ P1 only ──► [Human Gate] ──► code_fix_agent (GitHub PR) │ ticket_agent (Jira) ``` Next.js dashboard 通过 HTTP 连接到 FastAPI 后端和 ChromaDB。认证使用存储在 httpOnly cookie 中的 JWT。 ## 前置条件 - Python 3.11+ - Node.js 20+ - Docker + Docker Compose ## 快速开始 ### 1. 启动基础设施 ``` docker-compose up -d ``` 这将启动 PostgreSQL (端口 5433)、Redis (6379) 和 ChromaDB (8001)。 ### 2. 配置 Python 后端 ``` cd agents python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` 复制并编辑 env 文件: ``` cp .env.example .env ``` 本地开发所需的最低配置(`DEV_MODE=true` 会从 `.env` 而不是 Azure Key Vault 中读取): ``` DEV_MODE=true # Azure OpenAI AZURE_OPENAI_ENDPOINT=https://YOUR-RESOURCE.openai.azure.com/ AZURE_OPENAI_KEY=your-key AZURE_OPENAI_GPT4O_DEPLOYMENT=gpt-4o AZURE_OPENAI_GPT4O_MINI_DEPLOYMENT=gpt-4o-mini AZURE_OPENAI_EMBEDDING_DEPLOYMENT=text-embedding-3-small # 集成 JIRA_BASE_URL=https://your-org.atlassian.net JIRA_EMAIL=you@example.com JIRA_API_TOKEN=your-token CONFLUENCE_BASE_URL=https://your-org.atlassian.net/wiki CONFLUENCE_EMAIL=you@example.com CONFLUENCE_API_TOKEN=your-token DATADOG_API_KEY=your-key DATADOG_APP_KEY=your-app-key DATADOG_WEBHOOK_SECRET=your-secret GITHUB_TOKEN=ghp_... GITHUB_REPO=your-org/your-repo # Infrastructure POSTGRES_URL=postgresql://aldar:localdev@localhost:5433/incidents REDIS_URL=redis://localhost:6379 # Dashboard 认证 — 为生产环境生成你自己的密钥 DASHBOARD_JWT_SECRET=change-me-in-production DASHBOARD_JWT_EXPIRE_MINUTES=480 ``` 从**项目根目录**(不要在 `agents/` 内)启动后端: ``` # 从 agent_monitoring/ set -a; source agents/.env; set +a PYTHONPATH=. agents/.venv/bin/python -m uvicorn agents.api.main:app --port 8000 --reload ``` - API: http://localhost:8000 - Swagger UI: http://localhost:8000/docs ### 3. 初始化管理员账户 ``` curl -X POST http://localhost:8000/auth/bootstrap ``` 默认凭据(通过 `ADMIN_EMAIL` / `ADMIN_PASSWORD` 环境变量覆盖): - 邮箱: `admin@aldar.com` - 密码: `aldar-admin-2026` ### 4. 配置 Next.js dashboard ``` cd dashboard npm install ``` 创建 `dashboard/.env.local`: ``` NEXT_PUBLIC_API_URL=http://localhost:8000 NEXT_PUBLIC_CHROMA_URL=http://localhost:8001 DASHBOARD_JWT_SECRET=change-me-in-production # must match agents/.env ``` 启动 dashboard: ``` npm run dev -- --port 3001 ``` 打开 http://localhost:3001 — 你将被重定向到 `/login`。 ## 项目结构 ``` agent_monitoring/ ├── docker-compose.yml # postgres, redis, chromadb │ ├── agents/ # Python module (FastAPI + LangGraph) │ ├── requirements.txt │ ├── pytest.ini │ ├── .env # local secrets (git-ignored) │ ├── .env.example │ │ │ ├── agents/ # LangGraph agent implementations │ │ ├── base.py # BaseAgent + safe_run() │ │ ├── registry.py # AgentRegistry + DI root │ │ ├── graph.py # StateGraph assembly │ │ ├── triage/agent.py │ │ ├── analysis/agent.py │ │ ├── rag/agent.py │ │ ├── lookup/agent.py │ │ ├── ticket/agent.py │ │ └── code_fix/agent.py │ │ │ ├── api/ │ │ ├── main.py # FastAPI app + lifespan │ │ ├── auth.py # X-Client-ID / X-Client-Secret machine auth │ │ ├── dependencies.py │ │ ├── models.py │ │ └── routers/ │ │ ├── auth.py # POST /auth/login, GET /auth/me, POST /auth/logout │ │ ├── admin.py # GET/POST/PATCH/DELETE /admin/users │ │ ├── webhook.py # POST /webhook/datadog │ │ ├── incidents.py # GET /incidents[/{id}[/stream]] │ │ ├── approvals.py # POST /incidents/{id}/approve │ │ ├── agent_config.py # GET/PUT /agent-configs, PATCH /agent-configs/{name}/toggle │ │ ├── dashboard.py # GET /dashboard/stats, projects CRUD │ │ └── ingest.py # POST /ingest (bulk APM error counts) │ │ │ ├── core/ │ │ ├── state.py # Priority enum + IncidentState TypedDict │ │ └── interfaces.py # IAgent, ITicketingClient protocols │ │ │ ├── db/ │ │ ├── models.py # Incident, AgentRun, AgentModelConfig, DashboardUser, ProjectConfig │ │ ├── session.py # Async engine + table creation │ │ └── repository.py # Repository classes │ │ │ ├── infrastructure/ │ │ ├── llm_factory.py │ │ ├── credentials.py # Azure Key Vault fetch + Redis cache │ │ └── vector_store.py # ChromaDB client │ │ │ ├── integrations/ │ │ ├── jira/client.py │ │ ├── confluence/client.py │ │ ├── github/client.py │ │ └── datadog/client.py │ │ │ ├── scripts/ │ │ └── generate_client.py # Create API credentials │ │ │ └── tests/ │ ├── agents/ │ ├── api/ │ └── db/ │ └── dashboard/ # Next.js 14 App Router ├── package.json ├── next.config.ts ├── middleware.ts # JWT cookie guard │ └── app/ ├── layout.tsx ├── page.tsx # Overview / stats ├── login/page.tsx # Login form ├── agents/ # Agent controls + ChromaDB viewer ├── incidents/ # Incident list + detail ├── projects/ # Project config CRUD ├── settings/page.tsx ├── admin/ # User management (admin only) └── api/ # Next.js proxy routes → FastAPI ``` ## API 参考 | 方法 | 路径 | 认证 | 描述 | |--------|------|------|-------------| | `POST` | `/webhook/datadog` | API key | 接收 Datadog 告警,启动 pipeline | | `GET` | `/incidents` | API key | 列出所有事件 | | `GET` | `/incidents/{id}` | API key | 完整的事件状态 | | `GET` | `/incidents/{id}/stream` | API key | agent 事件的 SSE 流 | | `POST` | `/incidents/{id}/approve` | API key | 批准 / 拒绝暂停的 P1 | | `GET` | `/agent-configs` | API key | 列出每个 agent 的模型部署 | | `PUT` | `/agent-configs/{name}` | API key | 更新 agent 的部署 | | `PATCH` | `/agent-configs/{name}/toggle` | API key | 启用 / 禁用 agent | | `GET` | `/dashboard/stats` | Cookie | dashboard 的聚合统计信息 | | `GET` | `/auth/me` | Cookie | 当前用户 | | `POST` | `/auth/login` | 公开 | 登录,设置 httpOnly cookie | | `POST` | `/auth/logout` | Cookie | 清除会话 cookie | | `GET` | `/admin/users` | 管理员 cookie | 列出 dashboard 用户 | | `POST` | `/admin/users` | 管理员 cookie | 创建 dashboard 用户 | | `PATCH` | `/admin/users/{id}` | 管理员 cookie | 更新角色 / 激活状态 | | `DELETE` | `/admin/users/{id}` | 管理员 cookie | 移除用户 | | `GET` | `/health` | 公开 | 存活检查 | 完整的类型化 schema: http://localhost:8000/docs ## 运行测试 ``` # 从项目根目录 cd agents source .venv/bin/activate pytest tests/ -v # 按 layer pytest tests/agents/ -v # agent unit tests pytest tests/api/ -v # API endpoint tests pytest tests/db/ -v # DB repository tests (SQLite in-memory) ``` ## Dashboard 功能 | 功能 | 描述 | |---------|-------------| | 概览 | 实时统计 — 未解决事件、P1 数量、运行中的 agent、待处理的人工审批 | | 事件 | 完整的事件列表,包含优先级标签、状态、Jira 工单链接 | | Agents | 启用/禁用 agent,更改模型部署,ChromaDB 集合查看器 | | 项目 | 为每个服务添加和管理 Jira / Confluence / GitHub / Azure 仓库绑定 | | 设置 | 系统健康状态、连接配置、环境变量参考 | | 管理 | 用户管理 — 创建用户,分配管理员 / 查看者角色(仅限管理员) | ## 优先级行为 | 优先级 | RCA | 人工关卡 | 代码修复 | |----------|-----|------------|----------| | P1 | 是 | 是 — 阻塞 pipeline | 是(批准后) | | P2 | 是 | 否 | 否 | | P3–P5 | 否 | 否 | 否 | ## 合规性 | 要求 | 实现 | |-------------|----------------| | UAE PDPL | Azure OpenAI 私有 endpoint — 数据永不离开 Azure 租户 | | PCI DSS | prompt 中不包含卡片数据或凭据;仅使用 Azure Key Vault | | Aldar 工程框架 | 本地开发使用 `DEV_MODE=true`;生产环境需要 `AZURE_KEY_VAULT_URL` | | Qanas AI-SAST | 所有代码在合并前均进行扫描 | ## 环境变量参考 | 变量 | 必填 | 默认值 | 描述 | |----------|----------|---------|-------------| | `DEV_MODE` | 否 | `false` | 跳过 Key Vault,从 `.env` 读取 | | `AZURE_OPENAI_ENDPOINT` | 是 | — | Azure OpenAI 资源 URL | | `AZURE_OPENAI_KEY` | 是(开发) | — | API key(仅用于开发;生产环境使用 Key Vault) | | `AZURE_OPENAI_GPT4O_DEPLOYMENT` | 是 | — | gpt-4o 的部署名称 | | `AZURE_OPENAI_GPT4O_MINI_DEPLOYMENT` | 是 | — | gpt-4o-mini 的部署名称 | | `AZURE_OPENAI_EMBEDDING_DEPLOYMENT` | 是 | — | embeddings 的部署名称 | | `POSTGRES_URL` | 是 | — | PostgreSQL 异步连接字符串 | | `REDIS_URL` | 否 | — | Redis URL(缓存 Key Vault 密钥) | | `DASHBOARD_JWT_SECRET` | 是 | `change-me-in-production` | HS256 签名密钥 — 两个模块中必须保持一致 | | `DASHBOARD_JWT_EXPIRE_MINUTES` | 否 | `480` | 会话持续时间(分钟) | | `ADMIN_EMAIL` | 否 | `admin@aldar.com` | 初始管理员邮箱 | | `ADMIN_PASSWORD` | 否 | `aldar-admin-2026` | 初始管理员密码 | | `DATADOG_WEBHOOK_SECRET` | 是 | — | 用于 webhook 验证的 HMAC-SHA256 密钥 | | `JIRA_BASE_URL` | 是 | — | Jira 实例的基本 URL | | `JIRA_EMAIL` | 是 | — | Jira 服务账号邮箱 | | `JIRA_API_TOKEN` | 是 | — | Jira API token | | `CONFLUENCE_BASE_URL` | 是 | — | Confluence 的基本 URL | | `CONFLUENCE_EMAIL` | 是 | — | Confluence 服务账号邮箱 | | `CONFLUENCE_API_TOKEN` | 是 | — | Confluence API token | | `GITHUB_TOKEN` | 是 | — | 用于创建 PR 的 GitHub PAT | | `GITHUB_REPO` | 是 | — | 目标仓库 (`org/repo`) |
标签:AV绕过, Azure OpenAI, FastAPI, LangGraph, 大模型 Agent, 大语言模型蜜罐, 搜索引擎查询, 模块化设计, 测试用例, 自动化修复, 请求拦截, 运维监控, 逆向工具