Skip to content

Latest commit

 

History

History
73 lines (69 loc) · 1.82 KB

DEVELOPMENT.md

File metadata and controls

73 lines (69 loc) · 1.82 KB

开发指南

告警处理流程

如何开发新的告警代理

  1. 实现AlertProxy接口,
type AlertProxy interface {
	// Do a new alert requet
	DoRequest(params url.Values, alert Alert) error
}
  • DoRequest用来提取本次webhook的数据,并通过你的AlertProxy实例中的模板及原生告警内容,渲染生成新的http request,然后使用自己的客户端发起请求。
  1. Init()函数中注册该告警代理
func Init(cfgs *config.ProxyConfigs) {
	for _, v := range cfgs.Templates {
		if _, ok := alertProxyMap[v.Type]; ok {
			log.Fatalf("duplicated alert proxy type: %s", v.Type)
		}
		tmpl := template.Must(template.New(string(v.Type)).Parse(v.Template))
		switch v.Type {
		case config.Feishu:
			alertProxyMap[v.Type] = NewFeishuRobot(tmpl)
		case config.AliyunMsg:
			alertProxyMap[v.Type] = NewAliyunMsg(tmpl)
		case config.AliyunVoice:
			alertProxyMap[v.Type] = NewAliyunVoice(tmpl)
		default:
			log.Fatalf("unsupported alert proxy type: %s", v.Type)
		}
	}
}
  1. 将你的告警代理模板,填写在config/deploy/alertproxy.yaml文件中。
  • type: 代理类型
  • template: 要渲染的模板内容,你可以在DoRequest渲染模板

运行&部署

  1. 本地运行 自行修改config/deploy/alertproxy.yaml配置
go run main.go serve
  1. vscode debug
$ cat .vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "alertproxy",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}",
            "args": [
                "serve"
            ]
        }
    ]
}
  1. 构建镜像
make docker-build docker-push
  1. 部署
make deploy