Skip to content

Commit

Permalink
fix(alertmanager-extra): trim names and values before checking them
Browse files Browse the repository at this point in the history
Signed-off-by: Lyonel Martinez <[email protected]>
  • Loading branch information
Lowaiz authored and poiana committed Jul 18, 2023
1 parent 714e4bf commit dbe8ed7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,11 @@ func getConfig() *types.Configuration {
extraLabels := strings.Split(value, ",")
for _, labelData := range extraLabels {
labelName, labelValue, found := strings.Cut(labelData, ":")
labelName, labelValue = strings.TrimSpace(labelName), strings.TrimSpace(labelValue)
if !promKVNameRegex.MatchString(labelName) {
log.Printf("[ERROR] : AlertManager - Extra label name '%v' is not valid", labelName)
} else if found {
c.Alertmanager.ExtraLabels[labelName] = strings.TrimSpace(labelValue)
c.Alertmanager.ExtraLabels[labelName] = labelValue
} else {
c.Alertmanager.ExtraLabels[labelName] = ""
}
Expand All @@ -566,10 +567,11 @@ func getConfig() *types.Configuration {
extraAnnotations := strings.Split(value, ",")
for _, annotationData := range extraAnnotations {
annotationName, annotationValue, found := strings.Cut(annotationData, ":")
annotationName, annotationValue = strings.TrimSpace(annotationName), strings.TrimSpace(annotationValue)
if !promKVNameRegex.MatchString(annotationName) {
log.Printf("[ERROR] : AlertManager - Extra annotation name '%v' is not valid", annotationName)
} else if found {
c.Alertmanager.ExtraAnnotations[annotationName] = strings.TrimSpace(annotationValue)
c.Alertmanager.ExtraAnnotations[annotationName] = annotationValue
} else {
c.Alertmanager.ExtraAnnotations[annotationName] = ""
}
Expand Down

0 comments on commit dbe8ed7

Please sign in to comment.