diff --git a/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplate.java b/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplate.java
index 6fd7fac43d3b..0c1e5e2ae53b 100644
--- a/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplate.java
+++ b/batch-alarmsender/src/main/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplate.java
@@ -30,7 +30,7 @@ public class AlarmMailTemplate {
private static final String LINE_FEED = "
";
private static final String LINK_FORMAT = "pinpoint site";
- private static final String SCATTER_CHART_LINK_FORMAT = "scatter chart of %s";
+ private static final String SCATTER_CHART_LINK_FORMAT = "scatter chart of %s";
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss");
@@ -51,14 +51,23 @@ public String createSubject() {
return String.format("[PINPOINT-%s] %s Alarm for %s Service. #%d", batchEnv, rule.getCheckerName(), rule.getApplicationId(), sequenceCount);
}
- public String getCurrentTime() {
- LocalDateTime now = LocalDateTime.now();
- return FORMATTER.format(now);
+ public String getTime() {
+ LocalDateTime to = LocalDateTime.now();
+ String toTime = FORMATTER.format(to);
+ LocalDateTime from = to.minusMinutes(5);
+ String fromTime = FORMATTER.format(from);
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("from=");
+ sb.append(fromTime);
+ sb.append("&to=");
+ sb.append(toTime);
+ return sb.toString();
}
public String createBody() {
RuleInterface rule = checker.getRule();
- return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationId(), rule.getServiceType(), getCurrentTime());
+ return newBody(createSubject(), rule.getCheckerName(), rule.getApplicationId(), rule.getServiceType(), getTime());
}
private String newBody(String subject, String rule, String applicationId, String serviceType, String currentTime) {
diff --git a/batch-alarmsender/src/test/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplateTest.java b/batch-alarmsender/src/test/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplateTest.java
new file mode 100644
index 000000000000..7f512e51bd69
--- /dev/null
+++ b/batch-alarmsender/src/test/java/com/navercorp/pinpoint/batch/alarm/sender/AlarmMailTemplateTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2024 NAVER Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.navercorp.pinpoint.batch.alarm.sender;
+
+import com.navercorp.pinpoint.batch.alarm.checker.AlarmCheckerInterface;
+import com.navercorp.pinpoint.web.vo.RuleInterface;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author minwoo-jung
+ */
+//@Disabled
+@ExtendWith({MockitoExtension.class})
+class AlarmMailTemplateTest {
+
+ @Mock
+ AlarmCheckerInterface checker;
+
+ @Mock
+ RuleInterface rule;
+
+ @Test
+ public void newBodyTest() {
+ when(rule.getCheckerName()).thenReturn("checkerName");
+ when(rule.getApplicationId()).thenReturn("applicaitonId");
+ when(rule.getServiceType()).thenReturn("TOMCAT");
+ when(checker.getRule()).thenReturn(rule);
+ when(checker.getEmailMessage(anyString(), anyString(), anyString(), anyString())).thenReturn("ERROR RATE is 25 % (Threshold: 10 %)
");
+
+ AlarmMailTemplate alarmMailTemplate = new AlarmMailTemplate(checker, "http://pinpoint.com", "batchEnv", 1);
+ alarmMailTemplate.createBody();
+ }
+}
\ No newline at end of file