gpt4 book ai didi

java - 在邮件通知中显示环境 Spring Boot Admin

转载 作者:行者123 更新时间:2023-12-02 04:21:48 26 4
gpt4 key购买 nike

我有一组使用 spring-boot-admin 进行监控和检测的应用程序。万一其中一个出现故障,我会通过邮件和松弛收到通知。我会在消息/电子邮件中显示我获取了发生问题的环境。

这是我用于电子邮件的 thymeleaf 模板

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
h1, h2, h3, h4, h5, h6 {
font-weight: 400
}
ul {
list-style: none
}
html {
box-sizing: border-box
}
*, :after, :before {
box-sizing: inherit
}
table {
border-collapse: collapse;
border-spacing: 0
}
td, th {
text-align: left
}
body, button {
font-family: BlinkMacSystemFont, -apple-system, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif
}
code, pre {
-moz-osx-font-smoothing: auto;
-webkit-font-smoothing: auto;
font-family: monospace
}
</style>
</head>
<body>
<th:block th:remove="all">
<!-- This block will not appear in the body and is used for the subject -->
<th:block th:remove="tag" th:fragment="subject">
[Admin-server] - [[${instance.registration.name}]] is
[[${event.statusInfo.status}]]
</th:block>
</th:block>
<h1>
<span th:text="${instance.registration.name}"/>
(<span th:text="${instance.id}"/>)
está <span th:text="${event.statusInfo.status}"/>
</h1>
<p>
The instance
<a th:if="${baseUrl}" th:href="@{${baseUrl + '/#/instances/' +
instance.id + '/'}}"><span th:text="${instance.id}"/></a>
<span th:unless="${baseUrl}" th:text="${instance.id}"/>
has changed its status from
<span th:text="${lastStatus}"/> to <span
th:text="${event.statusInfo.status}"/>
</p>

<h2>Details</h2>
<dl th:fragment="statusDetails" th:with="details = ${details ?:
event.statusInfo.details}">
<th:block th:each="detail : ${details}">
<dt th:text="${detail.key}"/>
<dd th:unless="${detail.value instanceof T(java.util.Map)}"
th:text="${detail.value}"/>
<dd th:if="${detail.value instanceof T(java.util.Map)}">
<dl th:replace="${#execInfo.templateName} :: statusDetails
(details = ${detail.value})"/>
</dd>
</th:block>
</dl>
</body>
</html>

这是目前的显示方式

Notification

这是我来自 Spring Admin 的 application.yml

server:
port: ${admin-server.port:8086}
tomcat:
remote-ip-header: x-forwarded-for
protocol-header: x-forwarded-proto
spring:
application:
name: admin-server
security:
user:
name: ${spring-security.admin.username}
password: ${spring-security.admin.password}
cloud:
kubernetes:
reload:
enabled: true
boot:
admin:
discovery:
ignored-services: admin-server
notify:
mail:
enabled: ${admin-mail.enabled:true}
to: ${admin-mail.recipients}
from: ${admin-mail.from}
template: classpath:/template/status-changed.html
ignore-changes: OFFLINE:UP, DOWN:UP
slack:
webhook-url: ${admin-slack.webhook}
ignore-changes: OFFLINE:UP, DOWN:UP
enabled: true
mail:
test-connection: false
host: ********
port: 25
properties:
mail:
smtp:
connectiontimeout: 5000
timeout: 3000
writetimeout: 5000
debug: ${admin-mail.debug:false}
management:
endpoint:
restart:
enabled: true

这就是我希望的显示方式

Notification_2

我目前在另一个属性文件中(因为我使用配置服务器),其中有一个变量表示应用程序所在的环境。

如何将该变量放入 Thymeleaf 模板中?如果有任何其他方式,完全欢迎。

最佳答案

您可以查看here用于自定义邮件模板。

如果只需要显示环境名称,您可以考虑使用 spring.boot.admin.client.instance.name 将客户端注册为 Client Name (${ENV}) 属性并避免覆盖 thymeleaf 模板的麻烦。

我对应用程序监控使用了相同的方法。此外,可以使用保存环境名称的 ${ENV} 变量为每个环境自定义来自 id 的邮件通知。

关于java - 在邮件通知中显示环境 Spring Boot Admin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56632505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com