代码拉取完成,页面将自动刷新
package alert
import (
"strings"
"github.com/admpub/nging/application/dbschema"
"github.com/admpub/nging/application/library/cron/send"
"github.com/admpub/nging/application/library/imbot"
"github.com/webx-top/echo"
"github.com/webx-top/echo/param"
)
// Send 发送警报
func Send(a *dbschema.NgingAlertRecipient, extra echo.H, params param.Store) (err error) {
title := params.String(`title`)
ct, ok := params.Get(`content`).(send.ContentType)
if !ok {
return nil
}
switch a.Type {
case `email`:
content := ct.EmailContent(params)
err = send.Mail(a.Account, strings.SplitN(a.Account, `@`, 2)[0], title, content)
case `webhook`:
mess := imbot.Open(a.Platform)
if mess == nil || mess.Messager == nil {
return
}
var apiURL string
if len(a.Account) > 7 {
switch a.Account[0:7] {
case `https:/`, `http://`:
apiURL = a.Account
}
}
if len(apiURL) == 0 {
apiURL = mess.Messager.BuildURL(a.Account)
}
var atMobiles []string
if extra.Has(`at`) {
switch v := extra.Get(`at`).(type) {
case []interface{}:
atMobiles = make([]string, len(v))
for k, m := range v {
atMobiles[k] = param.AsString(m)
}
case []string:
atMobiles = v
}
}
content := ct.MarkdownContent(params)
message := string(content)
go func(apiURL string, title string, message string, atMobiles ...string) {
err = mess.Messager.SendMarkdown(apiURL, title, message, atMobiles...)
}(apiURL, title, message, atMobiles...)
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。