Skip to content

Commit

Permalink
[improve] email notice template use the common render (apache#2775)
Browse files Browse the repository at this point in the history
Signed-off-by: tomsun28 <[email protected]>
  • Loading branch information
tomsun28 authored Oct 15, 2024
1 parent a0995d2 commit efa2dc3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ protected String renderContent(NoticeTemplate noticeTemplate, Alert alert) throw
model.put("content", alert.getContent());
model.put("tagsLabel", bundle.getString("alerter.notify.tags"));
model.put("tags", alert.getTags());
// Single instance reuse cache considers mulitple-threading issues
if (alerterProperties != null) {
model.put("consoleUrl", alerterProperties.getConsoleUrl());
}
model.put("consoleLabel", bundle.getString("alerter.notify.console"));
// TODO Single instance reuse cache considers multiple-threading issues
String templateName = "freeMakerTemplate";
stringLoader.putTemplate(templateName, noticeTemplate.getContent());
cfg.setTemplateLoader(stringLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
import org.apache.hertzbeat.common.support.event.SystemConfigChangeEvent;
import org.apache.hertzbeat.common.util.ResourceBundleUtil;
import org.apache.hertzbeat.manager.component.alerter.AlertNotifyHandler;
import org.apache.hertzbeat.manager.dao.GeneralConfigDao;
import org.apache.hertzbeat.manager.pojo.dto.EmailNoticeSender;
import org.apache.hertzbeat.manager.service.MailService;
import org.apache.hertzbeat.manager.support.exception.AlertNoticeException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
Expand All @@ -48,12 +46,10 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class EmailAlertNotifyHandlerImpl implements AlertNotifyHandler {
public class EmailAlertNotifyHandlerImpl extends AbstractAlertNotifyHandlerImpl {

private final JavaMailSender javaMailSender;

private final MailService mailService;

@Value("${spring.mail.host:smtp.demo.com}")
private String host;

Expand Down Expand Up @@ -127,7 +123,7 @@ public void send(NoticeReceiver receiver, NoticeTemplate noticeTemplate, Alert a
messageHelper.setTo(receiver.getEmail());
messageHelper.setSentDate(new Date());
// Build email templates
String process = mailService.buildAlertHtmlTemplate(alert, noticeTemplate);
String process = renderContent(noticeTemplate, alert);
// Set Email Content Template
messageHelper.setText(process, true);
javaMailSender.send(mimeMessage);
Expand Down

This file was deleted.

This file was deleted.

22 changes: 11 additions & 11 deletions manager/src/main/resources/templates/1-EmailTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@
class="tblCell">
<div style="line-height: 150%;">
<span style="font-size: 30px; line-height: 150%;">
<strong >${nameTitle}</strong>
<strong >${title}</strong>
</span>
</div>
</td>
Expand Down Expand Up @@ -648,7 +648,7 @@
color: #817878;
font-weight: 500;">
<span>
${nameTarget}
${targetLabel}
</span>
</td>
<td><span
Expand All @@ -659,7 +659,7 @@
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span >
${nameMonitorId}
${monitorIdLabel}
</span>
</td>
<td>
Expand All @@ -670,7 +670,7 @@
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameMonitorName}
${monitorNameLabel}
</span>
</td>
<td>
Expand All @@ -681,7 +681,7 @@
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameMonitorHost}
${monitorHostLabel}
</span>
</td>
<td>
Expand All @@ -692,7 +692,7 @@
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${namePriority}
${priorityLabel}
</span>
</td>
<td>
Expand All @@ -703,19 +703,19 @@
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameTriggerTime}
${triggerTimeLabel}
</span>
</td>
<td><span
>${lastTriggerTime}</span>
>${triggerTime}</span>
</td>
</tr>
<#if nameRestoreTime??>
<#if restoreTime??>
<tr>
<td align="right"
style="padding-right: 10px; color: #817878; font-weight: 500;">
<span>
${nameRestoreTime}
${restoreTimeLabel}
</span>
</td>
<td><span
Expand Down Expand Up @@ -767,7 +767,7 @@
target="_blank"
style="color:#FFFFFF;text-decoration:none;"
href="${consoleUrl}"
data-link-type="web">${nameConsole}</a></span>
data-link-type="web">${consoleLabel}</a></span>
</td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit efa2dc3

Please sign in to comment.