MohamedGouda99/ai-incident-responder

GitHub: MohamedGouda99/ai-incident-responder

基于 LangGraph 和 RAG 的智能事件响应系统,接收 Prometheus 告警并生成 AI 驱动的修复建议。

Stars: 0 | Forks: 0

# AI 基础设施事件响应器 一个由 AI 驱动的事件响应系统,接收 Prometheus/Alertmanager webhook 告警,使用 **LangGraph** 代理和 **RAG**(LangChain + ChromaDB)搜索运行手册以查找匹配的修复步骤,并通过实时仪表板提供可操作的修复建议。 ## 架构 ``` graph TB subgraph Monitoring PM[Prometheus] --> AM[Alertmanager] end subgraph Backend [FastAPI Backend] WH[Webhook Receiver] --> IS[Incident Store] IS --> AG[LangGraph Agent] AG --> RC[RAG Context Retrieval] RC --> CV[(ChromaDB Vector Store)] AG --> LLM[OpenAI GPT-4o] AG --> AN[Analysis & Remediation] RB[Runbook Ingestion] --> CV end subgraph Frontend [React Dashboard] DB[Dashboard] --> IL[Incident List] DB --> ID[Incident Detail] DB --> RM[Runbook Manager] ID --> AA[AI Analysis View] AA --> RS[Remediation Steps] end AM -->|Webhook| WH Frontend -->|REST API| Backend subgraph Infrastructure GH[GitHub Actions CI/CD] TF[Terraform IaC] CR[GCP Cloud Run] GH --> CR TF --> CR end ``` ## 功能特性 - **Alertmanager Webhook 集成** — 实时接收和处理 Prometheus 告警 - **LangGraph AI 代理** — 多步推理流水线:上下文检索 → 分析 → 修复规划 - **RAG 驱动的运行手册搜索** — 将组织运行手册导入 ChromaDB 进行语义搜索 - **AI 生成的修复建议** — 提供根因分析、包含命令的分步修复方案、置信度评分和影响评估 - **React 仪表板** — 具有统计信息、AI 分析面板和运行手册管理功能的实时事件监控 - **生产级基础设施** — Docker 化,使用 GitHub Actions 进行 CI/CD,使用 Terraform 部署到 GCP Cloud Run ## 技术栈 | 层级 | 技术 | |-------|-----------| | AI 代理 | LangGraph, LangChain | | LLM | OpenAI GPT-4o-mini | | 向量存储 | ChromaDB | | 后端 | FastAPI, Python 3.12 | | 前端 | React 18, TypeScript, Tailwind CSS | | 基础设施 | Docker, GitHub Actions, Terraform | | 云平台 | GCP Cloud Run, Secret Manager | ## 快速开始 ### 前置条件 - Docker & Docker Compose - OpenAI API key ### 本地运行 ``` # 克隆 repository git clone https://github.com/MohamedGouda99/ai-incident-responder.git cd ai-incident-responder # 配置 environment cp .env.example .env # 编辑 .env 并添加您的 OPENAI_API_KEY # 启动所有 services docker-compose up --build ``` 应用程序可通过以下地址访问: - **前端**: http://localhost:3000 - **后端 API**: http://localhost:8000 - **API 文档**: http://localhost:8000/docs ### 发送测试告警 点击仪表板中的 **"Test Alert"** 按钮,或发送手动 webhook: ``` curl -X POST http://localhost:8000/api/v1/webhook/alertmanager \ -H "Content-Type: application/json" \ -d '{ "version": "4", "status": "firing", "alerts": [{ "status": "firing", "labels": { "alertname": "HighCPUUsage", "instance": "web-server-01:9090", "severity": "critical" }, "annotations": { "summary": "CPU usage above 90% for 5 minutes" } }] }' ``` ### 上传运行手册 ``` curl -X POST http://localhost:8000/api/v1/runbooks \ -H "Content-Type: application/json" \ -d '{ "title": "High CPU Usage Runbook", "content": "## When CPU > 90%\n1. Check top processes\n2. Scale horizontally\n3. Review recent deployments", "category": "infrastructure", "tags": ["cpu", "performance"] }' ``` ## 部署 ### 使用 Terraform 部署到 GCP Cloud Run ``` cd terraform # 配置 variables cp terraform.tfvars.example terraform.tfvars # 编辑 terraform.tfvars 并填入您的 GCP project 详情 # Deploy terraform init terraform plan terraform apply ``` ### 使用 GitHub Actions 进行 CI/CD 流水线自动执行以下操作: 1. 对后端和前端进行 Lint 检查和类型检查 2. 构建 Docker 镜像并推送到 GCR 3. 推送到 `main` 分支时部署到 Cloud Run 所需的 GitHub Secrets: - `GCP_PROJECT_ID` — 你的 GCP 项目 ID - `GCP_SA_KEY` — 服务账号密钥 JSON - `OPENAI_API_KEY` — OpenAI API key ## 项目结构 ``` ├── backend/ │ ├── app/ │ │ ├── agents/ # LangGraph incident analysis agent │ │ ├── api/ # FastAPI route handlers │ │ ├── core/ # Configuration and logging │ │ ├── models/ # Pydantic schemas │ │ └── services/ # Vector store, incident store, seeder │ ├── runbooks/ # Sample runbook documents │ ├── Dockerfile │ └── requirements.txt ├── frontend/ │ ├── src/ │ │ ├── components/ # React UI components │ │ ├── hooks/ # Custom React hooks │ │ ├── lib/ # API client │ │ └── types/ # TypeScript type definitions │ ├── Dockerfile │ └── nginx.conf ├── terraform/ # GCP Cloud Run infrastructure ├── .github/workflows/ # CI/CD pipeline ├── docker-compose.yml └── .env.example ``` ## 截图 ## 许可证 MIT
标签:Agent, AIOps, Alertmanager, API集成, AV绕过, ChromaDB, Cloud Run, Dashboard, DLL 劫持, Docker, EC2, ECS, FastAPI, GCP, GitHub Actions, Google Cloud, GPT-4o, IaC, Incident Response, LangChain, LangGraph, LLM, Python, RAG, React, Ruby, Runbook, Serverless, SRE, Syscalls, Terraform, Unmanaged PE, Webhook, 人工智能, 仪表盘, 偏差过滤, 力导向图, 可观测性, 向量数据库, 大语言模型, 安全防御评估, 故障自愈, 无后门, 根因分析, 检索增强生成, 用户模式Hook绕过, 监控告警, 知识库, 自动化攻击, 自动笔记, 语义搜索, 请求拦截, 轻量级, 运维自动化, 逆向工具