jaybamroliya/autonomou-ai-incident-response-orchestrator
GitHub: jaybamroliya/autonomou-ai-incident-response-orchestrator
基于 Kestra 编排引擎和 GPT-4o 的自主事件响应平台,实现从故障检测、日志采集、AI 根因分析到团队告警和工单创建的全流程自动化。
Stars: 0 | Forks: 0
# 🚨 自主 AI 事件响应编排器
### *AI 驱动。事件驱动。全自动化。*
[](https://kestra.io)
[](https://openai.com)
[](https://fastapi.tiangolo.com)
[](https://docker.com)
[](https://python.org)
[](LICENSE)
**检测故障 → 收集证据 → 运行 AI 分析 → 警告您的团队 → 创建工单 → 生成报告**
*全部在 60 秒内完成。由 Kestra 全面编排。*
[**🚀 快速开始**](#-quick-start) · [**📐 架构**](#-architecture) · [**🎬 演示**](#-demo) · [**🔄 工作流**](#-kestra-orchestration-workflows) · [**🤖 AI 分析**](#-ai-powered-analysis)
## 🎯 这是什么?
一个生产级的**自主事件响应平台**,使用 [Kestra](https://kestra.io) 作为其编排中枢,自动响应生产故障——从检测到解决建议——无需人工干预。
当您的服务宕机时,此系统会:
| 步骤 | 动作 | 时间 |
|------|--------|------|
| 🔍 **检测** | Kestra 健康监控触发(每 60 秒调度一次) | `0s` |
| 📊 **分类** | 严重程度 (CRITICAL/HIGH/MEDIUM/LOW) + SLA 计时器 | `+2s` |
| 📋 **收集** | 来自受影响服务的日志 + 指标(并行) | `+5s` |
| 🤖 **分析** | OpenAI GPT-4o 根本原因分析 + 修复建议 | `+20s` |
| 💬 **警告** | 包含 AI 摘要的丰富 Slack Block Kit 通知 | `+25s` |
| 🐙 **工单** | 包含完整 AI 分析 + 步骤的 GitHub issue | `+25s` |
| 📄 **报告** | 企业级事件报告 (Markdown) | `+30s` |
**总计:从故障发生到生成完整的事件响应包约需 ~30 秒。**
## 📐 架构
```
┌──────────────────────────────────────────────────────────────────┐
│ KESTRA ORCHESTRATION ENGINE │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ master-incident-orchestration │ │
│ │ │ │
│ │ STAGE 1 STAGE 2 STAGE 3 │ │
│ │ ┌──────────┐ ┌────────────┐ ┌─────────────────┐ │ │
│ │ │ Classify │───▶│ Collect │───▶│ AI Analyze │ │ │
│ │ │ Severity │ │ Parallel: │ │ GPT-4o │ │ │
│ │ └──────────┘ │ logs+metrcs│ └────────┬────────┘ │ │
│ │ └────────────┘ │ │ │
│ │ STAGE 4 STAGE 5 │ │ │
│ │ ┌───────────────────────┐ ┌──────────┐ │ │ │
│ │ │ Parallel Notifications│◀───│ Report │◀─┘ │ │
│ │ │ ├─ Slack Alert │ │ Generate │ │ │
│ │ │ └─ GitHub Issue │ └──────────┘ │ │
│ │ └───────────────────────┘ │ │
│ └──────────────────────────────────────────────────────────┘ │
│ ▲ │
│ ┌────────────┘ │
│ ┌───────────────────────────────┐ │
│ │ health-check (cron: * * * * *) │
│ │ Polls /health every 60s │
│ │ → fires master pipeline on failure │
│ └───────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
│ │ │
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌────────────────┐
│ FastAPI Service │ │ OpenAI API │ │ Slack + GitHub │
│ payment-api sim │ │ GPT-4o │ │ Notifications │
│ │ │ │ │ │
│ GET /health │ │ Root cause │ │ Block Kit │
│ GET /metrics │ │ Remediation │ │ Rich alerts │
│ GET /logs │ │ Severity │ │ Auto issues │
│ POST /simulate │ │ Impact │ │ │
└──────────────────┘ └──────────────────┘ └────────────────┘
```
### Mermaid 图表
```
flowchart TD
HC[🔍 health-check\ncron: every 60s] -->|HTTP 5xx detected| MO
subgraph MO[master-incident-orchestration]
S1[Stage 1\nClassify Severity] --> S2
subgraph S2[Stage 2 — Parallel Collection]
L1[Fetch Error Logs]
L2[Fetch Critical Logs]
L3[Fetch Metrics]
end
S2 --> S3[Stage 3\n🤖 AI Analysis\nGPT-4o]
S3 --> S4
subgraph S4[Stage 4 — Parallel Notifications]
N1[💬 Slack Alert]
N2[🐙 GitHub Issue]
end
S4 --> S5[Stage 5\n📄 Report Generation]
S5 --> S6[✅ Pipeline Complete]
end
IS[FastAPI\nIncident Service] -->|logs + metrics| S2
OAI[OpenAI GPT-4o] -->|root cause + remediation| S3
SLACK[Slack] -->|Block Kit alert| N1
GH[GitHub API] -->|auto issue| N2
```
## 🗂️ 项目结构
```
autonomous-ai-incident-response-orchestrator/
│
├── 🐳 docker-compose.yml # Full stack: Kestra + PostgreSQL + Incident Service
├── ⚙️ .env.example # Environment configuration template
├── 📋 Makefile # Developer shortcuts
│
├── 📦 incident-service/ # FastAPI failure simulation service
│ ├── app.py # 6 realistic failure scenarios, logs, metrics
│ ├── requirements.txt
│ └── Dockerfile
│
├── 🔄 kestra/flows/ # ← THE HERO — 8 orchestration workflows
│ ├── 01-health-check-flow.yml # Cron monitor → incident trigger
│ ├── 02-incident-trigger-flow.yml # Signal enrichment + classification
│ ├── 03-log-collection-flow.yml # Parallel log + metrics fetch
│ ├── 04-ai-root-cause-analysis-flow.yml # GPT-4o analysis engine
│ ├── 05-slack-notification-flow.yml # Block Kit Slack alerts
│ ├── 06-github-issue-flow.yml # Auto GitHub issue creation
│ ├── 07-incident-report-flow.yml # Markdown report generator
│ └── 08-master-incident-orchestration-flow.yml # ← Master pipeline
│
├── 📜 scripts/
│ ├── trigger-demo.sh # Interactive demo launcher
│ ├── test-integrations.py # Pre-demo integration checker
│ └── load-flows.sh # Auto-loads flows on startup
│
└── 📄 reports/
└── sample-incident-report.md # Example AI-generated report
```
## ⚡ 快速开始
### 前置条件
- [Docker Desktop](https://docker.com/products/docker-desktop)(带有 Compose v2)
- OpenAI API 密钥([在此获取](https://platform.openai.com/api-keys))
- Slack webhook URL(可选——[创建一个](https://api.slack.com/messaging/webhooks))
- GitHub 个人访问令牌(可选——需要 repo 权限)
### 1. 克隆并配置
```
git clone https://github.com/jaybamroliya/autonomou-ai-incident-response-orchestrator
cd autonomous-ai-incident-response-orchestrator
# 配置你的 API keys
cp .env.example .env
# 编辑文件 — 至少设置 OPENAI_API_KEY
```
### 2. 启动所有服务
```
docker compose up -d
```
这将启动:
- **Kestra** 位于 http://localhost:8080(编排引擎 + UI)
- **事件服务 (Incident Service)** 位于 http://localhost:8000(FastAPI 模拟服务)
- **PostgreSQL**(Kestra 后端存储)
- **Flow 加载器**(自动将所有 8 个工作流导入 Kestra)
等待约 30 秒启动,然后打开 **http://localhost:8080** 🎉
### 3. 验证设置
```
python3 scripts/test-integrations.py
```
### 4. 运行您的第一次演示
```
# 交互式 demo script
bash scripts/trigger-demo.sh
# 或:直接触发 CRITICAL 数据库故障
curl -X POST "http://localhost:8000/simulate-failure?failure_type=database_connection_pool_exhausted"
```
然后打开 **http://localhost:8080** → Flows → `master-incident-orchestration` → 观看它运行!
## 🔄 Kestra 编排工作流
所有 8 个工作流位于 `kestra/flows/` 中,并在启动时自动加载到 Kestra 中。
| Flow | 触发器 | 描述 |
|------|---------|-------------|
| `health-check` | ⏰ Cron(每 60 秒) | 轮询服务健康状况,在失败时触发事件流水线 |
| `incident-trigger` | 📡 子流程 | 丰富事件信号,分类严重程度 |
| `log-collection` | 📡 子流程 | 并行获取错误日志 + 指标 |
| `ai-root-cause-analysis` | 📡 子流程 | GPT-4o 分析及结构化 JSON 输出 |
| `slack-notification` | 📡 子流程 | 包含 AI 摘要的 Block Kit Slack 警报 |
| `github-issue` | 📡 子流程 | 自动创建带有完整报告的已标记 GitHub issue |
| `incident-report` | 📡 子流程 | 生成企业级 Markdown 事件报告 |
| **`master-incident-orchestration`** | 📡 子流程 / 手动 | **主角——端到端编排所有阶段** |
### 手动触发 (Kestra UI)
1. 打开 http://localhost:8080
2. **Flows** → `ai.incident.response` → `master-incident-orchestration`
3. 点击 **Execute** → 填写输入项:
- `incident_id`: `INC-DEMO001`
- `failure_type`: `database_connection_pool_exhausted`
- `component`: `postgres-primary`
- `error_message`: `FATAL: connection pool exhausted — max_connections=100 exceeded`
4. 观看 5 阶段执行图的动画!
## 🤖 AI 驱动的分析
AI 引擎将丰富的事件上下文发送到 **GPT-4o** 并返回:
```
{
"root_cause": {
"summary": "PostgreSQL connection pool exhausted by batch migration + traffic spike",
"confidence_pct": 94
},
"severity_assessment": {
"level": "CRITICAL",
"blast_radius": "~45,000 concurrent users",
"slo_breach": true
},
"business_impact": {
"revenue_risk": "$28,000/minute",
"affected_users_estimate": "~45,000 active users"
},
"remediation": {
"immediate_actions": [
{
"step": 1,
"action": "Kill runaway batch migration",
"command": "psql -c \"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE query LIKE '%migrate%';\"",
"eta_minutes": 2
}
],
"estimated_resolution_minutes": 25
}
}
```
### 模拟的故障场景
| 场景 | 严重程度 | HTTP 代码 |
|----------|----------|-----------|
| `database_connection_pool_exhausted` | CRITICAL | 503 |
| `memory_leak_oom` | CRITICAL | 500 |
| `disk_io_saturation` | CRITICAL | 507 |
| `downstream_api_timeout` | HIGH | 504 |
| `rate_limit_cascade` | HIGH | 429 |
| `certificate_expiry` | HIGH | 495 |
## ⚙️ 配置
| 变量 | 描述 | 必需 |
|----------|-------------|----------|
| `OPENAI_API_KEY` | OpenAI API 密钥 (GPT-4o) | ✅ 是 |
| `SLACK_WEBHOOK_URL` | Slack Incoming Webhook URL | 可选 |
| `GITHUB_TOKEN` | GitHub 个人访问令牌 | 可选 |
| `GITHUB_REPO` | GitHub 仓库 (`owner/repo`) | 可选 |
| `FAILURE_PROBABILITY` | 自动故障率 0.0-1.0(默认:0.3) | 可选 |
| `OPENAI_MODEL` | OpenAI 模型(默认:`gpt-4o`) | 可选 |
## 🏗️ 技术栈
| 组件 | 技术 | 用途 |
|-----------|-----------|---------|
| **编排** | [Kestra](https://kestra.io) | 工作流引擎,DAG 执行,调度 |
| **AI 引擎** | [OpenAI GPT-4o](https://openai.com) | 根本原因分析,修复建议 |
| **模拟** | [FastAPI](https://fastapi.tiangolo.com) | 真实的事件模拟 |
| **告警** | [Slack Block Kit](https://api.slack.com/block-kit) | 丰富的事件通知 |
| **工单管理** | [GitHub API v3](https://docs.github.com/en/rest) | 自动创建 issue |
| **存储** | [PostgreSQL 15](https://postgresql.org) | Kestra 后端 |
| **运行时** | [Docker Compose](https://docs.docker.com/compose/) | 本地部署 |
## 🗺️ 未来路线图
- [ ] PagerDuty 集成——针对 CRITICAL 事件的自动升级
- [ ] Prometheus + Grafana——真实指标监控
- [ ] 自动修复——Kestra 自动执行修复命令
- [ ] 多服务监控——同时监控 N 个服务
- [ ] Webhook 接收器——接受来自 Prometheus/Datadog/CloudWatch 的警报
- [ ] Post-mortem 文档生成器——AI 编写完整的复盘报告
- [ ] SLA 跟踪仪表板——随时间变化的 MTTR/MTTD 指标
## 📜 许可证
MIT——详见 [LICENSE](LICENSE)
**为 [Kestra 编排挑战赛](https://kestra.io) 而构建**
*AI 驱动的 DevOps 自动化——从检测到解决只需 30 秒。*
标签:AI, AIOps, AI分析, AI引擎, AV绕过, DLL 劫持, Docker, FastAPI, GitHub Actions, GPT-4o, IT运维, Kestra, LLM, NIDS, OpenAI, Python, RCA, Slack, Socks5代理, SRE, Unmanaged PE, 事件响应自动化, 人工智能, 代理支持, 企业安全, 偏差过滤, 内存规避, 告警, 团队协作, 大语言模型, 安全防御评估, 容器化, 工作流编排, 工单管理, 故障分析, 无后门, 智能运维, 根因分析, 测试用例, 版权保护, 生产环境, 用户模式Hook绕过, 监控, 系统可靠性, 编排, 网络资产管理, 自主事件响应, 自动化代码审查, 自动化平台, 自动笔记, 请求拦截, 运维自动化, 通知告警