dsnow121/ir-bot
GitHub: dsnow121/ir-bot
一个将 Slack 与 Google Workspace 打通的轻量级事件响应编排机器人,用一条命令自动完成建群、文档、会议、通知全流程。
Stars: 0 | Forks: 0
# IR Bot — Slack 事件响应编排
用于自动化事件响应启动的 Slack bot。只需一条斜杠命令即可启动整个事件工作区:专属频道、格式化的 Google Doc、附带 Meet 链接的作战室日历邀请、值班呼叫以及跨频道公告。
## 功能
`/incident` 打开一个模态框以收集事件详情,然后自动执行以下操作:
1. **创建 Slack 频道** — `#inc-YYYYMMDD-title`(公开或私有)
2. **创建 Google Doc** — 格式化的事件模板,包含时间线表格、IOC 表格、行动项和复盘章节
3. **创建 Google Calendar 事件** — 包含 Google Meet 链接的作战室邀请,5 分钟后开始
4. **发布事件简报** — 严重程度、INC 编号、摘要和响应检查清单发送到新频道
5. **呼叫值班响应人员** — 向值班用户发送 DM 并自动邀请其加入频道(仅限 P1/P2)
6. **在 #security-alerts 中公告** — 跨帖事件通知
### 其他命令
- `/oncall set|add|remove|clear|show` — 管理值班名单
- `/incident acl set|add|remove|clear|show` — 控制谁可以发起事件
## 技术栈
- Python (Flask + slack-bolt)
- Google Docs API, Calendar API, Drive API (OAuth 2.0)
- 部署在 AWS EC2 上,使用 nginx 反向代理和 Let's Encrypt SSL
## 设置
### Slack App
在 [api.slack.com/apps](https://api.slack.com/apps) 创建一个 Slack app,并配置以下 bot token 权限范围:
- `channels:read`, `channels:join`, `channels:manage`
- `groups:write`, `groups:read`
- `chat:write`, `im:write`
- `users:read`
- `commands`
创建两个斜杠命令:
- `/incident` — Request URL: `https://your-domain/slack/incident`
- `/oncall` — Request URL: `https://your-domain/slack/oncall`
将 Interactivity Request URL 设置为:`https://your-domain/slack/interactions`
### Google Cloud
创建一个 Google Cloud 项目并启用以下 API:
- Google Docs API
- Google Drive API
- Google Calendar API
创建 OAuth 2.0 凭据(Desktop 应用类型),下载为 `google_credentials.json` 并放置在项目根目录。
首次运行时,将打开一个浏览器窗口进行 OAuth 授权。刷新令牌将保存到 `token.json` 以供后续运行使用。
### 3. 环境变量
```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
将 `.env.example` 复制为 `.env` 并填入你的 Slack 凭据:
```
cp .env.example .env
```
### 4. 运行
```
python app.py
```
应用运行在端口 5000。在生产环境中,请将其置于配置了 SSL 的 nginx 之后。
## 事件 Doc 模板
生成的 Google Doc 包含:
- 元数据块(严重程度、INC 编号、时间戳、频道链接)
- Incident Commander 分配章节
- 摘要
- 时间线表格(Time / Action / Notes)
- IOC 表格(IOC / Type / Description / Source / Notes)
- 行动项表格(Action / Owner / Status / Ticket / Notes)
- 复盘:影响范围、经验教训、五个为什么、根本原因
## 许可证
MIT
标签:AWS EC2, ChatOps, Flask, Google Calendar API, Google Docs API, Incident-Management, Nginx, On-Call管理, Python, slack-bolt, Slack机器人, Slash-Command, SRE, 值班管理, 偏差过滤, 协作工具, 安全事故处理, 库, 应急响应, 无后门, 编排工具, 自动化运维, 运维自动化, 逆向工具