Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
fix: Alertmanager cloudevent payload (#353)
Browse files Browse the repository at this point in the history
* fix: Alertmanager cloudevent payload to be compatible with remediation-service

Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>

* Move problem event data into correct type

Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>

* Remove duplicated check

Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>

* Make remediation triggered data type private

Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>

* Remove pointer from variable

Signed-off-by: TannerGabriel <gabrieltanner.code@gmail.com>
  • Loading branch information
TannerGabriel authored Aug 9, 2022
1 parent 7748961 commit 55caac4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions eventhandling/alertEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
keptncommons "github.com/keptn/go-utils/pkg/lib"
"net/http"
"net/url"
"strings"
"time"

keptncommons "github.com/keptn/go-utils/pkg/lib"
"github.com/keptn/go-utils/pkg/lib/keptn"
keptnv2 "github.com/keptn/go-utils/pkg/lib/v0_2_0"

Expand Down Expand Up @@ -51,6 +51,13 @@ type annotations struct {
Description string `json:"descriptions,omitempty"`
}

type remediationTriggeredEventData struct {
keptnv2.EventData

// Problem contains details about the problem
Problem keptncommons.ProblemEventData `json:"problem"`
}

// ProcessAndForwardAlertEvent reads the payload from the request and sends a valid Cloud event to the keptn event broker
func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, logger *keptn.Logger, shkeptncontext string) {
var event alertManagerEvent
Expand All @@ -70,7 +77,7 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log
return
}

newEventData := keptncommons.ProblemEventData{
problemData := keptncommons.ProblemEventData{
State: problemState,
ProblemID: "",
ProblemTitle: event.Alerts[0].Annotations.Summary,
Expand All @@ -82,6 +89,15 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log
Service: event.Alerts[0].Labels.Service,
}

newEventData := remediationTriggeredEventData{
EventData: keptnv2.EventData{
Project: event.Alerts[0].Labels.Project,
Stage: event.Alerts[0].Labels.Stage,
Service: event.Alerts[0].Labels.Service,
},
Problem: problemData,
}

if event.Alerts[0].Fingerprint != "" {
// Note: fingerprint is always the same, we will append the startdate to create a unique keptn context
shkeptncontext = createOrApplyKeptnContext(event.Alerts[0].Fingerprint + event.Alerts[0].StartsAt)
Expand All @@ -102,7 +118,7 @@ func ProcessAndForwardAlertEvent(rw http.ResponseWriter, requestBody []byte, log
}

// createAndSendCE create a new problem.triggered event and send it to Keptn
func createAndSendCE(problemData keptncommons.ProblemEventData, shkeptncontext string) error {
func createAndSendCE(problemData remediationTriggeredEventData, shkeptncontext string) error {
source, _ := url.Parse("prometheus")

eventType := keptnv2.GetTriggeredEventType(problemData.Stage + "." + remediationTaskName)
Expand Down

0 comments on commit 55caac4

Please sign in to comment.