Added support for @mentions in HipChat notifications
This commit is contained in:
parent
8d205b2a27
commit
2d7992a59b
|
@ -54,6 +54,14 @@ message HipChatConfig {
|
|||
optional bool notify = 4 [default = false];
|
||||
// Notify when resolved.
|
||||
optional bool send_resolved = 6 [default = false];
|
||||
// Prefix to be put in front of the message (useful for @mentions, etc.).
|
||||
optional string prefix = 7 [default = ""];
|
||||
// Format the message as "html" or "text".
|
||||
enum MessageFormat {
|
||||
HTML = 0;
|
||||
TEXT = 1;
|
||||
}
|
||||
optional MessageFormat message_format = 8 [default = HTML];
|
||||
}
|
||||
|
||||
// Configuration for notification via Slack.
|
||||
|
|
|
@ -30,6 +30,40 @@ import math "math"
|
|||
var _ = proto.Marshal
|
||||
var _ = math.Inf
|
||||
|
||||
// Format the message as "html" or "text".
|
||||
type HipChatConfig_MessageFormat int32
|
||||
|
||||
const (
|
||||
HipChatConfig_HTML HipChatConfig_MessageFormat = 0
|
||||
HipChatConfig_TEXT HipChatConfig_MessageFormat = 1
|
||||
)
|
||||
|
||||
var HipChatConfig_MessageFormat_name = map[int32]string{
|
||||
0: "HTML",
|
||||
1: "TEXT",
|
||||
}
|
||||
var HipChatConfig_MessageFormat_value = map[string]int32{
|
||||
"HTML": 0,
|
||||
"TEXT": 1,
|
||||
}
|
||||
|
||||
func (x HipChatConfig_MessageFormat) Enum() *HipChatConfig_MessageFormat {
|
||||
p := new(HipChatConfig_MessageFormat)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
func (x HipChatConfig_MessageFormat) String() string {
|
||||
return proto.EnumName(HipChatConfig_MessageFormat_name, int32(x))
|
||||
}
|
||||
func (x *HipChatConfig_MessageFormat) UnmarshalJSON(data []byte) error {
|
||||
value, err := proto.UnmarshalJSONEnum(HipChatConfig_MessageFormat_value, data, "HipChatConfig_MessageFormat")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = HipChatConfig_MessageFormat(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Configuration for notification via PagerDuty.
|
||||
type PagerDutyConfig struct {
|
||||
// PagerDuty service key, see:
|
||||
|
@ -129,8 +163,11 @@ type HipChatConfig struct {
|
|||
// Should this message notify or not.
|
||||
Notify *bool `protobuf:"varint,4,opt,name=notify,def=0" json:"notify,omitempty"`
|
||||
// Notify when resolved.
|
||||
SendResolved *bool `protobuf:"varint,6,opt,name=send_resolved,def=0" json:"send_resolved,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
SendResolved *bool `protobuf:"varint,6,opt,name=send_resolved,def=0" json:"send_resolved,omitempty"`
|
||||
// Prefix to be put in front of the message (useful for @mentions, etc.).
|
||||
Prefix *string `protobuf:"bytes,7,opt,name=prefix,def=" json:"prefix,omitempty"`
|
||||
MessageFormat *HipChatConfig_MessageFormat `protobuf:"varint,8,opt,name=message_format,enum=io.prometheus.alertmanager.HipChatConfig_MessageFormat,def=0" json:"message_format,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *HipChatConfig) Reset() { *m = HipChatConfig{} }
|
||||
|
@ -141,6 +178,7 @@ const Default_HipChatConfig_Color string = "purple"
|
|||
const Default_HipChatConfig_ColorResolved string = "green"
|
||||
const Default_HipChatConfig_Notify bool = false
|
||||
const Default_HipChatConfig_SendResolved bool = false
|
||||
const Default_HipChatConfig_MessageFormat HipChatConfig_MessageFormat = HipChatConfig_HTML
|
||||
|
||||
func (m *HipChatConfig) GetAuthToken() string {
|
||||
if m != nil && m.AuthToken != nil {
|
||||
|
@ -184,6 +222,20 @@ func (m *HipChatConfig) GetSendResolved() bool {
|
|||
return Default_HipChatConfig_SendResolved
|
||||
}
|
||||
|
||||
func (m *HipChatConfig) GetPrefix() string {
|
||||
if m != nil && m.Prefix != nil {
|
||||
return *m.Prefix
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *HipChatConfig) GetMessageFormat() HipChatConfig_MessageFormat {
|
||||
if m != nil && m.MessageFormat != nil {
|
||||
return *m.MessageFormat
|
||||
}
|
||||
return Default_HipChatConfig_MessageFormat
|
||||
}
|
||||
|
||||
// Configuration for notification via Slack.
|
||||
type SlackConfig struct {
|
||||
// Slack webhook url, (https://api.slack.com/incoming-webhooks).
|
||||
|
@ -554,4 +606,5 @@ func (m *AlertManagerConfig) GetInhibitRule() []*InhibitRule {
|
|||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("io.prometheus.alertmanager.HipChatConfig_MessageFormat", HipChatConfig_MessageFormat_name, HipChatConfig_MessageFormat_value)
|
||||
}
|
||||
|
|
|
@ -190,6 +190,8 @@ func (n *notifier) sendHipChatNotification(op notificationOp, config *pb.HipChat
|
|||
incidentKey := a.Fingerprint()
|
||||
color := ""
|
||||
status := ""
|
||||
message := ""
|
||||
messageFormat := ""
|
||||
switch op {
|
||||
case notificationOpTrigger:
|
||||
color = config.GetColor()
|
||||
|
@ -198,11 +200,18 @@ func (n *notifier) sendHipChatNotification(op notificationOp, config *pb.HipChat
|
|||
color = config.GetColorResolved()
|
||||
status = "resolved"
|
||||
}
|
||||
if config.GetMessageFormat() == pb.HipChatConfig_TEXT {
|
||||
message = fmt.Sprintf("%s%s %s: %s", config.GetPrefix(), a.Labels["alertname"], status, a.Summary)
|
||||
messageFormat = "text"
|
||||
} else {
|
||||
message = fmt.Sprintf("%s<b>%s %s</b>: %s (<a href='%s'>view</a>)", config.GetPrefix(), html.EscapeString(a.Labels["alertname"]), status, html.EscapeString(a.Summary), a.Payload["GeneratorURL"])
|
||||
messageFormat = "html"
|
||||
}
|
||||
buf, err := json.Marshal(map[string]interface{}{
|
||||
"color": color,
|
||||
"message": fmt.Sprintf("<b>%s %s</b>: %s (<a href='%s'>view</a>)", html.EscapeString(a.Labels["alertname"]), status, html.EscapeString(a.Summary), a.Payload["GeneratorURL"]),
|
||||
"message": message,
|
||||
"notify": config.GetNotify(),
|
||||
"message_format": "html",
|
||||
"message_format": messageFormat,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue