This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch integte-extern-alarm
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git

commit c55e91054408d1a7ec06812068c3e4f306b8a7b7
Author: tomsun28 <[email protected]>
AuthorDate: Fri Jan 10 23:17:19 2025 +0800

    [improve] init
    
    Signed-off-by: tomsun28 <[email protected]>
---
 .../alert-integration.component.ts                 | 13 ++--
 .../{webhook.en-US.md => alertmanager.en-US.md}    |  0
 .../doc/alert-integration/alertmanager.zh-CN.md    | 44 ++++++++++++
 .../doc/alert-integration/alertmanager.zh-TW.md    |  0
 .../doc/alert-integration/prometheus.zh-CN.md      | 83 ++++++++++++++++------
 .../assets/doc/alert-integration/webhook.en-US.md  | 53 ++++++++++++--
 .../assets/doc/alert-integration/webhook.zh-CN.md  | 81 +++++++++++++++------
 web-app/src/assets/i18n/zh-CN.json                 |  1 +
 8 files changed, 224 insertions(+), 51 deletions(-)

diff --git 
a/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts 
b/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts
index 0a4802b007..aef7601346 100644
--- 
a/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts
+++ 
b/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts
@@ -35,10 +35,15 @@ export class AlertIntegrationComponent implements OnInit {
       icon: 'assets/img/integration/prometheus.svg'
     },
     {
-      id: 'tencent',
-      name: this.i18nSvc.fanyi('alert.integration.source.tencent'),
-      icon: 'assets/img/integration/tencent.svg'
-    }
+      id: 'alertmanager',
+      name: this.i18nSvc.fanyi('alert.integration.source.alertmanager'),
+      icon: 'assets/img/integration/prometheus.svg'
+    },
+    // {
+    //   id: 'tencent',
+    //   name: this.i18nSvc.fanyi('alert.integration.source.tencent'),
+    //   icon: 'assets/img/integration/tencent.svg'
+    // }
   ];
 
   selectedSource: DataSource | null = null;
diff --git a/web-app/src/assets/doc/alert-integration/webhook.en-US.md 
b/web-app/src/assets/doc/alert-integration/alertmanager.en-US.md
similarity index 100%
copy from web-app/src/assets/doc/alert-integration/webhook.en-US.md
copy to web-app/src/assets/doc/alert-integration/alertmanager.en-US.md
diff --git a/web-app/src/assets/doc/alert-integration/alertmanager.zh-CN.md 
b/web-app/src/assets/doc/alert-integration/alertmanager.zh-CN.md
new file mode 100644
index 0000000000..a345e69d4f
--- /dev/null
+++ b/web-app/src/assets/doc/alert-integration/alertmanager.zh-CN.md
@@ -0,0 +1,44 @@
+> 将 Prometheus AlertManager 的告警发送到 HertzBeat 告警平台。 
+
+### Alertmanager 配置 Webhook
+
+1. 在 Alertmanager 配置文件中添加 webhook 配置。
+
+    ```yaml
+    receivers:
+      - name: 'webhook'
+        webhook_configs:
+          - url: 'http://${hertzbeat_host}:1157/api/alerts/report/alertmanager'
+            http_config:
+              headers:
+              Authorization: 'Bearer {token}'
+            send_resolved: true
+    ```
+- `http://${hertzbeat_ip}:8080/api/alerts/report` 为 HertzBeat 提供的 webhook 接口地址。
+- `send_resolved: true` 表示发送告警恢复信息。
+- `Authorization` 内的 {token} 为 HertzBeat 提供的 token。
+
+2. 重启 Alertmanager 服务。
+
+### 配置验证
+
+- 触发 Prometheus AlertManager 告警。
+- 在 HertzBeat 告警平台中对告警数据处理查看,验证告警数据是否正确。
+
+### 数据流转:
+
+```mermaid
+graph LR
+    A[Prometheus Alertmanager] --> B[Webhook]
+    B --> C[HertzBeat告警平台]
+    C --> D[分组收敛]
+    D --> E[告警抑制]
+    E --> F[告警静默]
+    F --> G[告警中心]
+    F --> H[消息分发]
+```
+
+### 常见问题
+
+- 确保 Alertmanager 配置文件中的 webhook 地址正确,且网络通畅。
+- 检查 Alertmanager 的告警是否触发,是否发送到 HertzBeat 告警平台。
diff --git a/web-app/src/assets/doc/alert-integration/alertmanager.zh-TW.md 
b/web-app/src/assets/doc/alert-integration/alertmanager.zh-TW.md
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/web-app/src/assets/doc/alert-integration/prometheus.zh-CN.md 
b/web-app/src/assets/doc/alert-integration/prometheus.zh-CN.md
index 50880bd187..8ae23270d2 100644
--- a/web-app/src/assets/doc/alert-integration/prometheus.zh-CN.md
+++ b/web-app/src/assets/doc/alert-integration/prometheus.zh-CN.md
@@ -1,32 +1,69 @@
-## 告警字段說明
+> 由于 Prometheus Server 本身并不支持 HTTP API 的告警发送,因此需要借助外部脚本或者 Alertmanager 
来实现告警发送。  
+> 若使用 Alertmanager,可参考 **Alertmanager 集成文档**。这里提供非部署 Alertmanager 的 Prometheus 
Server 的告警配置方法。
 
-- `alert`: 告警規則名稱
-- `expr`: 告警觸發條件表達式
-- `for`: 告警持續時間閾值
-- `labels`: 告警標籤
-  - `severity`: 告警級別 (warning, critical)
-- `annotations`: 告警註釋信息
-  - `summary`: 告警摘要
-  - `description`: 告警詳細描述
+### Prometheus 告警配置
 
-## 驗證配置
+1. 編輯 Prometheus 配置文件 `prometheus.yml`,添加告警規則配置
+    ```yaml
+    rule_files:
+      - "rules/*.rules.yml"
+    ```
+    > `rules/*.rules.yml` 為告警規則文件路徑,可以根據實際情況修改
+> 2. 創建告警規則文件夾 `rules`,並創建告警規則文件 `rules/*.rules.yml`
+> 3. 編輯告警規則文件,添加告警規則配置
+> 4. 重新加載 Prometheus 配置
 
-1. 確保 Prometheus 配置正確並重新加載配置
-   ```bash
-   curl -X POST http://localhost:9090/-/reload
-   ```
+### 编写脚本自动发送告警
 
-2. 檢查 Prometheus 告警規則狀態
-   ```bash
-   curl http://localhost:9090/api/v1/rules
-   ```
+> 由于 Prometheus Server 本身并不支持 HTTP API 的告警发送,这里我们使用 Python 脚本来实现告警发送。
 
-3. 觸發測試告警並在 HertzBeat 告警中心查看
+1. 安装 Python requests 库
+    ```bash
+    pip install requests
+    ```
+2. 编写 Python 脚本 `send_alerts.py`
+```python
+import requests
 
-## 常見問題
+PROMETHEUS_URL = "http://<prometheus-host>:9090/api/v1/alerts"
+WEBHOOK_URL = "http://<hertzbeat-host>:1157/api/alerts/report/prometheus"
 
-1. 確保 HertzBeat URL 可以被 Prometheus 服務器訪問
-2. 檢查 Prometheus 日誌中是否有告警發送失敗的錯誤信息
-3. 驗證告警規則表達式的正確性
+def get_prometheus_alerts():
+    response = requests.get(PROMETHEUS_URL)
+    alerts = response.json()["data"]["alerts"]
+    return alerts
+
+def send_to_webhook(alert):
+    requests.post(WEBHOOK_URL, json=alert)
+
+if __name__ == "__main__":
+    alerts = get_prometheus_alerts()
+    for alert in alerts:
+        send_to_webhook(alert)
+        
+```
+3. 运行 Python 脚本
+    ```bash
+    python send_alerts.py
+    ```
+    > 该脚本会从 Prometheus Server 获取告警数据,并通过 Webhook 推送到 HertzBeat 告警平台。
+
+## 验证配置
+
+1. 确保 Prometheus 配置正确并重新加载配置
+    ```bash
+    curl -X POST http://localhost:9090/-/reload
+    ```
+2. 检查 Prometheus 告警规则状态
+    ```bash
+    curl http://localhost:9090/api/v1/rules
+    ```
+3. 触发测试告警并在 HertzBeat 告警中心查看
+
+## 常见问题
+
+- 确保 HertzBeat URL 可以被 Prometheus 服务器访问
+- 检查 Prometheus 日志中是否有告警发送失败的错误信息
+- 验证告警规则表达式的正确性
 
 更多信息請參考 [Prometheus 
告警配置文檔](https://prometheus.io/docs/alerting/latest/configuration/)
diff --git a/web-app/src/assets/doc/alert-integration/webhook.en-US.md 
b/web-app/src/assets/doc/alert-integration/webhook.en-US.md
index b876d8a96d..d80c736cde 100644
--- a/web-app/src/assets/doc/alert-integration/webhook.en-US.md
+++ b/web-app/src/assets/doc/alert-integration/webhook.en-US.md
@@ -1,7 +1,52 @@
-# Prometheus Alert Integration
+HertzBeat provides an external API interface that allows external systems to 
push alert data to the HertzBeat alert platform via Webhook.
 
-HertzBeat is fully compatible with Prometheus alert data format. You can 
configure Prometheus alerting rules to send alerts to HertzBeat.
+---
 
-## Prometheus Alert Configuration
+### API Endpoint
 
-Add the following configuration to your Prometheus configuration file:
+`POST /api/alerts/report`
+
+---
+
+### Request Headers
+
+- `Content-Type`: `application/json`
+- `Authorization`: `Bearer ${token}`
+
+---
+
+### Request Body
+
+```json
+{
+  "labels": {
+    "alertname": "HighCPUUsage",
+    "priority": "critical",
+    "instance": "343483943"
+  },
+  "annotations": {
+    "summary": "High CPU usage detected"
+  },
+  "content": "The CPU usage on instance 343483943 is critically high.",
+  "status": "firing",
+  "triggerTimes": 3,
+  "startAt": "2025-01-10T12:00:00.000Z",
+  "activeAt": "2025-01-10T12:05:00.000Z",
+  "endAt": null
+}
+```
+
+Field Description
+•      labels: Alert labels
+•      alertname: Name of the alert rule
+•      priority: Alert priority (warning, critical)
+•      instance: Alert instance
+•      annotations: Alert annotation information
+•      summary: Alert summary
+•      description: Detailed description of the alert
+•      content: Alert content
+•      status: Alert status (firing, resolved)
+•      triggerTimes: Number of times the alert was triggered
+•      startAt: Start time of the alert
+•      activeAt: Time when the alert became active
+•      endAt: End time of the alert (if resolved)
diff --git a/web-app/src/assets/doc/alert-integration/webhook.zh-CN.md 
b/web-app/src/assets/doc/alert-integration/webhook.zh-CN.md
index 50880bd187..ecc9d13abe 100644
--- a/web-app/src/assets/doc/alert-integration/webhook.zh-CN.md
+++ b/web-app/src/assets/doc/alert-integration/webhook.zh-CN.md
@@ -1,32 +1,73 @@
-## 告警字段說明
+> HertzBeat 对外提供 api 接口,外部系统可以通过 Webhook 方式调用此接口将告警数据推送到 HertzBeat 告警平台。
+
+### 接口端点
+
+`POST /api/alerts/report`
+
+### 请求头
+
+- `Content-Type`: `application/json`
+- `Authorization`: `Bearer ${token}`
+
+### 请求体
+
+```json
+{
+  "labels": {
+    "alertname": "HighCPUUsage",
+    "priority": "critical",
+    "instance": "343483943"
+  },
+  "annotations": {
+    "summary": "High CPU usage detected"
+  },
+  "content": "The CPU usage on instance 343483943 is critically high.",
+  "status": "firing",
+  "triggerTimes": 3,
+  "startAt": "2025-01-10T12:00:00.000Z",
+  "activeAt": "2025-01-10T12:05:00.000Z",
+  "endAt": null
+}
+```
+
+字段說明
 
-- `alert`: 告警規則名稱
-- `expr`: 告警觸發條件表達式
-- `for`: 告警持續時間閾值
 - `labels`: 告警標籤
-  - `severity`: 告警級別 (warning, critical)
+  - `alertname`: 告警規則名稱
+  - `priority`: 告警級別 (warning, critical)
+  - `instance`: 告警實例
 - `annotations`: 告警註釋信息
   - `summary`: 告警摘要
   - `description`: 告警詳細描述
+- `content`: 告警內容
+- `status`: 告警狀態 (firing, resolved)
+- `triggerTimes`: 告警觸發次數
+- `startAt`: 告警開始時間
+- `activeAt`: 告警激活時間
+- `endAt`: 告警結束時間
+
+
+### 配置验证
 
-## 驗證配置
+- 第三方系统触发告警后通过 webhook 回调 HertzBeat 的 `/api/alerts/report` 接口,将告警数据推送到 
HertzBeat 告警平台。 
+- 在 HertzBeat 告警平台中对告警数据处理查看,验证告警数据是否正确。
 
-1. 確保 Prometheus 配置正確並重新加載配置
-   ```bash
-   curl -X POST http://localhost:9090/-/reload
-   ```
 
-2. 檢查 Prometheus 告警規則狀態
-   ```bash
-   curl http://localhost:9090/api/v1/rules
-   ```
+### 数据流转:
 
-3. 觸發測試告警並在 HertzBeat 告警中心查看
+```mermaid
+graph LR
+    A[外部系统告警] --> B[Webhook]
+    B --> C[HertzBeat告警平台]
+    C --> D[分组收敛]
+    D --> E[告警抑制]
+    E --> F[告警静默]
+    F --> G[告警中心]
+    F --> H[消息分发]
+```
 
-## 常見問題
 
-1. 確保 HertzBeat URL 可以被 Prometheus 服務器訪問
-2. 檢查 Prometheus 日誌中是否有告警發送失敗的錯誤信息
-3. 驗證告警規則表達式的正確性
+### 常见问题
 
-更多信息請參考 [Prometheus 
告警配置文檔](https://prometheus.io/docs/alerting/latest/configuration/)
+- 确保 HertzBeat URL 可以被第三方系统服务器访问。 
+- 检查第三方系统日志中是否有告警发送成功失败的消息。
diff --git a/web-app/src/assets/i18n/zh-CN.json 
b/web-app/src/assets/i18n/zh-CN.json
index 5320cecaa1..b65bfa25bd 100644
--- a/web-app/src/assets/i18n/zh-CN.json
+++ b/web-app/src/assets/i18n/zh-CN.json
@@ -382,6 +382,7 @@
   "alert.integration.source": "集成告警源",
   "alert.integration.source.webhook": "默认Webhook",
   "alert.integration.source.prometheus": "Prometheus",
+  "alert.integration.source.alertmanager": "Alertmanager",
   "alert.integration.source.tencent": "腾讯云监控",
   "dashboard.alerts.title": "最近告警列表",
   "dashboard.alerts.title-no": "最近未处理告警",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to