diff --git a/action/action.go b/action/action.go index 8beaff3..fdfb9de 100644 --- a/action/action.go +++ b/action/action.go @@ -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) +} diff --git a/alert-manager-config.yml b/alert-manager-config.yml index 8848e2e..1bbad99 100644 --- a/alert-manager-config.yml +++ b/alert-manager-config.yml @@ -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 diff --git a/alert/processAlert.go b/alert/processAlert.go index 32de604..ad17fda 100644 --- a/alert/processAlert.go +++ b/alert/processAlert.go @@ -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) } } @@ -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) } } } diff --git a/cmd/server.go b/cmd/server.go index 5cd0b13..854032d 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -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 { diff --git a/enrichment/enrichment.go b/enrichment/enrichment.go index 4e51e86..433f5bd 100644 --- a/enrichment/enrichment.go +++ b/enrichment/enrichment.go @@ -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) + +} diff --git a/enrichment/upperCaseEncrichment.go b/enrichment/upperCaseEncrichment.go new file mode 100644 index 0000000..dcfe4f8 --- /dev/null +++ b/enrichment/upperCaseEncrichment.go @@ -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 +}