This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new eb5e843251 [feat] Add webhook authentication support for alert
notifications (#3797)
eb5e843251 is described below
commit eb5e8432514b607733c2b107179ef313a9efed45
Author: TeAmo <[email protected]>
AuthorDate: Mon Nov 17 22:59:35 2025 +0800
[feat] Add webhook authentication support for alert notifications (#3797)
Co-authored-by: Sherlock Yin <[email protected]>
Co-authored-by: yunfan24 <[email protected]>
Co-authored-by: aias00 <[email protected]>
Co-authored-by: Calvin <[email protected]>
Co-authored-by: kangli <[email protected]>
Co-authored-by: 刘俊辉 <[email protected]>
---
.../notice/impl/WebHookAlertNotifyHandlerImpl.java | 5 ++++
.../common/entity/alerter/NoticeReceiver.java | 14 +++++++++
web-app/src/app/pojo/NoticeReceiver.ts | 2 ++
.../alert-notice-receiver.component.html | 33 ++++++++++++++++++++++
.../alert-notice-receiver.component.ts | 1 +
web-app/src/assets/i18n/en-US.json | 3 ++
web-app/src/assets/i18n/zh-CN.json | 3 ++
7 files changed, 61 insertions(+)
diff --git
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/notice/impl/WebHookAlertNotifyHandlerImpl.java
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/notice/impl/WebHookAlertNotifyHandlerImpl.java
index cb90b4909a..8d601776f5 100644
---
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/notice/impl/WebHookAlertNotifyHandlerImpl.java
+++
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/notice/impl/WebHookAlertNotifyHandlerImpl.java
@@ -48,6 +48,11 @@ final class WebHookAlertNotifyHandlerImpl extends
AbstractAlertNotifyHandlerImpl
}
HttpHeaders headers = new HttpHeaders();
+ if ("Basic".equalsIgnoreCase(receiver.getHookAuthType())) {
+ headers.setBasicAuth(receiver.getHookAuthToken());
+ } else if ("Bearer".equalsIgnoreCase(receiver.getHookAuthType())) {
+ headers.setBearerAuth(receiver.getHookAuthToken());
+ }
headers.setContentType(MediaType.APPLICATION_JSON);
// alert.setContent(escapeJsonStr(alert.getContent()));
String webhookJson = renderContent(noticeTemplate, alert);
diff --git
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/alerter/NoticeReceiver.java
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/alerter/NoticeReceiver.java
index 328665e3f1..a33c6b9d1b 100644
---
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/alerter/NoticeReceiver.java
+++
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/alerter/NoticeReceiver.java
@@ -98,6 +98,20 @@ public class NoticeReceiver {
@Column(length = 1000)
private String hookUrl;
+ @Schema(title = "Auth Type: WebHook Authorization Type",
+ description = "Auth Type: WebHook Authorization Type, one of the
'None', 'Basic' and 'Bearer'",
+ example = "None", accessMode = READ_ONLY)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String hookAuthType;
+
+ @Schema(title = "Auth Token: WebHook Authorization Token",
+ description = "Auth Token: WebHook Authorization Token",
+ example = "YWxpY2U6c3VwZXJtYW4", accessMode = READ_WRITE)
+ @Size(max = 300)
+ @Column(length = 300)
+ private String hookAuthToken;
+
@Schema(title = "openId : The notification method is valid for WeChat
official account, enterprise WeChat robot or FlyBook robot",
description = "openId : The notification method is valid for
WeChat official account, enterprise WeChat robot or FlyBook robot",
example = "343432", accessMode = READ_WRITE)
diff --git a/web-app/src/app/pojo/NoticeReceiver.ts
b/web-app/src/app/pojo/NoticeReceiver.ts
index 99244cb2ca..cbd38ab280 100644
--- a/web-app/src/app/pojo/NoticeReceiver.ts
+++ b/web-app/src/app/pojo/NoticeReceiver.ts
@@ -33,6 +33,8 @@ export class NoticeReceiver {
discordChannelId!: string;
discordBotToken!: string;
hookUrl!: string;
+ hookAuthType!: string;
+ hookAuthToken!: string;
wechatId!: string;
accessToken!: string;
corpId!: string;
diff --git
a/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.html
b/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.html
index ab245b5f1e..374199b60d 100644
---
a/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.html
+++
b/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.html
@@ -245,6 +245,39 @@
<input [(ngModel)]="receiver.hookUrl" [required]="receiver.type ===
2" id="hookUrl" name="hookUrl" nz-input type="url" />
</nz-form-control>
</nz-form-item>
+ <nz-form-item *ngIf="receiver.type === 2">
+ <nz-form-label [nzSpan]="7" nzFor="hookAuthType">{{
'alert.notice.type.webhook-auth-type' | i18n }} </nz-form-label>
+ <nz-form-control [nzSpan]="12">
+ <nz-select
+ [(ngModel)]="receiver.hookAuthType"
+ id="hookAuthType"
+ name="hookAuthType"
+ nzPlaceHolder="{{
'alert.notice.type.webhook-auth-type.placeholder' | i18n }}"
+ >
+ <nz-option nzValue="None" nzLabel="None"></nz-option>
+ <nz-option nzValue="Basic" nzLabel="Basic"></nz-option>
+ <nz-option nzValue="Bearer" nzLabel="Bearer"></nz-option>
+ </nz-select>
+ </nz-form-control>
+ </nz-form-item>
+ <nz-form-item *ngIf="receiver.type === 2 && (receiver.hookAuthType ===
'Basic' || receiver.hookAuthType === 'Bearer')">
+ <nz-form-label
+ [nzRequired]="receiver.hookAuthType === 'Basic' ||
receiver.hookAuthType === 'Bearer'"
+ [nzSpan]="7"
+ nzFor="hookAuthToken"
+ >{{ 'alert.notice.type.webhook-auth-token' | i18n }}
+ </nz-form-label>
+ <nz-form-control [nzErrorTip]="'validation.required' | i18n"
[nzSpan]="12">
+ <input
+ [(ngModel)]="receiver.hookAuthToken"
+ [required]="receiver.hookAuthType === 'Basic' ||
receiver.hookAuthType === 'Bearer'"
+ id="hookAuthToken"
+ name="hookAuthToken"
+ nz-input
+ type="text"
+ />
+ </nz-form-control>
+ </nz-form-item>
<nz-form-item *ngIf="receiver.type === 3">
<nz-form-label [nzRequired]="receiver.type === 3" [nzSpan]="7"
nzFor="wechatId"
>{{ 'alert.notice.type.wechat-id' | i18n }}
diff --git
a/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.ts
b/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.ts
index 150c7be4d3..c43cecb1e5 100644
---
a/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.ts
+++
b/web-app/src/app/routes/alert/alert-notice/alert-notice-receiver/alert-notice-receiver.component.ts
@@ -159,6 +159,7 @@ export class AlertNoticeReceiverComponent implements OnInit
{
onNewNoticeReceiver() {
this.receiver = new NoticeReceiver();
+ this.receiver.hookAuthType = 'None';
this.isManageReceiverModalVisible = true;
this.isManageReceiverModalAdd = true;
}
diff --git a/web-app/src/assets/i18n/en-US.json
b/web-app/src/assets/i18n/en-US.json
index 0948405e12..e82d6992b2 100644
--- a/web-app/src/assets/i18n/en-US.json
+++ b/web-app/src/assets/i18n/en-US.json
@@ -226,6 +226,9 @@
"alert.notice.type.userId": "User ID",
"alert.notice.type.wechat": "Open WeChat",
"alert.notice.type.wechat-id": "WeChat OPENID",
+ "alert.notice.type.webhook-auth-type": "Auth Type",
+ "alert.notice.type.webhook-auth-type.placeholder": "Select Auth Type",
+ "alert.notice.type.webhook-auth-token": "Auth Token",
"alert.notify.title": "New Alert",
"alert.notify.body": "You have a new alert, please handle it in time",
"alert.setting.bind.available": "Available Monitors",
diff --git a/web-app/src/assets/i18n/zh-CN.json
b/web-app/src/assets/i18n/zh-CN.json
index a1378f0b62..e1f531b12c 100644
--- a/web-app/src/assets/i18n/zh-CN.json
+++ b/web-app/src/assets/i18n/zh-CN.json
@@ -226,6 +226,9 @@
"alert.notice.type.userId": "用户ID",
"alert.notice.type.wechat": "微信公众号",
"alert.notice.type.wechat-id": "微信OPENID",
+ "alert.notice.type.webhook-auth-type": "认证类型",
+ "alert.notice.type.webhook-auth-type.placeholder": "选择认证类型",
+ "alert.notice.type.webhook-auth-token": "认证Token",
"alert.notify.title": "新告警通知",
"alert.notify.body": "您有一条新的告警,请及时处理!",
"alert.setting.bind.available": "可选监控",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]