Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alertmanager-extra): trim names and values before checking them #563

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading