mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-25 15:42:18 +00:00
Add entity_display_name for VictorOps, use better state_message (#769)
* Add entity_display_name for VictorOps, use better state_message * Reuse existing long-form templates for state_message * Rebuild binaries * Limit state_message to 20K
This commit is contained in:
parent
41c5aaf3f4
commit
d5f0d1773f
@ -100,6 +100,7 @@ var (
|
||||
},
|
||||
MessageType: `CRITICAL`,
|
||||
StateMessage: `{{ template "victorops.default.state_message" . }}`,
|
||||
EntityDisplayName: `{{ template "victorops.default.entity_display_name" . }}`,
|
||||
MonitoringTool: `{{ template "victorops.default.monitoring_tool" . }}`,
|
||||
}
|
||||
|
||||
@ -321,12 +322,13 @@ func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||
type VictorOpsConfig struct {
|
||||
NotifierConfig `yaml:",inline" json:",inline"`
|
||||
|
||||
APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"`
|
||||
APIURL string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
||||
RoutingKey string `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
|
||||
MessageType string `yaml:"message_type,omitempty" json:"message_type,omitempty"`
|
||||
StateMessage string `yaml:"state_message,omitempty" json:"state_message,omitempty"`
|
||||
MonitoringTool string `yaml:"monitoring_tool,omitempty" json:"monitoring_tool,omitempty"`
|
||||
APIKey Secret `yaml:"api_key" json:"api_key"`
|
||||
APIURL string `yaml:"api_url" json:"api_url"`
|
||||
RoutingKey string `yaml:"routing_key" json:"routing_key"`
|
||||
MessageType string `yaml:"message_type" json:"message_type"`
|
||||
StateMessage string `yaml:"state_message" json:"state_message"`
|
||||
EntityDisplayName string `yaml:"entity_display_name" json:"entity_display_name"`
|
||||
MonitoringTool string `yaml:"monitoring_tool" json:"monitoring_tool"`
|
||||
|
||||
XXX map[string]interface{} `yaml:",inline" json:"-"`
|
||||
}
|
||||
|
@ -779,6 +779,7 @@ const (
|
||||
type victorOpsMessage struct {
|
||||
MessageType string `json:"message_type"`
|
||||
EntityID string `json:"entity_id"`
|
||||
EntityDisplayName string `json:"entity_display_name"`
|
||||
StateMessage string `json:"state_message"`
|
||||
MonitoringTool string `json:"monitoring_tool"`
|
||||
}
|
||||
@ -808,6 +809,7 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error
|
||||
tmpl = tmplText(n.tmpl, data, &err)
|
||||
apiURL = fmt.Sprintf("%s%s/%s", n.conf.APIURL, n.conf.APIKey, n.conf.RoutingKey)
|
||||
messageType = n.conf.MessageType
|
||||
stateMessage = tmpl(n.conf.StateMessage)
|
||||
)
|
||||
|
||||
if alerts.Status() == model.AlertFiring && !victorOpsAllowedEvents[messageType] {
|
||||
@ -818,10 +820,15 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error
|
||||
messageType = victorOpsEventResolve
|
||||
}
|
||||
|
||||
if len(stateMessage) > 20480 {
|
||||
stateMessage = stateMessage[0:20475] + "\n..."
|
||||
}
|
||||
|
||||
msg := &victorOpsMessage{
|
||||
MessageType: messageType,
|
||||
EntityID: hashKey(key),
|
||||
StateMessage: tmpl(n.conf.StateMessage),
|
||||
EntityDisplayName: tmpl(n.conf.EntityDisplayName),
|
||||
StateMessage: stateMessage,
|
||||
MonitoringTool: tmpl(n.conf.MonitoringTool),
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,19 @@ Alerts Resolved:
|
||||
{{ define "opsgenie.default.source" }}{{ template "__alertmanagerURL" . }}{{ end }}
|
||||
|
||||
|
||||
{{ define "victorops.default.state_message" }}{{ template "__subject" . }} | {{ template "__alertmanagerURL" . }}{{ end }}
|
||||
{{ define "victorops.default.state_message" }}{{ .CommonAnnotations.SortedPairs.Values | join " " }}
|
||||
{{ if gt (len .Alerts.Firing) 0 -}}
|
||||
Alerts Firing:
|
||||
{{ template "__text_alert_list" .Alerts.Firing }}
|
||||
{{- end }}
|
||||
{{ if gt (len .Alerts.Resolved) 0 -}}
|
||||
Alerts Resolved:
|
||||
{{ template "__text_alert_list" .Alerts.Resolved }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ define "victorops.default.entity_display_name" }}{{ template "__subject" . }}{{ end }}
|
||||
{{ define "victorops.default.monitoring_tool" }}{{ template "__alertmanager" . }}{{ end }}
|
||||
|
||||
|
||||
{{ define "email.default.subject" }}{{ template "__subject" . }}{{ end }}
|
||||
{{ define "email.default.html" }}
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user