Skip to content

Commit

Permalink
just call the action and enrichment loader fuction
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 30, 2024
1 parent 519f315 commit eef23f0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
8 changes: 8 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ type ActionLut map[string]ActionFunc
func (flut ActionLut) Add(fname string, f ActionFunc) {
flut[fname] = f
}

// Use this function to load all the defined enrichments in memory
// is not goroutine safe
// todo: protect this with a mutex/sync.Once
func LoadActions() {
actMap := GetActionMap()
actMap.Add("NOOP_ACTION", NoopAction)
}
4 changes: 2 additions & 2 deletions alert-manager-config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
alert_pipelines:
- alert_name: NOOP_ALERT
enrichments:
- enrichment_name: NOOP_ENRICHMENT
enrichment_args: ARG1,ARG2
- enrichment_name: UPPER_CASE
enrichment_args: arg1,arg2
actions:
- action_name: NOOP_ACTION
action_args: ARG1,ARG2
Expand Down
4 changes: 4 additions & 0 deletions alert/processAlert.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func ProcessAlert(a types.Alert) {
if err != nil {
fmt.Println(err)
}
} else {
logr.Info("no enrichment found with name: ", v.EnrichmentName)
}
}

Expand All @@ -75,6 +77,8 @@ func ProcessAlert(a types.Alert) {
if err != nil {
fmt.Println(err)
}
} else {
logr.Info("no action found with name: ", v.ActionName)
}
}
}
8 changes: 3 additions & 5 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ func serverCommandRunE(cmd *cobra.Command, args []string) error {
}

// Initialize the Enrichments
log.Info("Adding NooP Enrichment")
enr := enrichment.GetEnrichmentMap()
enr.Add("NOOP_ENRICHMENT", enrichment.NoopEnrichment)
log.Info("loading pre-defined enrichments")
enrichment.LoadEnrichments()

// Initialize the Actions
log.Info("Adding NooP Action")
actMap := action.GetActionMap()
actMap.Add("NOOP_ACTION", action.NoopAction)
action.LoadActions()

b, err := os.ReadFile(cFile)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions enrichment/enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ type EnrichmentLut map[string]EnrichmentFunc
func (flut EnrichmentLut) Add(fname string, f EnrichmentFunc) {
flut[fname] = f
}

// Use this function to load all the defined enrichments in memory
// is not goroutine safe
// todo: protect this with a mutex/sync.Once
func LoadEnrichments() {
enr := GetEnrichmentMap()
enr.Add("NOOP_ENRICHMENT", NoopEnrichment)
enr.Add("UPPER_CASE", UpperCaseEnrichment)

}
18 changes: 18 additions & 0 deletions enrichment/upperCaseEncrichment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package enrichment

import (
"alertmanager/logging"
"alertmanager/types"
"fmt"
"strings"
)

func UpperCaseEnrichment(alert types.Alert, e types.Enrichment) (interface{}, error) {
logr := logging.GetLogger()

rs := fmt.Sprintf("upper-case enrichment called: \nalert: %s\nenrichment: %s\nwith args: %s", alert.AlertName, e.EnrichmentName, e.EnrichmentArgs)

logr.Debug(rs)

return strings.ToUpper(e.EnrichmentArgs), nil
}

0 comments on commit eef23f0

Please sign in to comment.