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

fix: Alertmanager cloudevent payload #353

Merged
merged 5 commits into from
Aug 9, 2022
Merged
Changes from all commits
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
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 {
TannerGabriel marked this conversation as resolved.
Show resolved Hide resolved
source, _ := url.Parse("prometheus")

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