diff --git a/config/notifiers.go b/config/notifiers.go index 82829ded..f8896436 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -456,16 +456,18 @@ type OpsGenieConfig struct { HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` - APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` - APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` - Message string `yaml:"message,omitempty" json:"message,omitempty"` - Description string `yaml:"description,omitempty" json:"description,omitempty"` - Source string `yaml:"source,omitempty" json:"source,omitempty"` - Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` - Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` - Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` - Note string `yaml:"note,omitempty" json:"note,omitempty"` - Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` + APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"` + APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` + Message string `yaml:"message,omitempty" json:"message,omitempty"` + Description string `yaml:"description,omitempty" json:"description,omitempty"` + Source string `yaml:"source,omitempty" json:"source,omitempty"` + AllLabelsAsDetails bool `yaml:"all_labels_as_details,omitempty" json:"all_labels_as_details,omitempty"` + LabelsAsDetails []string `yaml:"labels_as_details,omitempty" json:"labels_as_details,omitempty"` + Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"` + Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"` + Tags string `yaml:"tags,omitempty" json:"tags,omitempty"` + Note string `yaml:"note,omitempty" json:"note,omitempty"` + Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` } const opsgenieValidTypesRe = `^(team|user|escalation|schedule)$` diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 078fcc62..dcb5d1e9 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -120,9 +120,27 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http tmpl := notify.TmplText(n.tmpl, data, &err) - details := make(map[string]string, len(n.conf.Details)) - for k, v := range n.conf.Details { - details[k] = tmpl(v) + var details map[string]string + + if n.conf.AllLabelsAsDetails { + details = make(map[string]string, len(data.CommonLabels)) + for k, v := range data.CommonLabels { + details[k] = v + } + } else if len(n.conf.LabelsAsDetails) > 0 { + details = make(map[string]string, len(n.conf.LabelsAsDetails)) + for _, k := range n.conf.LabelsAsDetails { + if v, ok := data.CommonLabels[k]; ok { + details[k] = v + } else { + details[k] = "N/A" + } + } + } else { + details = make(map[string]string, len(n.conf.Details)) + for k, v := range n.conf.Details { + details[k] = tmpl(v) + } } var (