v1

package
v0.0.0-release-12.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const NoopURL = "grafana://noop"
View Source
const Version = schema.V1

Variables

View Source
var FullValidConfigForTesting = fmt.Sprintf(`{
	"url": %q,
	"httpMethod": "PUT",
	"maxAlerts": "2",
	"authorization_scheme": "basic",
	"authorization_credentials": "",
	"username": "test-user",
	"password": "test-pass",
	"title": "test-title",
	"message": "test-message",
	"tlsConfig": {
		"insecureSkipVerify": false,
		"clientCertificate": %q,
		"clientKey": %q,
		"caCertificate": %q
	},
	"hmacConfig": {
		"secret": "test-hmac-secret",
		"header": "X-Grafana-Alerting-Signature",
		"timestampHeader": "X-Grafana-Alerting-Timestamp"
	}
}`, NoopURL, http.TestCertPem, http.TestKeyPem, http.TestCACert)

FullValidConfigForTesting is a string representation of a JSON object that contains all fields supported by the notifier Config. It can be used without secrets.

View Source
var FullValidSecretsForTesting = fmt.Sprintf(`{
	"username": "test-secret-user",
	"password": "test-secret-pass",
	"tlsConfig.clientCertificate": %q,
	"tlsConfig.clientKey": %q,
	"tlsConfig.caCertificate": %q,
	"hmacConfig.secret": "test-override-hmac-secret"
}`, http.TestCertPem, http.TestKeyPem, http.TestCACert)

FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets

View Source
var Schema = schema.IntegrationSchemaVersion{
	Version:   Version,
	CanCreate: true,
	Options: []schema.Field{
		{
			Label:        "URL",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			PropertyName: "url",
			Required:     true,
			Protected:    true,
		},
		{
			Label:   "HTTP Method",
			Element: schema.ElementTypeSelect,
			SelectOptions: []schema.SelectOption{
				{
					Value: "POST",
					Label: "POST",
				},
				{
					Value: "PUT",
					Label: "PUT",
				},
			},
			PropertyName: "httpMethod",
		},
		{
			Label:        "HTTP Basic Authentication - Username",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			PropertyName: "username",
		},
		{
			Label:        "HTTP Basic Authentication - Password",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypePassword,
			PropertyName: "password",
			Secure:       true,
		},
		{
			Label:        "Authorization Header - Scheme",
			Description:  "Optionally provide a scheme for the Authorization Request Header. Default is Bearer.",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			PropertyName: "authorization_scheme",
			Placeholder:  "Bearer",
		},
		{
			Label:        "Authorization Header - Credentials",
			Description:  "Credentials for the Authorization Request header. Only one of HTTP Basic Authentication or Authorization Request Header can be set.",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			PropertyName: "authorization_credentials",
			Secure:       true,
		},
		{
			Label:        "Extra Headers",
			Description:  "Optionally provide extra headers to be used in the request.",
			Element:      schema.ElementTypeKeyValueMap,
			InputType:    schema.InputTypeText,
			PropertyName: "headers",
		},
		{
			Label:        "Max Alerts",
			Description:  "Max alerts to include in a notification. Remaining alerts in the same batch will be ignored above this number. 0 means no limit.",
			Element:      schema.ElementTypeInput,
			InputType:    schema.InputTypeText,
			PropertyName: "maxAlerts",
		},
		{
			Label:        "Title",
			Description:  "Templated title of the message.",
			Element:      schema.ElementTypeTextArea,
			InputType:    schema.InputTypeText,
			PropertyName: "title",
			Placeholder:  templates.DefaultMessageTitleEmbed,
		},
		{
			Label:        "Message",
			Description:  "Templated message to be used in the payload's \"message\" field.",
			Element:      schema.ElementTypeTextArea,
			PropertyName: "message",
			Placeholder:  templates.DefaultMessageEmbed,
		},
		{
			Label:        "Custom Payload",
			Description:  "Optionally provide a templated payload. Overrides 'Message' and 'Title' field.",
			Element:      schema.ElementTypeSubform,
			PropertyName: "payload",
			SubformOptions: []schema.Field{
				{
					Label:        "Payload Template",
					Description:  "Custom payload template.",
					Element:      schema.ElementTypeTextArea,
					PropertyName: "template",
					Placeholder:  `{{ template "webhook.default.payload" . }}`,
					Required:     true,
				},
				{
					Label:        "Payload Variables",
					Description:  "Optionally provide a variables to be used in the payload template. They will be available in the template as `.Vars.<variable_name>`.",
					Element:      schema.ElementTypeKeyValueMap,
					InputType:    schema.InputTypeText,
					PropertyName: "vars",
				},
			},
		},

		{
			Label:          "TLS",
			PropertyName:   "tlsConfig",
			Description:    "TLS configuration options",
			Element:        schema.ElementTypeSubform,
			SubformOptions: schema.V1TLSSubformOptions(),
		},
		{
			Label:        "HMAC Signature",
			PropertyName: "hmacConfig",
			Description:  "HMAC signature configuration options",
			Element:      schema.ElementTypeSubform,
			SubformOptions: []schema.Field{
				{
					Label:        "Secret",
					Element:      schema.ElementTypeInput,
					Description:  "",
					InputType:    schema.InputTypeText,
					PropertyName: "secret",
					Required:     true,
					Secure:       true,
				},
				{
					Label:        "Header",
					Element:      schema.ElementTypeInput,
					Description:  "The header in which the HMAC signature will be included.",
					InputType:    schema.InputTypeText,
					PropertyName: "header",
					Placeholder:  "X-Grafana-Alerting-Signature",
					Required:     false,
					Secure:       false,
				},
				{
					Label:        "Timestamp header",
					Element:      schema.ElementTypeInput,
					Description:  "If set, the timestamp will be included in the HMAC signature. The value should be the name of the header to use.",
					InputType:    schema.InputTypeText,
					PropertyName: "timestampHeader",
					Required:     false,
					Secure:       false,
				},
			},
		},
		schema.V1HttpClientOption(),
	},
}

Functions

func OmitRestrictedHeaders

func OmitRestrictedHeaders(headers map[string]string) (map[string]string, []string)

OmitRestrictedHeaders returns new headers with restricted custom headers omitted. The exact risk of allowing customization of these headers is not clear, but it is better to be safe at first pass. We can always loosen the restrictions later if we find that it is not a problem. Returns the new headers and a list of omitted headers.

Types

type Config

type Config struct {
	URL        string
	HTTPMethod string
	MaxAlerts  int
	// Authorization Header.
	AuthorizationScheme      string
	AuthorizationCredentials string
	// HTTP Basic Authentication.
	User         string
	Password     string
	ExtraHeaders map[string]string

	Title      string
	Message    string
	TLSConfig  *receivers.TLSConfig
	HMACConfig *receivers.HMACConfig

	Payload CustomPayload
}

func NewConfig

func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error)

type CustomPayload

type CustomPayload struct {
	// Template is the template used to generate the payload for the webhook.
	Template string `json:"template,omitempty" yaml:"template,omitempty"`

	// Vars is a map of variables that can be used in the payload template. This is useful for providing
	// additional context to the payload template without storing it in the template itself.
	// Variables are accessible in the template through `.Vars.<key>`.
	Vars map[string]string `json:"vars,omitempty" yaml:"vars,omitempty"`
}

type Notifier

type Notifier struct {
	*receivers.Base
	// contains filtered or unexported fields
}

Notifier is responsible for sending alert notifications as webhooks.

func New

func New(cfg Config, meta receivers.Metadata, template *templates.Template, sender receivers.WebhookSender, images images.Provider, logger log.Logger, orgID int64) *Notifier

New is the constructor for the WebHook notifier.

func (*Notifier) Notify

func (wn *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)

Notify implements the Notifier interface.

func (*Notifier) SendResolved

func (wn *Notifier) SendResolved() bool

Jump to

Keyboard shortcuts

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