Adjust Opsgenie config for labels propagation
Signed-off-by: ricoberger <mail@ricoberger.de>
This commit is contained in:
parent
117c8ba8f1
commit
dcccf542f1
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
commoncfg "github.com/prometheus/common/config"
|
commoncfg "github.com/prometheus/common/config"
|
||||||
|
"github.com/prometheus/common/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -461,9 +462,9 @@ type OpsGenieConfig struct {
|
||||||
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
||||||
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
||||||
Source string `yaml:"source,omitempty" json:"source,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"`
|
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
|
||||||
|
DetailsLabels []string `yaml:"details_labels,omitempty" json:"details_labels,omitempty"`
|
||||||
|
DetailsLabelsAll bool `yaml:"-" json:"-"`
|
||||||
Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"`
|
Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"`
|
||||||
Tags string `yaml:"tags,omitempty" json:"tags,omitempty"`
|
Tags string `yaml:"tags,omitempty" json:"tags,omitempty"`
|
||||||
Note string `yaml:"note,omitempty" json:"note,omitempty"`
|
Note string `yaml:"note,omitempty" json:"note,omitempty"`
|
||||||
|
@ -493,6 +494,21 @@ func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.DetailsLabels != nil && c.Details != nil {
|
||||||
|
return errors.Errorf("OpsGenieConfig can only contain details or details_labels, but both fields were provided")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range c.DetailsLabels {
|
||||||
|
if l == "..." {
|
||||||
|
c.DetailsLabelsAll = true
|
||||||
|
} else {
|
||||||
|
labelName := model.LabelName(l)
|
||||||
|
if !labelName.IsValid() {
|
||||||
|
return errors.Errorf("invalid label name %q in details_labels list", l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,18 +122,20 @@ func (n *Notifier) createRequest(ctx context.Context, as ...*types.Alert) (*http
|
||||||
|
|
||||||
var details map[string]string
|
var details map[string]string
|
||||||
|
|
||||||
if n.conf.AllLabelsAsDetails {
|
if n.conf.DetailsLabelsAll {
|
||||||
details = make(map[string]string, len(data.CommonLabels))
|
details = make(map[string]string, len(data.CommonLabels))
|
||||||
for k, v := range data.CommonLabels {
|
for k, v := range data.CommonLabels {
|
||||||
details[k] = v
|
details[k] = v
|
||||||
}
|
}
|
||||||
} else if len(n.conf.LabelsAsDetails) > 0 {
|
} else if len(n.conf.DetailsLabels) > 0 {
|
||||||
details = make(map[string]string, len(n.conf.LabelsAsDetails))
|
details = make(map[string]string, len(n.conf.DetailsLabels))
|
||||||
for _, k := range n.conf.LabelsAsDetails {
|
for _, k := range n.conf.DetailsLabels {
|
||||||
if v, ok := data.CommonLabels[k]; ok {
|
label := string(k)
|
||||||
details[k] = v
|
|
||||||
|
if v, ok := data.CommonLabels[label]; ok {
|
||||||
|
details[label] = v
|
||||||
} else {
|
} else {
|
||||||
details[k] = "N/A"
|
details[label] = "N/A"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue