brianturner005/Incident_Response
GitHub: brianturner005/Incident_Response
全栈ITSM事件响应Web应用程序,管理事件生命周期。
Stars: 0 | Forks: 0
# 事件响应工具
一个全栈 ITSM 事件响应 Web 应用程序,用于管理事件生命周期的完整流程——从检测到解决。使用 Node.js、TypeScript、React 和 SQLite 构建。
   
## 功能
### 事件管理
- **全生命周期跟踪** — `打开 → 调查 → 确定 → 监控 → 解决`
- **严重级别** — P1(严重),P2(高),P3(中等),P4(低)
- **分配人与标签跟踪** — 指定所有者和标签事件以进行过滤
- **审计时间线** — 每个状态更改、备注和集成事件都会自动记录
### SLA 跟踪
| 严重级别 | 响应 SLA | 解决 SLA |
|----------|-------------|----------------|
| P1 | 15 分钟 | 1 小时 |
| P2 | 30 分钟 | 4 小时 |
| P3 | 2 小时 | 24 小时 |
| P4 | 8 小时 | 72 小时 |
每个事件卡上的实时倒计时计时器在 SLA 被违反时变为红色。
### 集成
- **Slack** — 通过 Incoming Webhooks 创建、解决和升级 Block Kit 通知
- **Jira** — 创建 Jira 问题(与事件相关联)时自动创建
- **入站 Webhook** — 用于接收来自外部工具(Datadog、PagerDuty、自定义脚本等)的警报的通用 HTTP 端点
### 仪表板和实时更新
- 显示按严重性、SLA 违规次数和平均解决时间打开事件的度量条
- 服务器发送事件(SSE)使仪表板保持实时状态,无需轮询
- 通过标题、严重性和状态进行搜索和过滤
### 事后分析生成
一键 Markdown 事后分析模板,预先填写事件元数据、SLA 数据和完整时间线——准备好填写根本原因和行动项。
## 技术栈
| 层 | 技术 |
|-----------|-------------------------------------|
| 后端 | Node.js 22, TypeScript, Express 5 |
| 数据库 | SQLite (better-sqlite3),WAL 模式 |
| 前端 | React 19,Vite 6,Tailwind CSS v4 |
| 实时 | 服务器发送事件(SSE) |
| 图标 | Lucide React |
| 开发运行器| concurrently + tsx watch |
## 前置条件
- **Node.js** v18 或更高版本(推荐 v22)
- **npm** v9 或更高版本
## 安装
```
git clone https://github.com/brianturner005/Incident_Response.git
cd Incident_Response
npm install
```
## 配置
复制示例环境文件并填写您想要启用的任何集成。所有字段都是可选的——应用程序可以在不配置任何外部集成的情况下完全运行。
```
cp .env.example .env
```
```
PORT=3000
DATA_DIR=./data
# Slack 入站 Webhook (https://api.slack.com/messaging/webhooks)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
# Jira Cloud (https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/)
JIRA_BASE_URL=https://yourorg.atlassian.net
JIRA_EMAIL=you@yourorg.com
JIRA_API_TOKEN=your_api_token_here
JIRA_PROJECT_KEY=IT
```
您还可以通过 UI 中的 **设置** 页面配置集成,而无需重新启动服务器。
## 运行应用程序
### 开发
同时启动 Express 服务器(通过 `tsx watch` 进行热重载)和 Vite 开发服务器。Vite 服务器将 `/api` 请求代理到 Express。
```
npm run dev
```
- **App UI**: http://localhost:5173
- **API**: http://localhost:3000/api
### 生产
```
npm run build # compiles TypeScript + bundles React with Vite
npm start # serves everything from Express on port 3000
```
- **App**: http://localhost:3000
SQLite 数据库在首次运行时自动创建在 `./data/incidents.db`。
## API 参考
所有端点都以前缀 `/api` 开头。
### 事件
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| `POST` | `/incidents` | 创建事件。如果已配置,则触发 Slack + Jira。 |
| `GET` | `/incidents` | 列出事件。查询参数:`status`、`severity`、`search`。 |
| `GET` | `/incidents/:id` | 获取事件详情。 |
| `PATCH` | `/incidents/:id` | 更新标题、描述、严重性、状态、分配人或标签。 |
| `POST` | `/incidents/:id/resolve` | 标记为已解决。发送 Slack 通知。 |
| `POST` | `/incidents/:id/notes` | 将手动备注添加到时间线。 |
| `GET` | `/incidents/:id/timeline` | 获取完整的审计时间线。 |
| `POST` | `/incidents/:id/postmortem` | 生成事后分析 Markdown 模板。 |
**创建事件正文:**
```
{
"title": "Payments API returning 500s",
"description": "Error rate on /api/checkout exceeds 5%",
"severity": "P1",
"assignee": "alice",
"tags": "payments,api"
}
```
### 度量
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| `GET` | `/metrics` | 按严重性、SLA 违规次数和平均解决时间打开事件。 |
### 配置
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| `GET` | `/config` | 获取当前集成配置(令牌被屏蔽)。 |
| `PUT` | `/config` | 更新集成配置键值对。 |
| `POST` | `/config/test-slack` | 发送测试 Slack 消息。 |
| `POST` | `/config/test-jira` | 验证 Jira 凭据(ping `/rest/api/3/myself`)。 |
### 实时事件
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| `GET` | `/events` | SSE 流。发出 `incident_created`、`incident_updated`、`incident_resolved` 事件。 |
### 入站 Webhook
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| `POST` | `/webhooks/inbound` | 接收外部警报并自动创建事件。 |
**入站 Webhook 正文:**
```
{
"title": "High error rate detected",
"description": "P99 latency exceeded threshold on service-A",
"severity": "P2",
"source": "Datadog",
"tags": ["api", "latency"]
}
```
如果 `severity` 缺失或无效,则默认为 `P2`。`source` 值将添加到事件的标签中作为 `source:`。
## 项目结构
```
Incident_Response/
├── src/
│ ├── shared/
│ │ └── types.ts # Shared TypeScript types (Incident, TimelineEvent, SLA_TARGETS, etc.)
│ ├── server/
│ │ ├── index.ts # HTTP server entry point
│ │ ├── app.ts # Express app setup, route mounting, static file serving
│ │ ├── db/
│ │ │ └── index.ts # SQLite initialization, schema DDL, WAL mode, env seeding
│ │ ├── routes/
│ │ │ ├── incidents.ts # Incident CRUD, resolve, notes, timeline, post-mortem
│ │ │ ├── config.ts # Integration config read/write + test endpoints
│ │ │ ├── metrics.ts # Aggregated metrics endpoint
│ │ │ ├── webhooks.ts # Inbound alert ingestion
│ │ │ └── events.ts # SSE stream
│ │ └── services/
│ │ ├── incident.ts # Core business logic: CRUD, SLA computation, metrics
│ │ ├── slack.ts # Slack Incoming Webhook client (Block Kit)
│ │ ├── jira.ts # Jira REST API v3 client
│ │ ├── postmortem.ts # Post-mortem Markdown generator
│ │ └── eventBus.ts # In-process pub/sub for SSE fan-out
│ └── client/
│ ├── index.html
│ ├── main.tsx # React entry point
│ ├── App.tsx # Router and layout
│ ├── api.ts # Typed fetch wrappers for all API endpoints
│ ├── index.css # Tailwind CSS v4 import
│ ├── components/
│ │ ├── SeverityBadge.tsx # Color-coded P1/P2/P3/P4 badge
│ │ ├── StatusBadge.tsx # Status badge with lifecycle colors
│ │ ├── SLATimer.tsx # Live countdown/elapsed timer with breach detection
│ │ ├── IncidentCard.tsx # Dashboard list card
│ │ ├── IncidentForm.tsx # Create incident modal
│ │ ├── Timeline.tsx # Vertical audit event list
│ │ └── MetricsBar.tsx # Top-of-dashboard metrics summary
│ └── pages/
│ ├── Dashboard.tsx # Incident list, filters, metrics, SSE live updates
│ ├── IncidentDetail.tsx # Full detail view, actions, note-taking, post-mortem
│ └── Settings.tsx # Integration configuration and test connections
├── data/ # SQLite database (created at runtime, gitignored)
├── dist/ # Compiled output (gitignored)
├── .env.example # Environment variable template
├── tsconfig.json # Base TypeScript config
├── tsconfig.server.json # Server build (CommonJS, outputs to dist/)
├── tsconfig.client.json # Client TypeScript config (for IDE support)
├── vite.config.ts # Vite build config with /api proxy
└── package.json
```
## 集成设置指南
### Slack
1. 访问 [api.slack.com/apps](https://api.slack.com/apps) 并创建一个新的应用程序。
2. 启用 **入站 Webhooks** 并将 webhook 添加到您想要的频道。
3. 复制 webhook URL(以 `https://hooks.slack.com/services/...` 开头)。
4. 将其粘贴到 `.env` 作为 `SLACK_WEBHOOK_URL`,或在 **设置** 页面上输入。
5. 通知包括:
- 新事件创建(包含严重性、状态、描述和 Jira 链接(如果可用))
- 事件解决
- 严重性升级
### Jira
1. 登录您的 Atlassian 账户并转到 [id.atlassian.com/manage-profile/security/api-tokens](https://id.atlassian.com/manage-profile/security/api-tokens).
2. 创建 API 令牌。
3. 在 `.env`(或设置页面)中填写四个 Jira 字段:`JIRA_BASE_URL`、`JIRA_EMAIL`、`JIRA_API_TOKEN`、`JIRA_PROJECT_KEY`。
4. 使用 **测试连接** 在设置中验证,然后再上线。
当事件打开时,会自动创建 Jira 问题。问题与事件详情页面相关联。优先级映射:
| 事件严重级别 | Jira 优先级 |
|-------------------|---------------|
| P1 | 最高 |
| P2 | 高 |
| P3 | 中等 |
| P4 | 低 |
### 外部工具(入站 Webhook)
任何可以发送 HTTP POST 的工具都可以将警报推送到系统中。以下是用 `curl` 的示例:
```
curl -X POST http://localhost:3000/api/webhooks/inbound \
-H "Content-Type: application/json" \
-d '{
"title": "Disk usage > 90% on prod-db-01",
"severity": "P2",
"source": "Nagios",
"tags": ["database", "storage"]
}'
```
这是将此工具与其他监控套件中的工具结合的主要集成点。
## 扩展工具套件
此工具旨在成为更大 ITSM 套件的一部分。关键集成表面包括:
- **`POST /api/webhooks/inbound`** — 从任何监控工具、日志分析器或自定义脚本推送警报
- **`GET /api/events`** — 订阅 SSE 流以实时响应事件生命周期更改
- **`GET /api/incidents` + `GET /api/metrics`** — 查询事件状态以用于仪表板或报告工具
- **`src/shared/types.ts`** 中的 **共享类型** — 如果构建 TypeScript 伴随工具,则直接导入
## 许可证
MIT — 查看 [LICENSE](./LICENSE).
标签:GNU通用公共许可证, IT服务管理, Jira集成, Markdown模板, MITM代理, Node.js, React, Slack集成, SLA跟踪, SQLite, Syscalls, TypeScript, Webhook, 严重程度分级, 事后分析, 仪表盘, 全栈应用, 力导向图, 安全插件, 实时更新, 搜索过滤, 生命周期管理, 自动化攻击, 集成