From f0f0b54268f4d0ee0aebb3bee1399ad4c8bedc0c Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Fri, 27 Oct 2023 16:35:19 +0800 Subject: [PATCH] fix: alarm email forward --- config/etc/default/restconf.yaml | 3 +++ features/fm/email.go | 26 +++++++++++++++++++++----- restagent/config/config.go | 9 +++++---- restagent/etc/restconf.yaml | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/config/etc/default/restconf.yaml b/config/etc/default/restconf.yaml index de896179..e7166037 100644 --- a/config/etc/default/restconf.yaml +++ b/config/etc/default/restconf.yaml @@ -115,6 +115,8 @@ alarm: port: 25 user: smtpuser password: xxxxxx + # TLS skip verify: true/false + tlsSkipVerify: true sms: apiURL: http://smsc.xxx.com accessKeyID: xxx @@ -127,6 +129,7 @@ alarm: # token: true/false to check accessToken # expires for session, unit: second # Support single/multiple session of user +# auth: crypt: bcrypt token: true diff --git a/features/fm/email.go b/features/fm/email.go index e83f9a82..24af2039 100644 --- a/features/fm/email.go +++ b/features/fm/email.go @@ -17,15 +17,27 @@ func AlarmEmailForward(alarmData *Alarm) error { log.Info("AlarmEmailForward processing... ") message := fmt.Sprintf(` -

Alarm information

-

Sequence: %d

+

Alarm information

+

Sequence: %d

NE name: %s

-

Title: %s

+

Title: %s

Severity: %s

Event Time: %s

-

The messsage is forwarded from OMC automatically, don't reply!

+

Automatic send by OMC, don't reply!

`, alarmData.AlarmSeq, alarmData.NeName, alarmData.AlarmTitle, alarmData.OrigSeverity, alarmData.EventTime) + // message := fmt.Sprintf(` + // Alarm information + + // Sequence: %d + // NE name: %s + // Title: %s + // Severity: %s + // Event Time: %s + + // Automatic send by OMC, don't reply! + // `, alarmData.AlarmSeq, alarmData.NeName, alarmData.AlarmTitle, alarmData.OrigSeverity, alarmData.EventTime) + // QQ 邮箱: // SMTP 服务器地址:smtp.qq.com(SSL协议端口:465/994 | 非SSL协议端口:25) // 163 邮箱: @@ -78,7 +90,7 @@ func AlarmEmailForward(alarmData *Alarm) error { m.SetBody("text/html", message) // text/plain的意思是将文件设置为纯文本的形式,浏览器在获取到这种文件时并不会对其进行处理 - // m.SetBody("text/plain", "纯文本") + //m.SetBody("text/plain", message) // m.Attach("test.sh") // 附件文件,可以是文件,照片,视频等等 // m.Attach("lolcatVideo.mp4") // 视频 // m.Attach("lolcat.jpg") // 照片 @@ -91,6 +103,10 @@ func AlarmEmailForward(alarmData *Alarm) error { ) // 关闭SSL协议认证 d.TLSConfig = &tls.Config{InsecureSkipVerify: true} + if !config.GetYamlConfig().Alarm.Email.TlsSkipVerify { + // 打开SSL协议认证 + d.TLSConfig = &tls.Config{InsecureSkipVerify: false} + } if err := d.DialAndSend(m); err != nil { operResult := fmt.Sprintf("Failed to DialAndSend:%v", err) diff --git a/restagent/config/config.go b/restagent/config/config.go index 2e5fd60b..6f9b3324 100644 --- a/restagent/config/config.go +++ b/restagent/config/config.go @@ -82,10 +82,11 @@ type YamlConfig struct { Alarm struct { ForwardAlarm bool `yaml:"forwardAlarm"` Email struct { - Smtp string `yaml:"smtp"` - Port uint16 `yaml:"port"` - User string `yaml:"user"` - Password string `yaml:"password"` + Smtp string `yaml:"smtp"` + Port uint16 `yaml:"port"` + User string `yaml:"user"` + Password string `yaml:"password"` + TlsSkipVerify bool `yaml:"tlsSkipVerify"` } `json:"email"` SMS struct { ApiURL string `yaml:"apiURL"` diff --git a/restagent/etc/restconf.yaml b/restagent/etc/restconf.yaml index 0d646d88..c91fe6ba 100644 --- a/restagent/etc/restconf.yaml +++ b/restagent/etc/restconf.yaml @@ -115,6 +115,8 @@ alarm: port: 25 user: smtpext@agrandtech.com password: "1000smtp@omc!" + # TLS skip verify: true/false + tlsSkipVerify: true sms: apiURL: http://smsc.xxx.com.cn/ accessKeyID: xxxx