slack

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

View Source
const PostMessageURL = "https://slack.com/api/chat.postMessage"

PostMessageURL is Slack's chat.postMessage endpoint.

Variables

View Source
var DefaultSlackConfig = SlackConfig{
	NotifierConfig: amcommoncfg.NotifierConfig{
		VSendResolved: false,
	},
	Color:      `{{ template "slack.default.color" . }}`,
	Username:   `{{ template "slack.default.username" . }}`,
	Title:      `{{ template "slack.default.title" . }}`,
	TitleLink:  `{{ template "slack.default.titlelink" . }}`,
	IconEmoji:  `{{ template "slack.default.iconemoji" . }}`,
	IconURL:    `{{ template "slack.default.iconurl" . }}`,
	Pretext:    `{{ template "slack.default.pretext" . }}`,
	Text:       `{{ template "slack.default.text" . }}`,
	Fallback:   `{{ template "slack.default.fallback" . }}`,
	CallbackID: `{{ template "slack.default.callbackid" . }}`,
	Footer:     `{{ template "slack.default.footer" . }}`,
}

DefaultSlackConfig defines default values for Slack configurations.

Functions

func ValidatePostUpdatesToThreadAPIURL added in v0.35.0

func ValidatePostUpdatesToThreadAPIURL(postUpdatesToThread bool, apiURL *amcommoncfg.SecretURL, apiURLFile string) error

ValidatePostUpdatesToThreadAPIURL validates the api url used by post_updates_to_thread.

func ValidateUpdateMessageAPIURL added in v0.35.0

func ValidateUpdateMessageAPIURL(updateMessage bool, apiURL *amcommoncfg.SecretURL, apiURLFile string) error

ValidateUpdateMessageAPIURL validates the api url used by update_message.

Types

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier implements a Notifier for Slack notifications.

func New

New returns a new Slack notification handler.

func (*Notifier) Notify

func (n *Notifier) Notify(ctx context.Context, as ...*alert.Alert) notify.NotifyVerdict

Notify implements the Notifier interface.

type SlackAction added in v0.35.0

type SlackAction struct {
	Type         string                  `yaml:"type,omitempty"  json:"type,omitempty"`
	Text         string                  `yaml:"text,omitempty"  json:"text,omitempty"`
	URL          string                  `yaml:"url,omitempty"   json:"url,omitempty"`
	Style        string                  `yaml:"style,omitempty" json:"style,omitempty"`
	Name         string                  `yaml:"name,omitempty"  json:"name,omitempty"`
	Value        string                  `yaml:"value,omitempty"  json:"value,omitempty"`
	ConfirmField *SlackConfirmationField `yaml:"confirm,omitempty"  json:"confirm,omitempty"`
}

SlackAction configures a single Slack action that is sent with each notification. See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons for more information.

func (*SlackAction) UnmarshalYAML added in v0.35.0

func (c *SlackAction) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for SlackAction.

func (*SlackAction) Validate added in v0.35.0

func (c *SlackAction) Validate() error

type SlackConfig added in v0.35.0

type SlackConfig struct {
	amcommoncfg.NotifierConfig `yaml:",inline" json:",inline"`

	HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`

	APIURL       *amcommoncfg.SecretURL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
	APIURLFile   string                 `yaml:"api_url_file,omitempty" json:"api_url_file,omitempty"`
	AppToken     commoncfg.Secret       `yaml:"app_token,omitempty" json:"app_token,omitempty"`
	AppTokenFile string                 `yaml:"app_token_file,omitempty" json:"app_token_file,omitempty"`
	AppURL       *amcommoncfg.URL       `yaml:"app_url,omitempty" json:"app_url,omitempty"`

	// Slack channel override, (like #other-channel or @username).
	Channel  string `yaml:"channel,omitempty" json:"channel,omitempty"`
	Username string `yaml:"username,omitempty" json:"username,omitempty"`
	Color    string `yaml:"color,omitempty" json:"color,omitempty"`

	Title       string         `yaml:"title,omitempty" json:"title,omitempty"`
	TitleLink   string         `yaml:"title_link,omitempty" json:"title_link,omitempty"`
	Pretext     string         `yaml:"pretext,omitempty" json:"pretext,omitempty"`
	Text        string         `yaml:"text,omitempty" json:"text,omitempty"`
	MessageText string         `yaml:"message_text,omitempty" json:"message_text,omitempty"`
	Fields      []*SlackField  `yaml:"fields,omitempty" json:"fields,omitempty"`
	ShortFields bool           `yaml:"short_fields" json:"short_fields,omitempty"`
	Footer      string         `yaml:"footer,omitempty" json:"footer,omitempty"`
	Fallback    string         `yaml:"fallback,omitempty" json:"fallback,omitempty"`
	CallbackID  string         `yaml:"callback_id,omitempty" json:"callback_id,omitempty"`
	IconEmoji   string         `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty"`
	IconURL     string         `yaml:"icon_url,omitempty" json:"icon_url,omitempty"`
	ImageURL    string         `yaml:"image_url,omitempty" json:"image_url,omitempty"`
	ThumbURL    string         `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"`
	LinkNames   bool           `yaml:"link_names" json:"link_names,omitempty"`
	MrkdwnIn    []string       `yaml:"mrkdwn_in,omitempty" json:"mrkdwn_in,omitempty"`
	Actions     []*SlackAction `yaml:"actions,omitempty" json:"actions,omitempty"`

	UpdateMessage bool `yaml:"update_message" json:"update_message,omitempty"`

	// PostUpdatesToThread posts subsequent notifications for an alert group as
	// replies in the thread of the initial message. Requires a bot token.
	PostUpdatesToThread bool `yaml:"post_updates_to_thread" json:"post_updates_to_thread,omitempty"`

	// Timeout is the maximum time allowed to invoke the slack. Setting this to 0
	// does not impose a timeout.
	Timeout time.Duration `yaml:"timeout" json:"timeout"`
}

SlackConfig configures notifications via Slack.

func (*SlackConfig) UnmarshalYAML added in v0.35.0

func (c *SlackConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*SlackConfig) Validate added in v0.35.0

func (c *SlackConfig) Validate() error

type SlackConfirmationField added in v0.35.0

type SlackConfirmationField struct {
	Text        string `yaml:"text,omitempty"  json:"text,omitempty"`
	Title       string `yaml:"title,omitempty"  json:"title,omitempty"`
	OkText      string `yaml:"ok_text,omitempty"  json:"ok_text,omitempty"`
	DismissText string `yaml:"dismiss_text,omitempty"  json:"dismiss_text,omitempty"`
}

SlackConfirmationField protect users from destructive actions or particularly distinguished decisions by asking them to confirm their button click one more time. See https://api.slack.com/docs/interactive-message-field-guide#confirmation_fields for more information.

func (*SlackConfirmationField) UnmarshalYAML added in v0.35.0

func (c *SlackConfirmationField) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for SlackConfirmationField.

func (*SlackConfirmationField) Validate added in v0.35.0

func (c *SlackConfirmationField) Validate() error

type SlackField added in v0.35.0

type SlackField struct {
	Title string `yaml:"title,omitempty" json:"title,omitempty"`
	Value string `yaml:"value,omitempty" json:"value,omitempty"`
	Short *bool  `yaml:"short,omitempty" json:"short,omitempty"`
}

SlackField configures a single Slack field that is sent with each notification. Each field must contain a title, value, and optionally, a boolean value to indicate if the field is short enough to be displayed next to other fields designated as short. See https://api.slack.com/docs/message-attachments#fields for more information.

func (*SlackField) UnmarshalYAML added in v0.35.0

func (c *SlackField) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for SlackField.

func (*SlackField) Validate added in v0.35.0

func (c *SlackField) Validate() error

Jump to

Keyboard shortcuts

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