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 ba03927dfd8b78718332873c34921be3601e7c3c Author: tomsun28 <tomsu...@outlook.com> AuthorDate: Fri Jan 10 23:42:16 2025 +0800 [webapp] add alert integration Signed-off-by: tomsun28 <tomsu...@outlook.com> --- .../alert-integration.component.ts | 6 +- .../doc/alert-integration/alertmanager.en-US.md | 2 + .../doc/alert-integration/alertmanager.zh-TW.md | 44 ++++++++++++++ .../doc/alert-integration/prometheus.en-US.md | 70 +++++++++++++++++++++- .../doc/alert-integration/prometheus.zh-TW.md | 69 +++++++++++++++++++++ .../assets/doc/alert-integration/webhook.en-US.md | 58 +++++++++++------- .../assets/doc/alert-integration/webhook.zh-TW.md | 70 ++++++++++++++++++++++ 7 files changed, 295 insertions(+), 24 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 c424d1ff88..c06aaafecc 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 @@ -61,17 +61,17 @@ export class AlertIntegrationComponent implements OnInit { this.route.params.subscribe(params => { const sourceId = params['source']; if (sourceId) { - // 查找匹配的数据源 + // Find matching data source const source = this.dataSources.find(s => s.id === sourceId); if (source) { this.selectedSource = source; } else { - // 如果找不到匹配的数据源,使用第一个作为默认值 + // If no matching source found, use the first one as default this.selectedSource = this.dataSources[0]; this.router.navigate(['/alert/integration/', this.selectedSource.id]); } } else { - // 没有路由参数时使用第一个数据源 + // When no route params, use the first data source this.selectedSource = this.dataSources[0]; this.router.navigate(['/alert/integration/', this.selectedSource.id]); } diff --git a/web-app/src/assets/doc/alert-integration/alertmanager.en-US.md b/web-app/src/assets/doc/alert-integration/alertmanager.en-US.md index b876d8a96d..e3fcba8621 100644 --- a/web-app/src/assets/doc/alert-integration/alertmanager.en-US.md +++ b/web-app/src/assets/doc/alert-integration/alertmanager.en-US.md @@ -5,3 +5,5 @@ HertzBeat is fully compatible with Prometheus alert data format. You can configu ## Prometheus Alert Configuration Add the following configuration to your Prometheus configuration file: + +``` 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 index e69de29bb2..b7606af054 100644 --- a/web-app/src/assets/doc/alert-integration/alertmanager.zh-TW.md +++ b/web-app/src/assets/doc/alert-integration/alertmanager.zh-TW.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/prometheus.en-US.md b/web-app/src/assets/doc/alert-integration/prometheus.en-US.md index b876d8a96d..82f7f2bffc 100644 --- a/web-app/src/assets/doc/alert-integration/prometheus.en-US.md +++ b/web-app/src/assets/doc/alert-integration/prometheus.en-US.md @@ -4,4 +4,72 @@ HertzBeat is fully compatible with Prometheus alert data format. You can configu ## Prometheus Alert Configuration -Add the following configuration to your Prometheus configuration file: +> Since Prometheus Server itself doesn't support sending alerts via HTTP API, external scripts or Alertmanager are needed to implement alert sending. +> If using Alertmanager, please refer to the **Alertmanager Integration Documentation**. Here we provide the alert configuration method for Prometheus Server without deploying Alertmanager. + +### Prometheus Alert Configuration + +1. Edit Prometheus configuration file `prometheus.yml`, add alert rules configuration + ```yaml + rule_files: + - "rules/*.rules.yml" + ``` + > `rules/*.rules.yml` is the path to alert rule files, which can be modified according to actual situations +> 2. Create alert rules folder `rules` and create alert rule files `rules/*.rules.yml` +> 3. Edit alert rule files, add alert rule configurations +> 4. Reload Prometheus configuration + +### Write Scripts to Send Alerts Automatically + +> Since Prometheus Server itself doesn't support sending alerts via HTTP API, we'll use Python scripts to implement alert sending. + +1. Install Python requests library + ```bash + pip install requests + ``` +2. Write Python script `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" + +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. Run Python script + ```bash + python send_alerts.py + ``` + > This script will fetch alert data from Prometheus Server and push it to HertzBeat alert platform via Webhook. + +## Verify Configuration + +1. Ensure Prometheus configuration is correct and reload configuration + ```bash + curl -X POST http://localhost:9090/-/reload + ``` +2. Check Prometheus alert rules status + ```bash + curl http://localhost:9090/api/v1/rules + ``` +3. Trigger test alerts and check in HertzBeat alert center + +## Common Issues + +- Ensure HertzBeat URL is accessible from Prometheus server +- Check Prometheus logs for alert sending failure error messages +- Verify the correctness of alert rule expressions + +For more information, please refer to [Prometheus Alerting Documentation](https://prometheus.io/docs/alerting/latest/configuration/) diff --git a/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md b/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md index e69de29bb2..d0da7ec7dc 100644 --- a/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md +++ b/web-app/src/assets/doc/alert-integration/prometheus.zh-TW.md @@ -0,0 +1,69 @@ +> 由於 Prometheus Server 本身並不支持 HTTP API 的告警發送,因此需要借助外部腳本或者 Alertmanager 來實現告警發送。 +> 若使用 Alertmanager,可參考 **Alertmanager 集成文檔**。這裡提供非部署 Alertmanager 的 Prometheus Server 的告警配置方法。 + +### Prometheus 告警配置 + +1. 編輯 Prometheus 配置文件 `prometheus.yml`,添加告警規則配置 + ```yaml + rule_files: + - "rules/*.rules.yml" + ``` + > `rules/*.rules.yml` 為告警規則文件路徑,可以根據實際情況修改 +> 2. 創建告警規則文件夾 `rules`,並創建告警規則文件 `rules/*.rules.yml` +> 3. 編輯告警規則文件,添加告警規則配置 +> 4. 重新加載 Prometheus 配置 + +### 編寫腳本自動發送告警 + +> 由於 Prometheus Server 本身並不支持 HTTP API 的告警發送,這裡我們使用 Python 腳本來實現告警發送。 + +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" + +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 d80c736cde..460ee25736 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,20 +1,14 @@ -HertzBeat provides an external API interface that allows external systems to push alert data to the HertzBeat alert platform via Webhook. - ---- +> HertzBeat provides an external API interface that allows external systems to push alert data to the HertzBeat alert platform via Webhook. ### API Endpoint `POST /api/alerts/report` ---- - ### Request Headers - `Content-Type`: `application/json` - `Authorization`: `Bearer ${token}` ---- - ### Request Body ```json @@ -37,16 +31,40 @@ HertzBeat provides an external API interface that allows external systems to pus ``` 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) + +- `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) + +### Configuration Verification + +- After the third-party system triggers an alert, it calls HertzBeat's `/api/alerts/report` interface via webhook to push alert data to the HertzBeat alert platform. +- Check the alert data processing in the HertzBeat alert platform to verify if the alert data is correct. + +### Data Flow: + +```mermaid +graph LR + A[External System Alert] --> B[Webhook] + B --> C[HertzBeat Alert Platform] + C --> D[Group Convergence] + D --> E[Alert Suppression] + E --> F[Alert Silence] + F --> G[Alert Center] + F --> H[Message Distribution] +``` + +### Common Issues + +- Ensure the HertzBeat URL is accessible from the third-party system server. +- Check the logs of the third-party system for messages indicating whether the alert was successfully sent or failed. diff --git a/web-app/src/assets/doc/alert-integration/webhook.zh-TW.md b/web-app/src/assets/doc/alert-integration/webhook.zh-TW.md index e69de29bb2..12c7e95afd 100644 --- a/web-app/src/assets/doc/alert-integration/webhook.zh-TW.md +++ b/web-app/src/assets/doc/alert-integration/webhook.zh-TW.md @@ -0,0 +1,70 @@ +> 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": "檢測到高 CPU 使用率" + }, + "content": "實例 343483943 的 CPU 使用率極高。", + "status": "firing", + "triggerTimes": 3, + "startAt": "2025-01-10T12:00:00.000Z", + "activeAt": "2025-01-10T12:05:00.000Z", + "endAt": null +} +``` + +字段說明 + +- `labels`: 告警標籤 + - `alertname`: 告警規則名稱 + - `priority`: 告警級別 (warning, critical) + - `instance`: 告警實例 +- `annotations`: 告警註釋信息 + - `summary`: 告警摘要 + - `description`: 告警詳細描述 +- `content`: 告警內容 +- `status`: 告警狀態 (firing, resolved) +- `triggerTimes`: 告警觸發次數 +- `startAt`: 告警開始時間 +- `activeAt`: 告警激活時間 +- `endAt`: 告警結束時間 + +### 配置驗證 + +- 第三方系統觸發告警後通過 webhook 回調 HertzBeat 的 `/api/alerts/report` 接口,將告警數據推送到 HertzBeat 告警平台。 +- 在 HertzBeat 告警平台中對告警數據處理查看,驗證告警數據是否正確。 + +### 數據流轉: + +```mermaid +graph LR + A[外部系統告警] --> B[Webhook] + B --> C[HertzBeat告警平台] + C --> D[分組收斂] + D --> E[告警抑制] + E --> F[告警靜默] + F --> G[告警中心] + F --> H[消息分發] +``` + +### 常見問題 + +- 確保 HertzBeat URL 可以被第三方系統服務器訪問。 +- 檢查第三方系統日誌中是否有告警發送成功失敗的消息。 --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org For additional commands, e-mail: notifications-h...@hertzbeat.apache.org