Skip to content

Commit

Permalink
move alert to types
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 29, 2024
1 parent e7a2345 commit 13070e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
11 changes: 10 additions & 1 deletion alert/processAlert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ import (
"alertmanager/config"
"alertmanager/enrichment"
"alertmanager/logging"
"alertmanager/types"
"fmt"
)

func LoadAlertFromPayload(a *types.Alert) error {
if an, ok := a.Labels["alertname"]; ok {
a.AlertName = an
return nil
}
return fmt.Errorf("alertname not present in alert payload")
}

// Processes an entire alert-pipeline end-to-end
// If an alert-pipeline is configured for given alert
// this function executes the enrichments one-by-one
// then it executes the actions one-by-one
// The body of the Action is passed to all the enrichment and action
// so that they have the complete context regarding what is going on
// The actions additionally will also contain the output of all the enrichments
func ProcessAlert(a Alert) {
func ProcessAlert(a types.Alert) {
logr := logging.GetLogger()
an := a.GetAlertName()

Expand Down
3 changes: 2 additions & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"alertmanager/alert"
"alertmanager/logging"
"alertmanager/types"
"alertmanager/utils"

"github.com/gofiber/fiber/v2"
Expand All @@ -11,7 +12,7 @@ import (
func alertWebhookHandler(c *fiber.Ctx) error {
logr := logging.GetLogger()
logr.Debug("in webhook handler")
ag := new(alert.AlertGroup)
ag := new(types.AlertGroup)

b := c.BodyRaw()

Expand Down
20 changes: 5 additions & 15 deletions alert/alert.go → types/alert.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package alert
package types

import (
"alertmanager/types"
"encoding/json"
"fmt"
"time"
)

type Alert struct {
// fields we use to process stuff
alertName string `json:"-"`
enrichments []types.Enrichment `json:"-"`
actions []types.Action `json:"-"`
AlertName string `json:"-"`
Enrichments []Enrichment `json:"-"`
Actions []Action `json:"-"`

// fields we get from outside
Annotations map[string]string `json:"annotations"`
Expand All @@ -35,7 +33,7 @@ type AlertGroup struct {

// getter and setter for internal fields
func (a *Alert) GetAlertName() string {
return a.alertName
return a.AlertName
}

func (c AlertGroup) String() string {
Expand All @@ -45,11 +43,3 @@ func (c AlertGroup) String() string {
// handled at the ValidateAndLoad level
return string(s)
}

func LoadAlertFromPayload(a *Alert) error {
if an, ok := a.Labels["alertname"]; ok {
a.alertName = an
return nil
}
return fmt.Errorf("alertname not present in alert payload")
}

0 comments on commit 13070e8

Please sign in to comment.