Update: Add multi-channel support via tags
This commit is contained in:
parent
ab9a800785
commit
d5344e244e
@ -40,6 +40,7 @@ id: INTEGER PRIMARY KEY
|
||||
name: TEXT NOT NULL -- 通道名称,如 "告警群"
|
||||
type: TEXT NOT NULL -- apprise 协议,如 "discord", "telegram"
|
||||
config: JSON -- 配置参数(URL、token 等)
|
||||
tags: JSON DEFAULT [] -- 标签,如 ["alerts", "production"]
|
||||
is_active: BOOLEAN DEFAULT 1
|
||||
created_at: TIMESTAMP
|
||||
updated_at: TIMESTAMP
|
||||
@ -68,8 +69,8 @@ variables: JSON
|
||||
```
|
||||
|
||||
### 核心功能
|
||||
1. **通道管理**: 增删改查通知通道
|
||||
2. **发送通知**: POST /api/notify 接收通知请求
|
||||
1. **通道管理**: 增删改查通知通道,支持标签分类
|
||||
2. **发送通知**: POST /api/notify 支持批量发送到多个通道或按标签发送
|
||||
3. **历史记录**: 查看发送历史和统计
|
||||
4. **手动发送**: Web 界面手动触发通知
|
||||
|
||||
|
||||
@ -68,11 +68,14 @@ class Channel(Base):
|
||||
name = Column(String, nullable=False, unique=True) # 通道名称,如 "告警群"
|
||||
type = Column(String, nullable=False) # apprise 协议,如 "discord"
|
||||
config = Column(JSON, nullable=False) # 配置参数
|
||||
tags = Column(JSON, default=list) # 标签,如 ["alerts", "urgent"]
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
```
|
||||
|
||||
**tags 字段示例**: `["production", "alerts", "discord"]` - 用于批量选择通道
|
||||
|
||||
**config 字段示例**:
|
||||
```json
|
||||
{
|
||||
@ -132,25 +135,45 @@ class Template(Base):
|
||||
### 4.1 通知发送 API
|
||||
|
||||
#### POST /api/notify
|
||||
发送通知到指定通道。
|
||||
发送通知到指定通道(支持批量发送)。
|
||||
|
||||
**请求体**:
|
||||
```json
|
||||
{
|
||||
"channel": "告警群", // 通道名称或 ID
|
||||
"title": "服务器告警", // 可选
|
||||
"channels": ["告警群", "运维群"], // 通道名称列表(与 tags 二选一)
|
||||
"tags": ["alerts", "production"], // 标签列表,发送到所有匹配的通道
|
||||
"title": "服务器告警", // 可选
|
||||
"body": "CPU 使用率超过 90%",
|
||||
"priority": "high" // 可选,默认 normal
|
||||
"priority": "high" // 可选,默认 normal
|
||||
}
|
||||
```
|
||||
|
||||
**说明**:
|
||||
- `channels` 和 `tags` 二选一,不能同时为空
|
||||
- 使用 `channels`: 精确指定通道名称列表
|
||||
- 使用 `tags`: 发送到包含任一标签的所有通道
|
||||
|
||||
**响应**:
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"notification_id": 123,
|
||||
"channel": "告警群",
|
||||
"status": "sent"
|
||||
"results": [
|
||||
{
|
||||
"channel": "告警群",
|
||||
"channel_id": 1,
|
||||
"status": "sent",
|
||||
"notification_id": 123
|
||||
},
|
||||
{
|
||||
"channel": "运维群",
|
||||
"channel_id": 2,
|
||||
"status": "sent",
|
||||
"notification_id": 124
|
||||
}
|
||||
],
|
||||
"total": 2,
|
||||
"sent": 2,
|
||||
"failed": 0
|
||||
}
|
||||
```
|
||||
|
||||
@ -159,7 +182,8 @@ class Template(Base):
|
||||
|
||||
**请求**:
|
||||
```
|
||||
GET /api/notify?channel=告警群&body=测试消息&priority=normal
|
||||
GET /api/notify?channels=告警群,运维群&body=测试消息&priority=normal
|
||||
GET /api/notify?tags=alerts,urgent&body=测试消息&priority=high
|
||||
```
|
||||
|
||||
### 4.2 通道管理 API
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user