diff --git a/controllers/WebTest.go b/controllers/WebTest.go
index a78cc401..29552578 100644
--- a/controllers/WebTest.go
+++ b/controllers/WebTest.go
@@ -49,7 +49,7 @@ func (c *MainController) AlertTest() {
PrometheusAlert邮件告警测试
欢迎使用PrometheusAlert
`
- ret := SendEmail(TestEmailMessage, beego.AppConfig.String("Default_emails"), logsign)
+ ret := SendEmail(TestEmailMessage, beego.AppConfig.String("Default_emails"), beego.AppConfig.String("Email_title"), logsign)
c.Data["json"] = ret
case "7moordx":
MobileMessage := "PrometheusAlertCenter测试告警"
@@ -93,7 +93,7 @@ func (c *MainController) AlertTest() {
c.ServeJSON()
}
-//markdown test
+// markdown test
func (c *MainController) MarkdownTest() {
if !CheckAccount(c.Ctx) {
c.Redirect("/login", 302)
@@ -123,7 +123,7 @@ func (c *MainController) MarkdownTest() {
}
-//test page
+// test page
func (c *MainController) Test() {
if !CheckAccount(c.Ctx) {
c.Redirect("/login", 302)
diff --git a/controllers/email.go b/controllers/email.go
index 90e3af7e..78cc178c 100644
--- a/controllers/email.go
+++ b/controllers/email.go
@@ -10,7 +10,7 @@ import (
)
// SendEmail
-func SendEmail(EmailBody, Emails, logsign string) string {
+func SendEmail(EmailBody, Emails, EmailTitle, logsign string) string {
open := beego.AppConfig.String("open-email")
if open != "1" {
logs.Info(logsign, "[email]", "email未配置未开启状态,请先配置open-email为1")
@@ -20,7 +20,7 @@ func SendEmail(EmailBody, Emails, logsign string) string {
serverPort, _ := beego.AppConfig.Int("Email_port")
fromEmail := beego.AppConfig.String("Email_user")
Passwd := beego.AppConfig.String("Email_password")
- EmailTitle := beego.AppConfig.String("Email_title")
+ //EmailTitle := beego.AppConfig.String("Email_title")
//Emails= xxx1@qq.com,xxx2@qq.com,xxx3@qq.com
SendToEmails := []string{}
m := gomail.NewMessage()
diff --git a/controllers/gitlab.go b/controllers/gitlab.go
index af760abb..263d36ea 100644
--- a/controllers/gitlab.go
+++ b/controllers/gitlab.go
@@ -473,7 +473,7 @@ func sendGitlabEvent(typeid int, event GitlabEvent, eventType, logsign, sendURL
if sendURL == "" {
sendURL = beego.AppConfig.String("Default_emails")
}
- SendEmail(EmailMessage, sendURL, logsign)
+ SendEmail(EmailMessage, sendURL, beego.AppConfig.String("Email_title"), logsign)
// 2 dingding robot
case 2:
DDtext := genDDtext(event, eventType)
diff --git a/controllers/prometheus.go b/controllers/prometheus.go
index 8a3b19ce..eed540f2 100644
--- a/controllers/prometheus.go
+++ b/controllers/prometheus.go
@@ -286,14 +286,16 @@ func SendMessageR(message Prometheus, rwxurl, rddurl, rfsurl, rphone, remail, rg
//发送消息到Email
if remail == "" && RMessage.Annotations.Email == "" {
Emails := beego.AppConfig.String("Default_emails")
- SendEmail(EmailMessage, Emails, logsign)
+ EmailTitle := beego.AppConfig.String("Email_title")
+ SendEmail(EmailMessage, Emails, EmailTitle, logsign)
} else {
+ EmailTitle := beego.AppConfig.String("Email_title")
if remail != "" {
- SendEmail(EmailMessage, remail, logsign)
+ SendEmail(EmailMessage, remail, EmailTitle, logsign)
}
if RMessage.Annotations.Email != "" {
Emails := RMessage.Annotations.Email
- SendEmail(EmailMessage, Emails, logsign)
+ SendEmail(EmailMessage, Emails, EmailTitle, logsign)
}
}
//发送消息到短信
diff --git a/controllers/prometheusalert.go b/controllers/prometheusalert.go
index 157fea71..c4de9ebe 100644
--- a/controllers/prometheusalert.go
+++ b/controllers/prometheusalert.go
@@ -68,6 +68,7 @@ type PrometheusAlertMsg struct {
WebHookUrl string
ToUser string
Email string
+ EmailTitle string
ToParty string
ToTag string
GroupId string
@@ -141,6 +142,7 @@ func (c *PrometheusAlertController) PrometheusAlert() {
pMsg.ToUser = checkURL(c.Input().Get("wxuser"), beego.AppConfig.String("WorkWechat_ToUser"))
pMsg.ToParty = checkURL(c.Input().Get("wxparty"), beego.AppConfig.String("WorkWechat_ToUser"))
pMsg.ToTag = checkURL(c.Input().Get("wxtag"), beego.AppConfig.String("WorkWechat_ToUser"))
+ pMsg.EmailTitle = checkURL(c.Input().Get("emailtitle"), beego.AppConfig.String("Email_title"))
// dd, wx, fsv2 的 at 格式不一样,放在告警组里不好处理和组装。
pMsg.AtSomeOne = c.Input().Get("at")
@@ -520,7 +522,7 @@ func SendMessagePrometheusAlert(message string, pmsg *PrometheusAlertMsg, logsig
ReturnMsg += Post7MOORphonecall(message, pmsg.Phone, logsign)
//邮件
case "email":
- ReturnMsg += SendEmail(message, pmsg.Email, logsign)
+ ReturnMsg += SendEmail(message, pmsg.Email, pmsg.EmailTitle, logsign)
// Telegram
case "tg":
ReturnMsg += SendTG(message, logsign)
diff --git a/doc/readme/system-var.md b/doc/readme/system-var.md
index 9b09a28e..c42dcec8 100644
--- a/doc/readme/system-var.md
+++ b/doc/readme/system-var.md
@@ -23,8 +23,15 @@
`示例:http://[prometheusalert_url]:8080/prometheusalert?type=dd&tpl=prometheus-dd&ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxx,https://oapi.dingtalk.com/robot/send?access_token=xxxxxx,https://oapi.dingtalk.com/robot/send?access_token=xxxxxx&rr=true&split=false`
-#### 5.自定义模板使用的是go语言的template模版,可以参考默认模版的一些语法来进行自定义。
+#### 5.url参数新增 `emailtitle=运维监控中心`,该参数仅针对email有效,作用是替换app.conf中的Email_title邮件标题配置,实现动态定义邮件标题
-#### 6.模版数据等信息均存储在程序目录的下的`db/PrometheusAlertDB.db`中。
+注意:此参数如设置为`split=false`,则PrometheusAlert web页面的路由和告警记录等功能将自动关闭,请谨慎。
+
+`示例:http://[prometheusalert_url]:8080/prometheusalert?type=email&tpl=prometheus-email&email=xxxx@xxx.com&emailtitle=运维监控中心`
+
+
+#### 6.自定义模板使用的是go语言的template模版,可以参考默认模版的一些语法来进行自定义。
+
+#### 7.模版数据等信息均存储在程序目录的下的`db/PrometheusAlertDB.db`中。
-#### 7.关于优先级问题:路由功能 > URL参数 > app.conf
\ No newline at end of file
+#### 8.关于优先级问题:路由功能 > URL参数 > app.conf
\ No newline at end of file