Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entity_display_name for VictorOps, use better state_message #769

Merged
merged 4 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add entity_display_name for VictorOps, use better state_message
  • Loading branch information
Siavash Safi committed Jun 29, 2017
commit abcc5e48d84a4c19fef7802fa50503195c9304b0
20 changes: 11 additions & 9 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ var (
NotifierConfig: NotifierConfig{
VSendResolved: true,
},
MessageType: `CRITICAL`,
StateMessage: `{{ template "victorops.default.state_message" . }}`,
MonitoringTool: `{{ template "victorops.default.monitoring_tool" . }}`,
MessageType: `CRITICAL`,
StateMessage: `{{ template "victorops.default.state_message" . }}`,
EntityDisplayName: `{{ template "victorops.default.entity_display_name" . }}`,
MonitoringTool: `{{ template "victorops.default.monitoring_tool" . }}`,
}

// DefaultPushoverConfig defines default values for Pushover configurations.
Expand Down Expand Up @@ -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:"-"`
}
Expand Down
18 changes: 10 additions & 8 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,11 @@ const (
)

type victorOpsMessage struct {
MessageType string `json:"message_type"`
EntityID string `json:"entity_id"`
StateMessage string `json:"state_message"`
MonitoringTool string `json:"monitoring_tool"`
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"`
}

type victorOpsErrorResponse struct {
Expand Down Expand Up @@ -819,10 +820,11 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error
}

msg := &victorOpsMessage{
MessageType: messageType,
EntityID: hashKey(key),
StateMessage: tmpl(n.conf.StateMessage),
MonitoringTool: tmpl(n.conf.MonitoringTool),
MessageType: messageType,
EntityID: hashKey(key),
EntityDisplayName: tmpl(n.conf.EntityDisplayName),
StateMessage: tmpl(n.conf.StateMessage),
MonitoringTool: tmpl(n.conf.MonitoringTool),
}

if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions template/default.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ Alerts Resolved:
{{ define "opsgenie.default.source" }}{{ template "__alertmanagerURL" . }}{{ end }}


{{ define "victorops.default.state_message" }}{{ template "__subject" . }} | {{ template "__alertmanagerURL" . }}{{ end }}
{{ define "victorops.default.monitoring_tool" }}{{ template "__alertmanager" . }}{{ end }}
{{ define "victorops.default.state_message" }}{{ template "__alertmanager" . }}: {{ template "__alertmanagerURL" . }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't create additional default formats, use what we already have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using __subject as entity_display_name now, and using a more verbose state_message(similar to opsgenie.default.description) instead of __subject.
In other words having __subject in 2 different fields is not very useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to maintain a format per notifier is not desirable, this should be a copy (preferably a template) of what we already have for this type of long-form field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, I will use the same template used for opsgenie.default.description.


{{ 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" }}
Expand Down