Skip to content

Commit

Permalink
move action and enrichment to types
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 29, 2024
1 parent 334b3d7 commit e7a2345
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 60 deletions.
15 changes: 7 additions & 8 deletions action/action.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package action

type Action struct {
ActionName string `yaml:"action_name"`
ActionArgs string `yaml:"action_args"`
}

func GetDefaultAction() Action {
return Action{ActionName: "NOOP_ACTION", ActionArgs: "ARG1,ARG2"}
}
import "alertmanager/types"

var actionMap = make(ActionLut)

func GetActionMap() *ActionLut {
return &actionMap
}

type ActionLut map[string]func(types.Action, map[string]interface{}) error

func (flut ActionLut) Add(fname string, f func(types.Action, map[string]interface{}) error) {
flut[fname] = f
}
7 changes: 0 additions & 7 deletions action/actionLUT.go

This file was deleted.

3 changes: 2 additions & 1 deletion action/noopAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package action

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

func NoopAction(a Action, resultMap map[string]interface{}) error {
func NoopAction(a types.Action, resultMap map[string]interface{}) error {
logr := logging.GetLogger()
logr.Debug("noop action called")
rs := fmt.Sprintf("noop action called \n")
Expand Down
25 changes: 4 additions & 21 deletions alert/alert.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package alert

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

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

// fields we get from outside
Annotations map[string]string `json:"annotations"`
Expand All @@ -39,22 +38,6 @@ func (a *Alert) GetAlertName() string {
return a.alertName
}

func (a *Alert) GetActions() []action.Action {
return a.actions
}

func (a *Alert) SetActions(actions []action.Action) {
a.actions = actions
}

func (a *Alert) GetEnrichments() []enrichment.Enrichment {
return a.enrichments
}

func (a *Alert) SetEnrichments(enrichments []enrichment.Enrichment) {
a.enrichments = enrichments
}

func (c AlertGroup) String() string {
s, _ := json.Marshal(c)
// we dont need to look at this error as we are marshalling a struct.
Expand Down
15 changes: 7 additions & 8 deletions enrichment/enrichment.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package enrichment

type Enrichment struct {
EnrichmentName string `yaml:"enrichment_name"`
EnrichmentArgs string `yaml:"enrichment_args"`
}

func GetDefaultEnrichment() Enrichment {
return Enrichment{EnrichmentName: "NOOP_ENRICHMENT", EnrichmentArgs: "ARG1,ARG2"}
}
import "alertmanager/types"

var enrichmentMap = make(EnrichmentLut)

func GetEnrichmentMap() *EnrichmentLut {
return &enrichmentMap
}

type EnrichmentLut map[string]func(types.Enrichment) (interface{}, error)

func (flut EnrichmentLut) Add(fname string, f func(types.Enrichment) (interface{}, error)) {
flut[fname] = f
}
7 changes: 0 additions & 7 deletions enrichment/enrichmentLUT.go

This file was deleted.

3 changes: 2 additions & 1 deletion enrichment/noopEnrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package enrichment

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

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

rs := fmt.Sprint("noop enrichment called with : ", e.EnrichmentArgs)
Expand Down
10 changes: 10 additions & 0 deletions types/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

type Action struct {
ActionName string `yaml:"action_name"`
ActionArgs string `yaml:"action_args"`
}

func GetDefaultAction() Action {
return Action{ActionName: "NOOP_ACTION", ActionArgs: "ARG1,ARG2"}
}
12 changes: 5 additions & 7 deletions types/alertManagerConfig.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"alertmanager/action"
"alertmanager/enrichment"
"alertmanager/logging"

"gopkg.in/yaml.v3"
Expand All @@ -13,16 +11,16 @@ type AlertManagerConfig struct {
}

type AlertPipelineConfig struct {
AlertName string `yaml:"alert_name"`
Enrichments []enrichment.Enrichment `yaml:"enrichments"`
Actions []action.Action `yaml:"actions"`
AlertName string `yaml:"alert_name"`
Enrichments []Enrichment `yaml:"enrichments"`
Actions []Action `yaml:"actions"`
}

func DefaultAlertPipelineConfig() AlertPipelineConfig {
return AlertPipelineConfig{
AlertName: "NOOP_ALERT",
Enrichments: []enrichment.Enrichment{enrichment.GetDefaultEnrichment()},
Actions: []action.Action{action.GetDefaultAction()},
Enrichments: []Enrichment{GetDefaultEnrichment()},
Actions: []Action{GetDefaultAction()},
}
}

Expand Down
10 changes: 10 additions & 0 deletions types/enrichment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

type Enrichment struct {
EnrichmentName string `yaml:"enrichment_name"`
EnrichmentArgs string `yaml:"enrichment_args"`
}

func GetDefaultEnrichment() Enrichment {
return Enrichment{EnrichmentName: "NOOP_ENRICHMENT", EnrichmentArgs: "ARG1,ARG2"}
}

0 comments on commit e7a2345

Please sign in to comment.