Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use kapacitor alert details as opsgenie description text #2409

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions services/opsgenie2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ func (s *Service) Test(options interface{}) error {
o.Message,
o.EntityID,
time.Now(),
"",
models.Result{},
)
}

func (s *Service) Alert(teams []string, recipients []string, recoveryAction string, level alert.Level, message, entityID string, t time.Time, details models.Result) error {
req, err := s.preparePost(teams, recipients, recoveryAction, level, message, entityID, t, details)
func (s *Service) Alert(teams []string, recipients []string, recoveryAction string, level alert.Level, message, entityID string, t time.Time, eventDetails string, details models.Result) error {
req, err := s.preparePost(teams, recipients, recoveryAction, level, message, entityID, t, eventDetails, details)
if err != nil {
return errors.Wrap(err, "failed to prepare API request")
}
Expand All @@ -142,7 +143,7 @@ func (s *Service) Alert(teams []string, recipients []string, recoveryAction stri
return nil
}

func (s *Service) preparePost(teams []string, recipients []string, recoveryAction string, level alert.Level, message, entityID string, t time.Time, details models.Result) (*http.Request, error) {
func (s *Service) preparePost(teams []string, recipients []string, recoveryAction string, level alert.Level, message, entityID string, t time.Time, eventDetails string, details models.Result) (*http.Request, error) {
c := s.config()
if !c.Enabled {
return nil, errors.New("service is not enabled")
Expand Down Expand Up @@ -190,12 +191,17 @@ func (s *Service) preparePost(teams []string, recipients []string, recoveryActio
ogData["note"] = ""
ogData["priority"] = priority

// Encode details as description
b, err := json.Marshal(details)
if err != nil {
return nil, err
// Use event details as description if available
if len(eventDetails) > 0 {
ogData["description"] = eventDetails
} else {
// Otherwise encode details as description
b, err := json.Marshal(details)
if err != nil {
return nil, err
}
ogData["description"] = string(b)
}
ogData["description"] = string(b)

//Extra Fields (can be used for filtering)
ogDetails := make(map[string]string)
Expand Down Expand Up @@ -293,6 +299,7 @@ func (h *handler) Handle(event alert.Event) {
event.State.Message,
event.State.ID,
event.State.Time,
event.State.Details,
event.Data.Result,
); err != nil {
h.diag.Error("failed to send event to OpsGenie", err)
Expand Down