Skip to content

Commit

Permalink
intiial alert processing
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 25, 2024
1 parent 6e7a0c9 commit 696ccdb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 12 additions & 1 deletion alert/processAlert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import (
"alertmanager/logging"
)

// Once I have an alertName
// I check for its pipeline in the AMconfig
// Once i get that
// I can the proper enrichmentFunc
// and the proper actionFunc
func ProcessAlert(a Alert) {
logr := logging.GetLogger()
an := a.GetAlertName()

logr.Debug("alert processor", an)

logr.Debug("Here is the alert config", config.GetAmConfig())
amc := config.GetAmConfig()
p := amc.GetPipelineForAlert(an)
if p != nil {
logr.Infof("no alert-pipeline configured for %s", an)
}

logr.Debug("alert pipeline", p)

}
15 changes: 15 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"alertmanager/action"
"alertmanager/enrichment"
"alertmanager/logging"
"fmt"

"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -51,6 +52,8 @@ func GetAmConfig() *AlertManagerConfig {
func ValidateAndLoad(b []byte) (*AlertManagerConfig, error) {
amConfig := GetAmConfig()

// todo protect this by a Mutex
// a write mutex is enough
// todo
// try to use a strict unmarshalling like in json
err := yaml.Unmarshal(b, &amConfig)
Expand All @@ -71,3 +74,15 @@ func ValidateAndLoad(b []byte) (*AlertManagerConfig, error) {
// maybe check if json-schema etc can help here
return amConfig, nil
}

func (am *AlertManagerConfig) GetPipelineForAlert(name string) *AlertPipelineConfig {
logr := logging.GetLogger()
for _, pipes := range am.AlertPipelines {
if pipes.AlertName == name {
logr.Debug("Pipeline found for alert : ", name)
return &pipes
}
}
logr.Debug("no pipelines found for alert : ", name)
return nil
}
6 changes: 3 additions & 3 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ func alertWebhookHandler(c *fiber.Ctx) error {
nalerts := len(alerts)
for i := 0; i < nalerts; i++ {
logr.Debugf(`loading alert %d -> %v`, i, alerts[i])
a := alerts[i]
err := alert.LoadAlertFromPayload(&a)
err := alert.LoadAlertFromPayload(&alerts[i])
if err != nil {
return c.SendStatus(fiber.StatusBadRequest)
}
logr.Debugf("%s", a.GetAlertName())
logr.Debugf("alertname found in payload : %s", alerts[i].GetAlertName())
}

// now that we know that all the alerts in the payload are processable
Expand All @@ -45,6 +44,7 @@ func alertWebhookHandler(c *fiber.Ctx) error {
// todo
// do we want to use go-routines and channels here ?
// ideally would depend on the volume here

for i := 0; i < nalerts; i++ {
logr.Debugf(`processing alert %d -> %v`, i, alerts[i])
alert.ProcessAlert(alerts[i])
Expand Down

0 comments on commit 696ccdb

Please sign in to comment.