示例#1
0
func newFlowdockMessage(op notificationOp, config *pb.FlowdockConfig, a *Alert) (*flowdockMessage, error) {
	status := ""
	switch op {
	case notificationOpTrigger:
		status = "firing"
	case notificationOpResolve:
		status = "resolved"
	}
	contentBuf := &bytes.Buffer{}
	err := contentTmpl.Execute(contentBuf, struct{ Alert *Alert }{Alert: a})
	if err != nil {
		return nil, err
	}

	msg := &flowdockMessage{
		Source:      "Prometheus",
		FromAddress: config.GetFromAddress(),
		Subject:     html.EscapeString(a.Summary),
		Format:      "html",
		Content:     contentBuf.String(),
		Link:        a.Payload["generatorURL"],
		Tags:        append(config.GetTag(), status),
	}
	return msg, nil
}
示例#2
0
func (n *notifier) sendFlowdockNotification(op notificationOp, config *pb.FlowdockConfig, a *Alert) error {
	flowdockMessage := newFlowdockMessage(op, config, a)
	url := strings.TrimRight(*flowdockURL, "/") + "/" + config.GetApiToken()
	jsonMessage, err := json.Marshal(flowdockMessage)
	if err != nil {
		return err
	}
	httpResponse, err := postJSON(jsonMessage, url)
	if err != nil {
		return err
	}
	if err := processResponse(httpResponse, "Flowdock", a); err != nil {
		return err
	}
	return nil
}
示例#3
0
func newFlowdockMessage(op notificationOp, config *pb.FlowdockConfig, a *Alert) *flowdockMessage {
	status := ""
	switch op {
	case notificationOpTrigger:
		status = "firing"
	case notificationOpResolve:
		status = "resolved"
	}

	msg := &flowdockMessage{
		Source:      "Prometheus",
		FromAddress: config.GetFromAddress(),
		Subject:     html.EscapeString(a.Summary),
		Format:      "html",
		Content:     fmt.Sprintf("*%s %s*: %s (<%s|view>)", html.EscapeString(a.Labels["alertname"]), status, html.EscapeString(a.Summary), a.Payload["generatorURL"]),
		Link:        a.Payload["generatorURL"],
		Tags:        append(config.GetTag(), status),
	}
	return msg
}