-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ospp] support custom notice template #1233
Conversation
👍 |
# password: 123456 | ||
# url: jdbc:h2:./data/hertzbeat;MODE=MYSQL | ||
# hikari: | ||
# max-lifetime: 120000 | ||
datasource: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个配置修改本地测试可以的,但是不要提交远程
description = "模板名称", | ||
example = "dispatch-1", accessMode = READ_WRITE) | ||
@Length(max = 100) | ||
@NotNull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
针对String类型的非空校验,可以使用@NotBlank
@Schema(title = "Record the latest modification time (timestamp in milliseconds)", | ||
description = "记录最新修改时间", accessMode = READ_ONLY) | ||
@LastModifiedDate | ||
private LocalDateTime gmtUpdate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否缺少一个字段,用于标识是否系统预设模版(系统预设模板不允许删除)?
@@ -189,7 +344,9 @@ public boolean sendTestMsg(NoticeReceiver noticeReceiver) { | |||
alert.setFirstAlarmTime(System.currentTimeMillis()); | |||
alert.setLastAlarmTime(System.currentTimeMillis()); | |||
alert.setPriority(CommonConstants.ALERT_PRIORITY_CODE_CRITICAL); | |||
return dispatcherAlarm.sendNoticeMsg(noticeReceiver, alert); | |||
Byte type=noticeReceiver.getType(); | |||
NoticeTemplate noticeTemplate=getNoticeTemplatesById(Long.valueOf(type));; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边逻辑不太对,传参是type
,但是查询是通过模板ID查询
|
||
@Override | ||
public NoticeTemplate getNoticeTemplatesById(Long templateId) { | ||
return noticeTemplateDao.getReferenceById(templateId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议使用findById
,返回值用Optional
context.setVariable("monitorNameLabel", bundle.getString("alerter.notify.monitorName")); | ||
context.setVariable("targetLabel", bundle.getString("alerter.notify.target")); | ||
context.setVariable("target", alert.getTarget()); | ||
String monitorId=alert.getTags().get("monitorId"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
存在空指针风险
Signed-off-by: Eden4701 <Eden4701@163.com>
Signed-off-by: Eden4701 <Eden4701@163.com>
hi pls fix these confilcts
|
Signed-off-by: Eden4701 <Eden4701@163.com>
建议不设置
|
要不要把我们内置的默认消息模版像之前一样以文件的方式存储,用户自定义消息模版用现在的数据库方式存储。系统启动时从文件中加载内置模版到内存中,当 |
Should we store our built-in default message templates in files as before, and user-defined message templates in the current database method? When the system starts, the built-in template is loaded from the file into the memory. When |
新的代码已提交,预设模板文件存储,自定义模板在数据库,设置通知规则时模板是可选项,用户不选择模板时默认使用预设模板 |
The new code has been submitted, the preset template file is stored, and the custom template is in the database. The template is optional when setting notification rules. When the user does not select a template, the preset template is used by default. |
|
||
@EventListener(SystemConfigChangeEvent.class) | ||
public void onEvent(SystemConfigChangeEvent event) { | ||
log.info("{} receive system config change event: {}.", this.getClass().getName(), event.getSource()); | ||
this.bundle = ResourceBundleUtil.getBundle("alerter"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi 这里需要保留 当用户语言变更时 模版语言监听变更
//获取sender | ||
JavaMailSenderImpl sender = (JavaMailSenderImpl) javaMailSender; | ||
String fromUsername = username; | ||
try { | ||
boolean useDatabase = false; | ||
GeneralConfig emailConfig = generalConfigDao.findByType(TYPE); | ||
if (emailConfig != null && emailConfig.getContent() != null) { | ||
// 若启用数据库配置 | ||
String content = emailConfig.getContent(); | ||
EmailNoticeSender emailNoticeSenderConfig = objectMapper.readValue(content, EmailNoticeSender.class); | ||
if (emailNoticeSenderConfig.isEnable()) { | ||
sender.setHost(emailNoticeSenderConfig.getEmailHost()); | ||
sender.setPort(emailNoticeSenderConfig.getEmailPort()); | ||
sender.setUsername(emailNoticeSenderConfig.getEmailUsername()); | ||
sender.setPassword(emailNoticeSenderConfig.getEmailPassword()); | ||
Properties props = sender.getJavaMailProperties(); | ||
props.put("mail.smtp.ssl.enable", emailNoticeSenderConfig.isEmailSsl()); | ||
fromUsername = emailNoticeSenderConfig.getEmailUsername(); | ||
useDatabase = true; | ||
} | ||
} | ||
if (!useDatabase) { | ||
// 若数据库未配置则启用yml配置 | ||
sender.setHost(host); | ||
sender.setPort(port); | ||
sender.setUsername(username); | ||
sender.setPassword(password); | ||
Properties props = sender.getJavaMailProperties(); | ||
props.put("mail.smtp.ssl.enable", sslEnable); | ||
} | ||
} catch (Exception e) { | ||
log.error("Type not found {}",e.getMessage()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi 数据库获取邮件服务器配置需要保留,我们现在支持用户在页面配置邮件服务器 或者 在 application.yml配置邮件服务器。优先级 页面数据库配置 高于 application.yml 文件配置。
|
||
@EventListener(SystemConfigChangeEvent.class) | ||
public void onEvent(SystemConfigChangeEvent event) { | ||
log.info("{} receive system config change event: {}.", this.getClass().getName(), event.getSource()); | ||
this.bundle = ResourceBundleUtil.getBundle("alerter"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi 同上上,这里监听语言变更也需要保留
@EventListener(SystemConfigChangeEvent.class) | ||
public void onEvent(SystemConfigChangeEvent event) { | ||
log.info("{} receive system config change event: {}.", this.getClass().getName(), event.getSource()); | ||
this.bundle = ResourceBundleUtil.getBundle("alerter"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi 同上,这里监听语言变更也需要保留
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍👍LGTM
@all-contributors please add @Eden4701 for code |
I've put up a pull request to add @Eden4701! 🎉 |
@Eden4701 hi 打扰了 今天使用中有个建议反馈下 我们现在对默认模版每次是发告警时去打开文件,读取文件内容,关闭文件这样,在大量告警消息时会很耗性能。建议参考 org.dromara.hertzbeat.manager.service.impl.AppServiceImpl#run 在程序启动时统一读取文件加载到内存中,发告警消息时若使用内置默认模版,就到内存中取模版内容即可。 |
@Eden4701 hi I’m sorry to bother you. I have a suggestion during use today. Please give me feedback. We now use the default template to open the file, read the file content, and close the file every time an alarm is sent. This will consume a lot of performance when there are a large number of alarm messages. It is recommended to refer to org.dromara.hertzbeat.manager.service.impl.AppServiceImpl#run to uniformly read the file and load it into the memory when the program starts. If you use the built-in default template when sending an alarm message, just get the template content from the memory. |
ok |
OK |
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
Signed-off-by: Eden4701 <Eden4701@163.com> Co-authored-by: ulikehhh <2762242004@qq.com>
What's changed?
Custom Notice Template Configuration
Checklist