incident_notifier.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package notifier
  2. import "github.com/porter-dev/porter/api/types"
  3. type IncidentNotifier interface {
  4. NotifyNew(incident *types.Incident, url string) error
  5. NotifyResolved(incident *types.Incident, url string) error
  6. }
  7. type MultiIncidentNotifier struct {
  8. notifConf *types.NotificationConfig
  9. notifiers []IncidentNotifier
  10. }
  11. func NewMultiIncidentNotifier(notifConf *types.NotificationConfig, notifiers ...IncidentNotifier) IncidentNotifier {
  12. return &MultiIncidentNotifier{notifConf, notifiers}
  13. }
  14. func (m *MultiIncidentNotifier) NotifyNew(incident *types.Incident, url string) error {
  15. // if notification config exists and notifs are disabled for this release, or failure notifications
  16. // are disabled, do not alert
  17. if m.notifConf != nil && (!m.notifConf.Enabled || !m.notifConf.Failure) {
  18. return nil
  19. }
  20. for _, n := range m.notifiers {
  21. if err := n.NotifyNew(incident, url); err != nil {
  22. return err
  23. }
  24. }
  25. return nil
  26. }
  27. func (m *MultiIncidentNotifier) NotifyResolved(incident *types.Incident, url string) error {
  28. // if notification config exists and notifs are disabled for this release, or failure notifications
  29. // are disabled, do not alert
  30. if m.notifConf != nil && (!m.notifConf.Enabled || !m.notifConf.Failure) {
  31. return nil
  32. }
  33. for _, n := range m.notifiers {
  34. if err := n.NotifyResolved(incident, url); err != nil {
  35. return err
  36. }
  37. }
  38. return nil
  39. }