alarm.go 649 B

1234567891011121314151617181920212223242526272829
  1. package httpclient
  2. import (
  3. "bufio"
  4. "bytes"
  5. "go.uber.org/zap"
  6. )
  7. // Verify parse the body and verify that it is correct
  8. type AlarmVerify func(body []byte) (shouldAlarm bool)
  9. type AlarmObject interface {
  10. Send(subject, body string) error
  11. }
  12. func onFailedAlarm(title string, raw []byte, logger *zap.Logger, alarmObject AlarmObject) {
  13. buf := bytes.NewBuffer(nil)
  14. scanner := bufio.NewScanner(bytes.NewReader(raw))
  15. for scanner.Scan() {
  16. buf.WriteString(scanner.Text())
  17. buf.WriteString(" <br/>")
  18. }
  19. if err := alarmObject.Send(title, buf.String()); err != nil && logger != nil {
  20. logger.Error("calls failed alarm err", zap.Error(err))
  21. }
  22. }