This is an automated email from the ASF dual-hosted git repository.
tomsun28 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 e5462bf096 [alerter]bugfix: fix Gotify default webhook URL (#4350)
e5462bf096 is described below
commit e5462bf09634e9a63f4f1a79d1481749bfd8819b
Author: Tanay Paul <[email protected]>
AuthorDate: Mon Oct 5 07:40:57 2026 +0530
[alerter]bugfix: fix Gotify default webhook URL (#4350)
Co-authored-by: Tomsun28 <[email protected]>
---
.../apache/hertzbeat/alert/AlerterProperties.java | 2 +-
.../impl/GotifyAlertNotifyHandlerImplTest.java | 25 ++++++++++++++++++----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/AlerterProperties.java
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/AlerterProperties.java
index 022c75b4e1..d4e2fb9fb3 100644
---
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/AlerterProperties.java
+++
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/AlerterProperties.java
@@ -72,7 +72,7 @@ public class AlerterProperties {
/**
* Gotify Notify url
*/
- private String gotifyWebhookUrl = "https://push.example.de/message?token=";
+ private String gotifyWebhookUrl =
"https://push.example.de/message?token=%s";
/**
* Ntfy default server url
diff --git
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/notice/impl/GotifyAlertNotifyHandlerImplTest.java
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/notice/impl/GotifyAlertNotifyHandlerImplTest.java
index 1704f2fc31..1b0038bfcd 100644
---
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/notice/impl/GotifyAlertNotifyHandlerImplTest.java
+++
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/notice/impl/GotifyAlertNotifyHandlerImplTest.java
@@ -17,9 +17,11 @@
package org.apache.hertzbeat.alert.notice.impl;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.apache.hertzbeat.alert.AlerterProperties;
@@ -31,6 +33,7 @@ import org.apache.hertzbeat.alert.notice.AlertNoticeException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -70,7 +73,7 @@ class GotifyAlertNotifyHandlerImplTest {
receiver = new NoticeReceiver();
receiver.setId(1L);
receiver.setName("test-receiver");
- receiver.setAccessToken("test-token");
+ receiver.setGotifyToken("test-token");
groupAlert = new GroupAlert();
SingleAlert singleAlert = new SingleAlert();
@@ -86,13 +89,13 @@ class GotifyAlertNotifyHandlerImplTest {
template.setId(1L);
template.setName("test-template");
template.setContent("test content");
-
- when(bundle.getString("alerter.notify.title")).thenReturn("Alert
Notification");
-
when(alerterProperties.getGotifyWebhookUrl()).thenReturn("http://localhost:8080/gotify/%s");
}
@Test
public void testNotifyAlertSuccess() {
+ when(bundle.getString("alerter.notify.title")).thenReturn("Alert
Notification");
+
when(alerterProperties.getGotifyWebhookUrl()).thenReturn("http://localhost:8080/gotify/%s");
+
CommonRobotNotifyResp successResp = new CommonRobotNotifyResp();
successResp.setErrCode(0);
ResponseEntity<CommonRobotNotifyResp> responseEntity =
@@ -105,10 +108,17 @@ class GotifyAlertNotifyHandlerImplTest {
)).thenReturn(responseEntity);
gotifyAlertNotifyHandler.send(receiver, template, groupAlert);
+
+ ArgumentCaptor<String> urlCaptor =
ArgumentCaptor.forClass(String.class);
+ verify(restTemplate).postForEntity(urlCaptor.capture(), any(),
eq(CommonRobotNotifyResp.class));
+ assertEquals("http://localhost:8080/gotify/test-token",
urlCaptor.getValue());
}
@Test
public void testNotifyAlertFailure() {
+ when(bundle.getString("alerter.notify.title")).thenReturn("Alert
Notification");
+
when(alerterProperties.getGotifyWebhookUrl()).thenReturn("http://localhost:8080/gotify/%s");
+
CommonRobotNotifyResp failResp = new CommonRobotNotifyResp();
failResp.setCode(1);
failResp.setErrMsg("Test Error");
@@ -124,4 +134,11 @@ class GotifyAlertNotifyHandlerImplTest {
assertThrows(AlertNoticeException.class,
() -> gotifyAlertNotifyHandler.send(receiver, template,
groupAlert));
}
+
+ @Test
+ public void testDefaultAlerterPropertiesUrl() {
+ AlerterProperties properties = new AlerterProperties();
+ String formattedUrl = String.format(properties.getGotifyWebhookUrl(),
"test-token");
+ assertEquals("https://push.example.de/message?token=test-token",
formattedUrl);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]