Skip to content

Commit ffff501

Browse files
committed
pkg/csprofiles: default duration and type for partial configuration
1 parent c1e858c commit ffff501

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/csprofiles/csprofiles.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type Runtime struct {
2121
Logger *log.Entry `json:"-" yaml:"-"`
2222
}
2323

24-
const defaultDuration = "4h"
24+
const (
25+
defaultDuration = "4h"
26+
defaultType = "ban"
27+
)
2528

2629
func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
2730
var err error
@@ -77,7 +80,7 @@ func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
7780
for _, decision := range profile.Decisions {
7881
if runtime.RuntimeDurationExpr == nil {
7982
var duration string
80-
if decision.Duration != nil {
83+
if decision.Duration != nil && *decision.Duration != "" {
8184
duration = *decision.Duration
8285
} else {
8386
runtime.Logger.Warningf("No duration specified for %s, using default duration %s", profile.Name, defaultDuration)
@@ -121,8 +124,10 @@ func (Profile *Runtime) GenerateDecisionFromProfile(Alert *models.Alert) ([]*mod
121124
/*some fields are populated from the reference object : duration, scope, type*/
122125

123126
decision.Duration = new(string)
124-
if refDecision.Duration != nil {
127+
if refDecision.Duration != nil && *refDecision.Duration != "" {
125128
*decision.Duration = *refDecision.Duration
129+
} else {
130+
*decision.Duration = defaultDuration
126131
}
127132

128133
if Profile.Cfg.DurationExpr != "" && Profile.RuntimeDurationExpr != nil {
@@ -145,7 +150,11 @@ func (Profile *Runtime) GenerateDecisionFromProfile(Alert *models.Alert) ([]*mod
145150
}
146151

147152
decision.Type = new(string)
148-
*decision.Type = *refDecision.Type
153+
if refDecision.Type != nil && *refDecision.Type != "" {
154+
*decision.Type = *refDecision.Type
155+
} else {
156+
*decision.Type = defaultType
157+
}
149158

150159
/*for the others, let's populate it from the alert and its source*/
151160
decision.Value = new(string)

0 commit comments

Comments
 (0)