mirror of
https://github.com/prometheus/alertmanager
synced 2025-03-01 09:10:58 +00:00
Add support for images and links in the PagerDuty notification config (#1559)
* Add support for images and links in the PagerDuty notification config This only works when using the v2 API. It supports template values for all fields. Signed-off-by: Sean Houghton <sean.houghton@activision.com>
This commit is contained in:
parent
d593562493
commit
c9e250dab1
@ -203,12 +203,27 @@ type PagerdutyConfig struct {
|
||||
ClientURL string `yaml:"client_url,omitempty" json:"client_url,omitempty"`
|
||||
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
||||
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
|
||||
Images []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
|
||||
Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
|
||||
Severity string `yaml:"severity,omitempty" json:"severity,omitempty"`
|
||||
Class string `yaml:"class,omitempty" json:"class,omitempty"`
|
||||
Component string `yaml:"component,omitempty" json:"component,omitempty"`
|
||||
Group string `yaml:"group,omitempty" json:"group,omitempty"`
|
||||
}
|
||||
|
||||
// PagerdutyLink is a link
|
||||
type PagerdutyLink struct {
|
||||
HRef string `yaml:"href,omitempty" json:"href,omitempty"`
|
||||
Text string `yaml:"text,omitempty" json:"text,omitempty"`
|
||||
}
|
||||
|
||||
// PagerdutyImage is an image
|
||||
type PagerdutyImage struct {
|
||||
Src string `yaml:"src,omitempty" json:"src,omitempty"`
|
||||
Alt string `yaml:"alt,omitempty" json:"alt,omitempty"`
|
||||
Text string `yaml:"text,omitempty" json:"text,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||
func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
*c = DefaultPagerdutyConfig
|
||||
|
@ -465,6 +465,19 @@ type pagerDutyMessage struct {
|
||||
Client string `json:"client,omitempty"`
|
||||
ClientURL string `json:"client_url,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
Images []pagerDutyImage `json:"images,omitempty"`
|
||||
Links []pagerDutyLink `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
type pagerDutyLink struct {
|
||||
HRef string `json:"href"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type pagerDutyImage struct {
|
||||
Src string `json:"src"`
|
||||
Alt string `json:"alt"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type pagerDutyPayload struct {
|
||||
@ -547,6 +560,8 @@ func (n *PagerDuty) notifyV2(
|
||||
RoutingKey: tmpl(string(n.conf.RoutingKey)),
|
||||
EventAction: eventType,
|
||||
DedupKey: hashKey(key),
|
||||
Images: make([]pagerDutyImage, len(n.conf.Images)),
|
||||
Links: make([]pagerDutyLink, len(n.conf.Links)),
|
||||
Payload: &pagerDutyPayload{
|
||||
Summary: tmpl(n.conf.Description),
|
||||
Source: tmpl(n.conf.Client),
|
||||
@ -558,6 +573,17 @@ func (n *PagerDuty) notifyV2(
|
||||
},
|
||||
}
|
||||
|
||||
for index, item := range n.conf.Images {
|
||||
msg.Images[index].Src = tmpl(item.Src)
|
||||
msg.Images[index].Alt = tmpl(item.Alt)
|
||||
msg.Images[index].Text = tmpl(item.Text)
|
||||
}
|
||||
|
||||
for index, item := range n.conf.Links {
|
||||
msg.Links[index].HRef = tmpl(item.HRef)
|
||||
msg.Links[index].Text = tmpl(item.Text)
|
||||
}
|
||||
|
||||
if tmplErr != nil {
|
||||
return false, fmt.Errorf("failed to template PagerDuty v2 message: %v", tmplErr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user