pedropardo14/incident-response-platform

GitHub: pedropardo14/incident-response-platform

这是一个基于 Mercury Composable 框架的自托管事件响应系统,能够自动化处理 GitHub Actions 失败,通过并行分流评估严重性并联动 Microsoft Teams 与 Notion 完成警报与文档记录。

Stars: 0 | Forks: 0

# IRIS — Incident Response Intelligence System IRIS 是一个自托管的 incident response 平台,基于 [Mercury Composable](https://accenture.github.io/mercury-composable/) 构建,这是 Accenture 开发的事件驱动 Java 框架。当 GitHub Actions workflow 失败时,IRIS 会自动对其进行分流——并行获取最近的提交和服务指标,评估严重性,存储 incident,向 Microsoft Teams 发送警报,并在 Notion 中创建结构化报告。所有编排完全在 YAML 流文件中定义,无需控制器样板代码。 ## 功能 - **自动 incident 检测** — GitHub Actions webhook 在 workflow 失败时触发完整流程 - **并行分流** — 使用 Mercury 的 fork-n-join 执行同时获取提交和服务指标 - **严重性评估** — 根据分支、失败类型和错误率将 incident 分类为 `critical`、`high`、`medium` 或 `low` - **Microsoft Teams 警报** — 在 incident 创建和解决时向您的频道发送富文本卡片 *NOT ADDED - Implimintation is there* - **Notion incident 文档** — 创建包含提交、指标和解决说明的结构化报告页面,并在解决时更新 - **实时仪表板** — 单页 UI,包含实时 incident 列表、统计信息、模拟和解决按钮 - **模拟模式** — 无需真实的 GitHub 失败即可触发逼真的虚假 incident - **定时健康检查** — 通过 Mercury 的 mini-scheduler 每 5 分钟 ping 数据库 ## 架构 每一段业务逻辑都是一个无状态的 `@PreLoad` 函数。所有编排都位于 YAML 流文件中。没有控制器,没有服务层,没有紧耦合。 ### Incident 流程 ``` POST /webhook/github │ ▼ ParseGitHubWebhook ← validates + extracts fields, returns 202 immediately │ fork ───────────────────────────────────┐ │ │ ▼ ▼ FetchRecentCommits FetchServiceMetrics (GitHub API → last 5 commits) (Postgres → error rates) │ │ └─────────────── join ────────────────┘ │ ▼ AssessSeverity ← critical / high / medium / low │ ▼ StoreIncident ← persists to Postgres │ fork ──────────────────────────┐ │ │ ▼ ▼ NotifyTeams CreateNotionPage (Adaptive Card) (structured report) │ │ └──────────── join ──────────┘ │ ▼ UpdateIncidentRecord ← writes Notion URL + Teams status ``` ### Composable 函数 | 函数 | 路由 | 用途 | |---|---|---| | `ParseGitHubWebhook` | `v1.github.parse.webhook` | 验证并提取 webhook 字段 | | `FetchRecentCommits` | `v1.github.fetch.commits` | 通过 GitHub API 获取最近 5 次提交 | | `FetchServiceMetrics` | `v1.metrics.fetch` | 从 Postgres 查询错误指标 | | `AssessSeverity` | `v1.severity.assess` | 根据分支 + 指标计算严重性 | | `StoreIncident` | `v1.incident.store` | 将 incident 记录插入 Postgres | | `NotifyTeams` | `v1.teams.notify` | 向 Teams webhook 发送警报卡片 | | `CreateNotionPage` | `v1.notion.create.page` | 在 Notion 中创建 incident 报告页面 | | `UpdateIncidentRecord` | `v1.incident.update` | 将 Notion URL + Teams 状态写回 | | `ResolveIncident` | `v1.incident.resolve` | 在 Postgres 中标记 incident 已解决 | | `UpdateNotionStatus` | `v1.notion.update.status` | 将 Notion 页面 Status 修补为 Resolved | | `NotifyTeamsResolved` | `v1.teams.notify.resolved` | 向 Teams 发送解决卡片 | | `SimulateFailure` | `v1.simulate.failure` | 生成逼真的虚假 webhook payload | | `HealthCheck` | `iris.health` | 数据库连接 + 未解决 incident 计数 | ### REST 端点 | 方法 | URL | 描述 | |---|---|---| | `POST` | `/webhook/github` | 接收 GitHub Actions 失败 webhook | | `POST` | `/api/simulate/failure` | 触发虚假 incident (演示) | | `GET` | `/api/incidents` | 列出所有 incident | | `GET` | `/api/incidents/{id}` | 按 ID 获取 incident | | `POST` | `/api/incidents/{id}/resolve` | 解决一个 incident | ## 技术栈 | 层级 | 技术 | |---|---| | 框架 | Mercury Composable 4.4.2 | | 运行时 | Java 21 Virtual Threads | | HTTP | Spring Boot 4.0 + Mercury REST Automation | | 数据库 | PostgreSQL (Spring JDBC) | | 调度 | Mercury Mini-Scheduler | | 通知 | Microsoft Teams Incoming Webhook | | 文档 | Notion API | | 代码来源 | GitHub REST API | | HTTP 客户端 | OkHttp 4 | ## 快速开始 ### 前置条件 - Java 21+ - Maven 3.9+ - PostgreSQL - Mercury Composable 源码(用于本地 Maven 安装) ### 1. 安装 Mercury 库 ``` git clone https://github.com/Accenture/mercury-composable cd mercury-composable mvn install -pl "system/platform-core,system/rest-spring-4,system/event-script-engine,system/mini-scheduler" -am -DskipTests ``` ### 2. 设置 Postgres ``` createdb iris ``` Schema 会在首次启动时自动创建。 ### 3. 配置环境变量 在项目根目录下创建 `.env` 文件: ``` # Database (必填) IRIS_DB_URL=jdbc:postgresql://localhost:5432/iris IRIS_DB_USER=your_postgres_user IRIS_DB_PASSWORD=your_postgres_password # GitHub (可选 — 如未设置则回退到 demo commits) GITHUB_TOKEN=ghp_xxxx GITHUB_OWNER=your-github-username GITHUB_REPO=your-repo-name # Microsoft Teams (可选 — 如未设置则日志输出到控制台) TEAMS_WEBHOOK_URL=https://yourorg.webhook.office.com/webhookb2/... # Notion (可选 — 如未设置则日志输出到控制台) NOTION_TOKEN=secret_xxxx NOTION_DATABASE_ID=your-database-id ``` ### 4. 构建 ``` mvn package -DskipTests ``` ### 5. 运行 ``` set -a && source .env && set +a java -jar target/incident-response-platform-1.0.0.jar ``` 在浏览器中打开 `http://localhost:8200`。 ## 配置集成 ### GitHub Webhook 1. 进入您的仓库 → **Settings → Webhooks → Add webhook** 2. Payload URL: `http://your-server:8200/webhook/github` 3. Content type: `application/json` 4. Events: 选择 **Workflow runs** ### Microsoft Teams 1. 在 Teams 中,打开频道 → `...` → **Connectors** 2. 配置 **Incoming Webhook**,将其命名为 `IRIS` 3. 将 webhook URL 复制到 `.env` 文件中的 `TEAMS_WEBHOOK_URL` ### Notion 1. 访问 `https://www.notion.so/profile/integrations` → **New integration** 2. 创建一个数据库,包含列:`Name` (title)、`Severity` (select)、`Status` (select)、`Repository` (text) 3. 通过 **Connections** 将您的集成连接到该数据库 4. 将 token 复制到 `NOTION_TOKEN`,将数据库 ID 复制到 `NOTION_DATABASE_ID` ## 无集成运行 IRIS 可以在没有任何 API token 的情况下完全运行。GitHub 提交会回退到逼真的演示数据,Teams/Notion 操作则会记录到控制台。使用仪表板上的 **Simulate Failure** 按钮即可端到端触发完整流程,无需任何外部账户。 ## 项目结构 ``` src/main/ ├── java/com/accenture/iris/ │ ├── start/ │ │ ├── MainApp.java ← entry point, schema init │ │ └── DbAccess.java ← static Spring JDBC accessor │ └── functions/ ← all composable @PreLoad functions └── resources/ ├── flows/ ← Mercury YAML flow definitions │ ├── incident-triggered.yml │ ├── simulate-failure.yml │ ├── resolve-incident.yml │ ├── list-incidents.yml │ └── get-incident.yml ├── flows.yaml ← flow index ├── rest.yaml ← REST endpoint configuration ├── cron.yaml ← scheduled health check ├── application.properties └── public/ └── index.html ← dashboard UI ``` ## 许可证 Apache 2.0
标签:GitHub Actions, Mercury框架, Microsoft Teams, Notion集成, Webhook, YAML, 严重性评估, 事故管理, 健康检查, 力导向图, 告警通知, 域名枚举, 安全库, 实时仪表盘, 工作流自动化, 并行处理, 故障定级, 智能运维, 测试用例, 监控告警, 自动化编排, 自动笔记, 自托管平台