mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-16 10:37:09 +00:00
Add check for templated Opsgenie receiver config (#3060)
* Add check for templated Opsgenie receiver config Solves #2887, where Opsgenie responder type can be templated according to docs, but configuration logic checked for specific list of values only. Signed-off-by: Erki Esken <erki@esken.net> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
1b202b91bf
commit
9ae611329a
@ -18,6 +18,7 @@ import (
|
|||||||
"net/textproto"
|
"net/textproto"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -541,9 +542,16 @@ func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
|||||||
return errors.Errorf("opsGenieConfig responder %v has to have at least one of id, username or name specified", r)
|
return errors.Errorf("opsGenieConfig responder %v has to have at least one of id, username or name specified", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Type = strings.ToLower(r.Type)
|
if strings.Contains(r.Type, "{{") {
|
||||||
if !opsgenieTypeMatcher.MatchString(r.Type) {
|
_, err := template.New("").Parse(r.Type)
|
||||||
return errors.Errorf("opsGenieConfig responder %v type does not match valid options %s", r, opsgenieValidTypesRe)
|
if err != nil {
|
||||||
|
return errors.Errorf("opsGenieConfig responder %v type is not a valid template: %v", r, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
r.Type = strings.ToLower(r.Type)
|
||||||
|
if !opsgenieTypeMatcher.MatchString(r.Type) {
|
||||||
|
return errors.Errorf("opsGenieConfig responder %v type does not match valid options %s", r, opsgenieValidTypesRe)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,6 +743,25 @@ api_url: http://example.com
|
|||||||
responders:
|
responders:
|
||||||
- type: schedule
|
- type: schedule
|
||||||
api_url: http://example.com
|
api_url: http://example.com
|
||||||
|
`,
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "valid responder type template",
|
||||||
|
in: `api_key: xyz
|
||||||
|
responders:
|
||||||
|
- id: foo
|
||||||
|
type: "{{/* valid comment */}}team"
|
||||||
|
api_url: http://example.com
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid responder type template",
|
||||||
|
in: `api_key: xyz
|
||||||
|
responders:
|
||||||
|
- id: foo
|
||||||
|
type: "{{/* invalid comment }}team"
|
||||||
|
api_url: http://example.com
|
||||||
`,
|
`,
|
||||||
err: true,
|
err: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user