Make channels_config no longer depend on legacy alerting (#53799)

This commit is contained in:
Alexander Weaver 2022-08-19 11:21:02 -05:00 committed by GitHub
parent 0b322a0f5d
commit c7b93ec331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 231 additions and 169 deletions

View File

@ -1,13 +1,12 @@
package channels_config package channels_config
import ( import (
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/ngalert/notifier/channels" "github.com/grafana/grafana/pkg/services/ngalert/notifier/channels"
) )
// GetAvailableNotifiers returns the metadata of all the notification channels that can be configured. // GetAvailableNotifiers returns the metadata of all the notification channels that can be configured.
func GetAvailableNotifiers() []*alerting.NotifierPlugin { func GetAvailableNotifiers() []*NotifierPlugin {
pushoverSoundOptions := []alerting.SelectOption{ pushoverSoundOptions := []SelectOption{
{ {
Value: "default", Value: "default",
Label: "Default", Label: "Default",
@ -81,7 +80,7 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
} }
pushoverPriorityOptions := []alerting.SelectOption{ pushoverPriorityOptions := []SelectOption{
{ {
Value: "2", Value: "2",
Label: "Emergency", Label: "Emergency",
@ -104,26 +103,26 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
} }
return []*alerting.NotifierPlugin{ return []*NotifierPlugin{
{ {
Type: "dingding", Type: "dingding",
Name: "DingDing", Name: "DingDing",
Description: "Sends HTTP POST request to DingDing", Description: "Sends HTTP POST request to DingDing",
Heading: "DingDing settings", Heading: "DingDing settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx", Placeholder: "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "Message Type", Label: "Message Type",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
PropertyName: "msgType", PropertyName: "msgType",
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: "link", Value: "link",
Label: "Link"}, Label: "Link"},
@ -135,7 +134,7 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -146,19 +145,19 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Kafka REST Proxy", Name: "Kafka REST Proxy",
Description: "Sends notifications to Kafka Rest Proxy", Description: "Sends notifications to Kafka Rest Proxy",
Heading: "Kafka settings", Heading: "Kafka settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Kafka REST Proxy", Label: "Kafka REST Proxy",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "http://localhost:8082", Placeholder: "http://localhost:8082",
PropertyName: "kafkaRestProxy", PropertyName: "kafkaRestProxy",
Required: true, Required: true,
}, },
{ {
Label: "Topic", Label: "Topic",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "topic1", Placeholder: "topic1",
PropertyName: "kafkaTopic", PropertyName: "kafkaTopic",
Required: true, Required: true,
@ -170,30 +169,30 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Email", Name: "Email",
Description: "Sends notifications using Grafana server configured SMTP settings", Description: "Sends notifications using Grafana server configured SMTP settings",
Heading: "Email settings", Heading: "Email settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Single email", Label: "Single email",
Description: "Send a single email to all recipients", Description: "Send a single email to all recipients",
Element: alerting.ElementTypeCheckbox, Element: ElementTypeCheckbox,
PropertyName: "singleEmail", PropertyName: "singleEmail",
}, },
{ {
Label: "Addresses", Label: "Addresses",
Description: "You can enter multiple email addresses using a \";\" separator", Description: "You can enter multiple email addresses using a \";\" separator",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
PropertyName: "addresses", PropertyName: "addresses",
Required: true, Required: true,
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Description: "Optional message to include with the email. You can use template variables", Description: "Optional message to include with the email. You can use template variables",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
PropertyName: "message", PropertyName: "message",
}, },
{ // New in 9.0. { // New in 9.0.
Label: "Subject", Label: "Subject",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Templated subject of the email", Description: "Templated subject of the email",
PropertyName: "subject", PropertyName: "subject",
Placeholder: `{{ template "default.title" . }}`, Placeholder: `{{ template "default.title" . }}`,
@ -205,11 +204,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "PagerDuty", Name: "PagerDuty",
Description: "Sends notifications to PagerDuty", Description: "Sends notifications to PagerDuty",
Heading: "PagerDuty settings", Heading: "PagerDuty settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Integration Key", Label: "Integration Key",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Pagerduty Integration Key", Placeholder: "Pagerduty Integration Key",
PropertyName: "integrationKey", PropertyName: "integrationKey",
Required: true, Required: true,
@ -217,8 +216,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Severity", Label: "Severity",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: "critical", Value: "critical",
Label: "Critical", Label: "Critical",
@ -241,29 +240,29 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
{ // New in 8.0. { // New in 8.0.
Label: "Class", Label: "Class",
Description: "The class/type of the event, for example 'ping failure' or 'cpu load'", Description: "The class/type of the event, for example 'ping failure' or 'cpu load'",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "class", PropertyName: "class",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Component", Label: "Component",
Description: "Component of the source machine that is responsible for the event, for example mysql or eth0", Description: "Component of the source machine that is responsible for the event, for example mysql or eth0",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Grafana", Placeholder: "Grafana",
PropertyName: "component", PropertyName: "component",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Group", Label: "Group",
Description: "Logical grouping of components of a service, for example 'app-stack'", Description: "Logical grouping of components of a service, for example 'app-stack'",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "group", PropertyName: "group",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Summary", Label: "Summary",
Description: "You can use templates for summary", Description: "You can use templates for summary",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "summary", PropertyName: "summary",
}, },
@ -274,20 +273,20 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "VictorOps", Name: "VictorOps",
Description: "Sends notifications to VictorOps", Description: "Sends notifications to VictorOps",
Heading: "VictorOps settings", Heading: "VictorOps settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "VictorOps url", Placeholder: "VictorOps url",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message Type", Label: "Message Type",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
PropertyName: "messageType", PropertyName: "messageType",
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: "CRITICAL", Value: "CRITICAL",
Label: "CRITICAL"}, Label: "CRITICAL"},
@ -304,11 +303,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Pushover", Name: "Pushover",
Description: "Sends HTTP POST request to the Pushover API", Description: "Sends HTTP POST request to the Pushover API",
Heading: "Pushover settings", Heading: "Pushover settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "API Token", Label: "API Token",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Application token", Placeholder: "Application token",
PropertyName: "apiToken", PropertyName: "apiToken",
Required: true, Required: true,
@ -316,8 +315,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "User key(s)", Label: "User key(s)",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "comma-separated list", Placeholder: "comma-separated list",
PropertyName: "userKey", PropertyName: "userKey",
Required: true, Required: true,
@ -325,54 +324,54 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Device(s) (optional)", Label: "Device(s) (optional)",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "comma-separated list; leave empty to send to all devices", Placeholder: "comma-separated list; leave empty to send to all devices",
PropertyName: "device", PropertyName: "device",
}, },
{ {
Label: "Alerting priority", Label: "Alerting priority",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: pushoverPriorityOptions, SelectOptions: pushoverPriorityOptions,
PropertyName: "priority", PropertyName: "priority",
}, },
{ {
Label: "OK priority", Label: "OK priority",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: pushoverPriorityOptions, SelectOptions: pushoverPriorityOptions,
PropertyName: "okPriority", PropertyName: "okPriority",
}, },
{ {
Description: "How often (in seconds) the Pushover servers will send the same alerting or OK notification to the user.", Description: "How often (in seconds) the Pushover servers will send the same alerting or OK notification to the user.",
Label: "Retry (Only used for Emergency Priority)", Label: "Retry (Only used for Emergency Priority)",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "minimum 30 seconds", Placeholder: "minimum 30 seconds",
PropertyName: "retry", PropertyName: "retry",
}, },
{ {
Description: "How many seconds the alerting or OK notification will continue to be retried.", Description: "How many seconds the alerting or OK notification will continue to be retried.",
Label: "Expire (Only used for Emergency Priority)", Label: "Expire (Only used for Emergency Priority)",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "maximum 86400 seconds", Placeholder: "maximum 86400 seconds",
PropertyName: "expire", PropertyName: "expire",
}, },
{ {
Label: "Alerting sound", Label: "Alerting sound",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: pushoverSoundOptions, SelectOptions: pushoverSoundOptions,
PropertyName: "sound", PropertyName: "sound",
}, },
{ {
Label: "OK sound", Label: "OK sound",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: pushoverSoundOptions, SelectOptions: pushoverSoundOptions,
PropertyName: "okSound", PropertyName: "okSound",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -383,11 +382,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Slack", Name: "Slack",
Description: "Sends notifications to Slack", Description: "Sends notifications to Slack",
Heading: "Slack settings", Heading: "Slack settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Recipient", Label: "Recipient",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Specify channel, private group, or IM channel (can be an encoded ID or a name) - required unless you provide a webhook", Description: "Specify channel, private group, or IM channel (can be an encoded ID or a name) - required unless you provide a webhook",
PropertyName: "recipient", PropertyName: "recipient",
Required: true, Required: true,
@ -399,8 +398,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
// if it's necessary and missing. // if it's necessary and missing.
{ {
Label: "Token", Label: "Token",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Provide a Slack API token (starts with \"xoxb\") - required unless you provide a webhook", Description: "Provide a Slack API token (starts with \"xoxb\") - required unless you provide a webhook",
PropertyName: "token", PropertyName: "token",
Secure: true, Secure: true,
@ -409,43 +408,43 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Username", Label: "Username",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Set the username for the bot's message", Description: "Set the username for the bot's message",
PropertyName: "username", PropertyName: "username",
}, },
{ {
Label: "Icon emoji", Label: "Icon emoji",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Provide an emoji to use as the icon for the bot's message. Overrides the icon URL.", Description: "Provide an emoji to use as the icon for the bot's message. Overrides the icon URL.",
PropertyName: "icon_emoji", PropertyName: "icon_emoji",
}, },
{ {
Label: "Icon URL", Label: "Icon URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Provide a URL to an image to use as the icon for the bot's message", Description: "Provide a URL to an image to use as the icon for the bot's message",
PropertyName: "icon_url", PropertyName: "icon_url",
}, },
{ {
Label: "Mention Users", Label: "Mention Users",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Mention one or more users (comma separated) when notifying in a channel, by ID (you can copy this from the user's Slack profile)", Description: "Mention one or more users (comma separated) when notifying in a channel, by ID (you can copy this from the user's Slack profile)",
PropertyName: "mentionUsers", PropertyName: "mentionUsers",
}, },
{ {
Label: "Mention Groups", Label: "Mention Groups",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Mention one or more groups (comma separated) when notifying in a channel (you can copy this from the group's Slack profile URL)", Description: "Mention one or more groups (comma separated) when notifying in a channel (you can copy this from the group's Slack profile URL)",
PropertyName: "mentionGroups", PropertyName: "mentionGroups",
}, },
{ {
Label: "Mention Channel", Label: "Mention Channel",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: "", Value: "",
Label: "Disabled", Label: "Disabled",
@ -464,8 +463,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Webhook URL", Label: "Webhook URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Optionally provide a Slack incoming webhook URL for sending messages, in this case the token isn't necessary", Description: "Optionally provide a Slack incoming webhook URL for sending messages, in this case the token isn't necessary",
Placeholder: "Slack incoming webhook URL", Placeholder: "Slack incoming webhook URL",
PropertyName: "url", PropertyName: "url",
@ -475,23 +474,23 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ // New in 8.4. { // New in 8.4.
Label: "Endpoint URL", Label: "Endpoint URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Optionally provide a custom Slack message API endpoint for non-webhook requests, default is https://slack.com/api/chat.postMessage", Description: "Optionally provide a custom Slack message API endpoint for non-webhook requests, default is https://slack.com/api/chat.postMessage",
Placeholder: "Slack endpoint url", Placeholder: "Slack endpoint url",
PropertyName: "endpointUrl", PropertyName: "endpointUrl",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Title", Label: "Title",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Templated title of the slack message", Description: "Templated title of the slack message",
PropertyName: "title", PropertyName: "title",
Placeholder: `{{ template "slack.default.title" . }}`, Placeholder: `{{ template "slack.default.title" . }}`,
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Text Body", Label: "Text Body",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Description: "Body of the slack message", Description: "Body of the slack message",
PropertyName: "text", PropertyName: "text",
Placeholder: `{{ template "slack.default.text" . }}`, Placeholder: `{{ template "slack.default.text" . }}`,
@ -503,19 +502,19 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Sensu Go", Name: "Sensu Go",
Description: "Sends HTTP POST request to a Sensu Go API", Description: "Sends HTTP POST request to a Sensu Go API",
Heading: "Sensu Go Settings", Heading: "Sensu Go Settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Backend URL", Label: "Backend URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "http://sensu-api.local:8080", Placeholder: "http://sensu-api.local:8080",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "API Key", Label: "API Key",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypePassword, InputType: InputTypePassword,
Description: "API key to auth to Sensu Go backend", Description: "API key to auth to Sensu Go backend",
PropertyName: "apikey", PropertyName: "apikey",
Required: true, Required: true,
@ -523,34 +522,34 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Proxy entity name", Label: "Proxy entity name",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "default", Placeholder: "default",
PropertyName: "entity", PropertyName: "entity",
}, },
{ {
Label: "Check name", Label: "Check name",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "default", Placeholder: "default",
PropertyName: "check", PropertyName: "check",
}, },
{ {
Label: "Handler", Label: "Handler",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "handler", PropertyName: "handler",
}, },
{ {
Label: "Namespace", Label: "Namespace",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "default", Placeholder: "default",
PropertyName: "namespace", PropertyName: "namespace",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -561,33 +560,33 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Microsoft Teams", Name: "Microsoft Teams",
Description: "Sends notifications using Incoming Webhook connector to Microsoft Teams", Description: "Sends notifications using Incoming Webhook connector to Microsoft Teams",
Heading: "Teams settings", Heading: "Teams settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Teams incoming webhook url", Placeholder: "Teams incoming webhook url",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "Title", Label: "Title",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Templated title of the Teams message.", Description: "Templated title of the Teams message.",
PropertyName: "title", PropertyName: "title",
Placeholder: `{{ template "default.title" . }}`, Placeholder: `{{ template "default.title" . }}`,
}, },
{ {
Label: "Section Title", Label: "Section Title",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Section title for the Teams message. Leave blank for none.", Description: "Section title for the Teams message. Leave blank for none.",
PropertyName: "sectiontitle", PropertyName: "sectiontitle",
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -598,11 +597,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Telegram", Name: "Telegram",
Description: "Sends notifications to Telegram", Description: "Sends notifications to Telegram",
Heading: "Telegram API settings", Heading: "Telegram API settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "BOT API Token", Label: "BOT API Token",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Telegram BOT API Token", Placeholder: "Telegram BOT API Token",
PropertyName: "bottoken", PropertyName: "bottoken",
Required: true, Required: true,
@ -610,15 +609,15 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Chat ID", Label: "Chat ID",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Integer Telegram Chat Identifier", Description: "Integer Telegram Chat Identifier",
PropertyName: "chatid", PropertyName: "chatid",
Required: true, Required: true,
}, },
{ // New in 8.0. { // New in 8.0.
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -629,18 +628,18 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Webhook", Name: "Webhook",
Description: "Sends HTTP POST request to a URL", Description: "Sends HTTP POST request to a URL",
Heading: "Webhook settings", Heading: "Webhook settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "HTTP Method", Label: "HTTP Method",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: "POST", Value: "POST",
Label: "POST", Label: "POST",
@ -654,38 +653,38 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "HTTP Basic Authentication - Username", Label: "HTTP Basic Authentication - Username",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "username", PropertyName: "username",
}, },
{ {
Label: "HTTP Basic Authentication - Password", Label: "HTTP Basic Authentication - Password",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypePassword, InputType: InputTypePassword,
PropertyName: "password", PropertyName: "password",
Secure: true, Secure: true,
}, },
{ // New in 9.1 { // New in 9.1
Label: "Authorization Header - Scheme", Label: "Authorization Header - Scheme",
Description: "Optionally provide a scheme for the Authorization Request Header. Default is Bearer.", Description: "Optionally provide a scheme for the Authorization Request Header. Default is Bearer.",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "authorization_scheme", PropertyName: "authorization_scheme",
Placeholder: "Bearer", Placeholder: "Bearer",
}, },
{ // New in 9.1 { // New in 9.1
Label: "Authorization Header - Credentials", Label: "Authorization Header - Credentials",
Description: "Credentials for the Authorization Request header. Only one of HTTP Basic Authentication or Authorization Request Header can be set.", Description: "Credentials for the Authorization Request header. Only one of HTTP Basic Authentication or Authorization Request Header can be set.",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "authorization_credentials", PropertyName: "authorization_credentials",
Secure: true, Secure: true,
}, },
{ // New in 8.0. TODO: How to enforce only numbers? { // New in 8.0. TODO: How to enforce only numbers?
Label: "Max Alerts", 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.", 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: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "maxAlerts", PropertyName: "maxAlerts",
}, },
}, },
@ -695,11 +694,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "WeCom", Name: "WeCom",
Description: "Send alerts generated by Grafana to WeCom", Description: "Send alerts generated by Grafana to WeCom",
Heading: "WeCom settings", Heading: "WeCom settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx", Placeholder: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxx",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
@ -708,14 +707,14 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
{ {
Label: "Message", Label: "Message",
Description: "Custom WeCom message. You can use template variables.", Description: "Custom WeCom message. You can use template variables.",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
{ // New in 9.1. { // New in 9.1.
Label: "Title", Label: "Title",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Templated title of the message", Description: "Templated title of the message",
PropertyName: "title", PropertyName: "title",
Placeholder: `{{ template "default.title" . }}`, Placeholder: `{{ template "default.title" . }}`,
@ -727,25 +726,25 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Alertmanager", Name: "Alertmanager",
Description: "Sends notifications to Alertmanager", Description: "Sends notifications to Alertmanager",
Heading: "Alertmanager Settings", Heading: "Alertmanager Settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "http://localhost:9093", Placeholder: "http://localhost:9093",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "Basic Auth User", Label: "Basic Auth User",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "basicAuthUser", PropertyName: "basicAuthUser",
}, },
{ {
Label: "Basic Auth Password", Label: "Basic Auth Password",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypePassword, InputType: InputTypePassword,
PropertyName: "basicAuthPassword", PropertyName: "basicAuthPassword",
Secure: true, Secure: true,
}, },
@ -756,33 +755,33 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Discord", Name: "Discord",
Heading: "Discord settings", Heading: "Discord settings",
Description: "Sends notifications to Discord", Description: "Sends notifications to Discord",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Message Content", Label: "Message Content",
Description: "Mention a group using @ or a user using <@ID> when notifying in a channel", Description: "Mention a group using @ or a user using <@ID> when notifying in a channel",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
{ {
Label: "Webhook URL", Label: "Webhook URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Discord webhook URL", Placeholder: "Discord webhook URL",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "Avatar URL", Label: "Avatar URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
PropertyName: "avatar_url", PropertyName: "avatar_url",
}, },
{ {
Label: "Use Discord's Webhook Username", Label: "Use Discord's Webhook Username",
Description: "Use the username configured in Discord's webhook settings. Otherwise, the username will be 'Grafana'", Description: "Use the username configured in Discord's webhook settings. Otherwise, the username will be 'Grafana'",
Element: alerting.ElementTypeCheckbox, Element: ElementTypeCheckbox,
PropertyName: "use_discord_username", PropertyName: "use_discord_username",
}, },
}, },
@ -792,18 +791,18 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "Google Hangouts Chat", Name: "Google Hangouts Chat",
Description: "Sends notifications to Google Hangouts Chat via webhooks based on the official JSON message format", Description: "Sends notifications to Google Hangouts Chat via webhooks based on the official JSON message format",
Heading: "Google Hangouts Chat settings", Heading: "Google Hangouts Chat settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "URL", Label: "URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "Google Hangouts Chat incoming webhook url", Placeholder: "Google Hangouts Chat incoming webhook url",
PropertyName: "url", PropertyName: "url",
Required: true, Required: true,
}, },
{ {
Label: "Message", Label: "Message",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
Placeholder: `{{ template "default.message" . }}`, Placeholder: `{{ template "default.message" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
@ -814,11 +813,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "LINE", Name: "LINE",
Description: "Send notifications to LINE notify", Description: "Send notifications to LINE notify",
Heading: "LINE notify settings", Heading: "LINE notify settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Token", Label: "Token",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "LINE notify token key", Placeholder: "LINE notify token key",
PropertyName: "token", PropertyName: "token",
Required: true, Required: true,
@ -832,11 +831,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Heading: "Threema Gateway settings", Heading: "Threema Gateway settings",
Info: "Notifications can be configured for any Threema Gateway ID of type \"Basic\". End-to-End IDs are not currently supported." + Info: "Notifications can be configured for any Threema Gateway ID of type \"Basic\". End-to-End IDs are not currently supported." +
"The Threema Gateway ID can be set up at https://gateway.threema.ch/.", "The Threema Gateway ID can be set up at https://gateway.threema.ch/.",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "Gateway ID", Label: "Gateway ID",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "*3MAGWID", Placeholder: "*3MAGWID",
Description: "Your 8 character Threema Gateway Basic ID (starting with a *).", Description: "Your 8 character Threema Gateway Basic ID (starting with a *).",
PropertyName: "gateway_id", PropertyName: "gateway_id",
@ -845,8 +844,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Recipient ID", Label: "Recipient ID",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "YOUR3MID", Placeholder: "YOUR3MID",
Description: "The 8 character Threema ID that should receive the alerts.", Description: "The 8 character Threema ID that should receive the alerts.",
PropertyName: "recipient_id", PropertyName: "recipient_id",
@ -855,8 +854,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "API Secret", Label: "API Secret",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Description: "Your Threema Gateway API secret.", Description: "Your Threema Gateway API secret.",
PropertyName: "api_secret", PropertyName: "api_secret",
Required: true, Required: true,
@ -869,11 +868,11 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
Name: "OpsGenie", Name: "OpsGenie",
Description: "Sends notifications to OpsGenie", Description: "Sends notifications to OpsGenie",
Heading: "OpsGenie settings", Heading: "OpsGenie settings",
Options: []alerting.NotifierOption{ Options: []NotifierOption{
{ {
Label: "API Key", Label: "API Key",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "OpsGenie API Key", Placeholder: "OpsGenie API Key",
PropertyName: "apiKey", PropertyName: "apiKey",
Required: true, Required: true,
@ -881,8 +880,8 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
}, },
{ {
Label: "Alert API URL", Label: "Alert API URL",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: "https://api.opsgenie.com/v2/alerts", Placeholder: "https://api.opsgenie.com/v2/alerts",
PropertyName: "apiUrl", PropertyName: "apiUrl",
Required: true, Required: true,
@ -890,32 +889,32 @@ func GetAvailableNotifiers() []*alerting.NotifierPlugin {
{ {
Label: "Message", Label: "Message",
Description: "Alert text limited to 130 characters.", Description: "Alert text limited to 130 characters.",
Element: alerting.ElementTypeInput, Element: ElementTypeInput,
InputType: alerting.InputTypeText, InputType: InputTypeText,
Placeholder: `{{ template "default.title" . }}`, Placeholder: `{{ template "default.title" . }}`,
PropertyName: "message", PropertyName: "message",
}, },
{ {
Label: "Description", Label: "Description",
Description: "A description of the incident.", Description: "A description of the incident.",
Element: alerting.ElementTypeTextArea, Element: ElementTypeTextArea,
PropertyName: "description", PropertyName: "description",
}, },
{ {
Label: "Auto close incidents", Label: "Auto close incidents",
Element: alerting.ElementTypeCheckbox, Element: ElementTypeCheckbox,
Description: "Automatically close alerts in OpsGenie once the alert goes back to ok.", Description: "Automatically close alerts in OpsGenie once the alert goes back to ok.",
PropertyName: "autoClose", PropertyName: "autoClose",
}, { }, {
Label: "Override priority", Label: "Override priority",
Element: alerting.ElementTypeCheckbox, Element: ElementTypeCheckbox,
Description: "Allow the alert priority to be set using the og_priority annotation", Description: "Allow the alert priority to be set using the og_priority annotation",
PropertyName: "overridePriority", PropertyName: "overridePriority",
}, },
{ {
Label: "Send notification tags as", Label: "Send notification tags as",
Element: alerting.ElementTypeSelect, Element: ElementTypeSelect,
SelectOptions: []alerting.SelectOption{ SelectOptions: []SelectOption{
{ {
Value: channels.OpsgenieSendTags, Value: channels.OpsgenieSendTags,
Label: "Tags", Label: "Tags",

View File

@ -0,0 +1,63 @@
package channels_config
// NotifierPlugin holds meta information about a notifier.
type NotifierPlugin struct {
Type string `json:"type"`
Name string `json:"name"`
Heading string `json:"heading"`
Description string `json:"description"`
Info string `json:"info"`
Options []NotifierOption `json:"options"`
}
// NotifierOption holds information about options specific for the NotifierPlugin.
type NotifierOption struct {
Element ElementType `json:"element"`
InputType InputType `json:"inputType"`
Label string `json:"label"`
Description string `json:"description"`
Placeholder string `json:"placeholder"`
PropertyName string `json:"propertyName"`
SelectOptions []SelectOption `json:"selectOptions"`
ShowWhen ShowWhen `json:"showWhen"`
Required bool `json:"required"`
ValidationRule string `json:"validationRule"`
Secure bool `json:"secure"`
DependsOn string `json:"dependsOn"`
}
// ElementType is the type of element that can be rendered in the frontend.
type ElementType string
const (
// ElementTypeInput will render an input
ElementTypeInput = "input"
// ElementTypeSelect will render a select
ElementTypeSelect = "select"
// ElementTypeCheckbox will render a checkbox
ElementTypeCheckbox = "checkbox"
// ElementTypeTextArea will render a textarea
ElementTypeTextArea = "textarea"
)
// InputType is the type of input that can be rendered in the frontend.
type InputType string
const (
// InputTypeText will render a text field in the frontend
InputTypeText = "text"
// InputTypePassword will render a password field in the frontend
InputTypePassword = "password"
)
// SelectOption is a simple type for Options that have dropdown options. Should be used when Element is ElementTypeSelect.
type SelectOption struct {
Value string `json:"value"`
Label string `json:"label"`
}
// ShowWhen holds information about when options are dependant on other options.
type ShowWhen struct {
Field string `json:"field"`
Is string `json:"is"`
}