alert.go 950 B

12345678910111213141516171819202122232425262728
  1. package proposal
  2. import (
  3. "encoding/json"
  4. "time"
  5. )
  6. // AlertMessage 告警信息
  7. type AlertMessage struct {
  8. ProjectName string `json:"project_name"` // 项目名,用于区分不同项目告警信息
  9. Env string `json:"env"` // 运行环境
  10. TraceID string `json:"trace_id"` // 唯一ID,用于追踪关联
  11. HOST string `json:"host"` // 请求 HOST
  12. URI string `json:"uri"` // 请求 URI
  13. Method string `json:"method"` // 请求 Method
  14. ErrorMessage interface{} `json:"error_message"` // 错误信息
  15. ErrorStack string `json:"error_stack"` // 堆栈信息
  16. Timestamp time.Time `json:"timestamp"` // 时间戳
  17. }
  18. // Marshal 序列化到JSON
  19. func (a *AlertMessage) Marshal() (jsonRaw []byte) {
  20. jsonRaw, _ = json.Marshal(a)
  21. return
  22. }
  23. // NotifyHandler 告警的发送句柄
  24. type NotifyHandler func(msg *AlertMessage)