Populate details from common labels and details
Signed-off-by: ricoberger <mail@ricoberger.de>
This commit is contained in:
parent
8248c50365
commit
9a87f5c113
|
@ -456,17 +456,17 @@ 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"`
|
||||
DetailsUseCommonLabels bool `yaml:"details_use_common_labels,omitempty" json:"details_use_common_labels,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"`
|
||||
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
|
||||
CommonLabelsAsDetails bool `yaml:"common_labels_as_details,omitempty" json:"common_labels_as_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)$`
|
||||
|
@ -492,10 +492,6 @@ func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
|||
}
|
||||
}
|
||||
|
||||
if c.Details != nil && c.DetailsUseCommonLabels == true {
|
||||
return errors.Errorf("OpsGenieConfig can only contain details or details_use_common_labels, but both fields were provided")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -120,18 +120,16 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http
|
|||
|
||||
tmpl := notify.TmplText(n.tmpl, data, &err)
|
||||
|
||||
var details map[string]string
|
||||
details := make(map[string]string)
|
||||
|
||||
if n.conf.DetailsUseCommonLabels {
|
||||
details = make(map[string]string, len(data.CommonLabels))
|
||||
if n.conf.CommonLabelsAsDetails {
|
||||
for k, v := range data.CommonLabels {
|
||||
details[k] = v
|
||||
}
|
||||
} else {
|
||||
details = make(map[string]string, len(n.conf.Details))
|
||||
for k, v := range n.conf.Details {
|
||||
details[k] = tmpl(v)
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range n.conf.Details {
|
||||
details[k] = tmpl(v)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
Loading…
Reference in New Issue