alertmanager

package
v0.0.0-...-e61e643 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package alertmanager implements a Service capable of processing webhooks from prometheus alertmanager.

Index

Constants

View Source
const ServiceType = "alertmanager"

ServiceType of the Alertmanager service.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	types.DefaultService

	// The URL which should be added to alertmanagers config - Populated by Go-NEB after Service registration.
	WebhookURL string `json:"webhook_url"`
	// A map of matrix rooms to templates
	Rooms map[string]struct {
		TextTemplate string `json:"text_template"`
		HTMLTemplate string `json:"html_template"`
		MsgType      string `json:"msg_type"`
	} `json:"rooms"`
	// contains filtered or unexported fields
}

Service contains the Config fields for the Alertmanager service.

This service will send notifications into a Matrix room when Alertmanager sends webhook events to it. It requires a public domain which Alertmanager can reach. Notices will be sent as the service user ID.

For the template strings, take a look at https://golang.org/pkg/text/template/ and the html variant https://golang.org/pkg/html/template/. The data they get is a webhookNotification

You can set msg_type to either m.text or m.notice

Example JSON request:

{
    rooms: {
        "!ewfug483gsfe:localhost": {
            "text_template": "your plain text template goes here",
            "html_template": "your html template goes here",
            "msg_type": "m.text"
        },
    }
}

func (*Service) OnReceiveWebhook

func (s *Service) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli *gomatrix.Client)

OnReceiveWebhook receives requests from Alertmanager and sends requests to Matrix as a result.

func (*Service) PostRegister

func (s *Service) PostRegister(oldService types.Service)

PostRegister deletes this service if there are no registered repos.

func (*Service) Register

func (s *Service) Register(oldService types.Service, client *gomatrix.Client) error

Register makes sure the Config information supplied is valid.

type WebhookNotification

type WebhookNotification struct {
	Version           string            `json:"version"`
	GroupKey          string            `json:"groupKey"`
	Status            string            `json:"status"`
	Receiver          string            `json:"receiver"`
	GroupLabels       map[string]string `json:"groupLabels"`
	CommonLabels      map[string]string `json:"commonLabels"`
	CommonAnnotations map[string]string `json:"commonAnnotations"`
	ExternalUrl       string            `json:"externalURL"`
	Alerts            []struct {
		Status       string            `json:"status"`
		Labels       map[string]string `json:"labels"`
		Annotations  map[string]string `json:"annotations"`
		StartsAt     string            `json:"startsAt"`
		EndsAt       string            `json:"endsAt"`
		GeneratorUrl string            `json:"generatorURL"`
	} `json:"alerts"`
}

The payload from Alertmanager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL