告警引擎模块是n9e-server,发送也是这个模块,查看server.conf,可以看到Alerting相关的一些配置,都是和告警发送相关的:

    1. [SMTP]
    2. Host = "smtp.163.com"
    3. Port = 994
    4. User = "username"
    5. Pass = "password"
    6. From = "username@163.com"
    7. InsecureSkipVerify = true
    8. Batch = 5
    9. [Alerting]
    10. TemplatesDir = "./etc/template"
    11. NotifyConcurrency = 10
    12. # use builtin go code notify by default
    13. NotifyBuiltinEnable = true
    14. [Alerting.CallScript]
    15. # built in sending capability in go code
    16. # so, no need enable script sender
    17. Enable = false
    18. ScriptPath = "./etc/script/notify.py"
    19. [Alerting.CallPlugin]
    20. Enable = false
    21. # use a plugin via `go build -buildmode=plugin -o notify.so`
    22. PluginPath = "./etc/script/notify.so"
    23. Caller = "n9eCaller"
    24. [Alerting.RedisPub]
    25. Enable = false
    26. # complete redis key: ${ChannelPrefix} + ${Cluster}
    27. ChannelPrefix = "/alerts/"
    28. [Alerting.Webhook]
    29. Enable = false
    30. Url = "http://a.com/n9e/callback"
    31. BasicAuthUser = ""
    32. BasicAuthPass = ""
    33. Timeout = "5s"
    34. Headers = ["Content-Type", "application/json", "X-From", "N9E"]

    SMTP相关的是邮件发送的配置;剩下的Alerting相关的配置,都可以不用动,默认夜莺支持了邮件、钉钉、企微、飞书四种通知机制;对于发送的消息内容,有个通知模板,在Alerting.TemplatesDir指定的配置目录里可以看到一堆模板文件,采用Go的模板语法,如果想修改消息内容就是修改这些模板文件即可。

    如果想二次开发,自行对告警做处理,可以启用Alerting.CallScript、Alerting.CallPlugin、Alerting.RedisPub、Alerting.Webhook等配置段,分别表示,通过脚本的方式自行处理发送告警、通过Plugin的方式来发送告警、让系统把告警消息统一推送给Redis,启用全局的Webhook,告警之后夜莺回调一个全局的Url,您可以在这个回调地址里写自己的定制逻辑。