routing

package
v0.8.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSMTPServerHost = "localhost"
View Source
const DefaultSMTPServerPort = 25
View Source
const EmailEndpointInternalId = "email"
View Source
const PagerDutyEndpointInternalId = "pagerduty"
View Source
const SlackEndpointInternalId = "slack"

Variables

View Source
var (
	DefaultSlackConfig = SlackConfig{
		NotifierConfig: cfg.NotifierConfig{
			VSendResolved: false,
		},
		Color:      `{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}`,
		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" . }}`,
	}
	// DefaultEmailConfig defines default values for Email configurations.
	DefaultEmailConfig = EmailConfig{
		NotifierConfig: cfg.NotifierConfig{
			VSendResolved: false,
		},
		HTML: `{{ template "email.default.html" . }}`,
		Text: ``,
	}

	// DefaultPagerdutyConfig defines default values for PagerDuty configurations.
	DefaultPagerdutyConfig = PagerdutyConfig{
		NotifierConfig: &cfg.NotifierConfig{
			VSendResolved: true,
		},
		Description: `{{ template "pagerduty.default.description" .}}`,
		Client:      `{{ template "pagerduty.default.client" . }}`,
		ClientURL:   `{{ template "pagerduty.default.clientURL" . }}`,
	}
	// DefaultPagerdutyDetails defines the default values for PagerDuty details.
	DefaultPagerdutyDetails = map[string]string{
		"firing":       `{{ template "pagerduty.default.instances" .Alerts.Firing }}`,
		"resolved":     `{{ template "pagerduty.default.instances" .Alerts.Resolved }}`,
		"num_firing":   `{{ .Alerts.Firing | len }}`,
		"num_resolved": `{{ .Alerts.Resolved | len }}`,
	}
)

Functions

func NewRouteBase

func NewRouteBase(conditionId string) *cfg.Route

func UpdateRouteWithGeneralRequestInfo

func UpdateRouteWithGeneralRequestInfo(route *cfg.Route, req *alertingv1.FullAttachedEndpoints) error

Types

type EmailConfig

type EmailConfig struct {
	cfg.NotifierConfig `yaml:",inline" json:",inline"`
	To                 string       `yaml:"to,omitempty" json:"to,omitempty"`
	From               string       `yaml:"from,omitempty" json:"from,omitempty"`
	Hello              string       `yaml:"hello,omitempty" json:"hello,omitempty"`
	Smarthost          cfg.HostPort `yaml:"smarthost,omitempty" json:"smarthost,omitempty"`
	AuthUsername       string       `yaml:"auth_username,omitempty" json:"auth_username,omitempty"`
	// Change from secret to string since the string is stored in a kube secret anyways
	AuthPassword string `yaml:"auth_password,omitempty" json:"auth_password,omitempty"`
	// Change from secret to string since the string is stored in a kube secret anyways
	AuthSecret   string            `yaml:"auth_secret,omitempty" json:"auth_secret,omitempty"`
	AuthIdentity string            `yaml:"auth_identity,omitempty" json:"auth_identity,omitempty"`
	Headers      map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
	HTML         string            `yaml:"html,omitempty" json:"html,omitempty"`
	Text         string            `yaml:"text,omitempty" json:"text,omitempty"`
	RequireTLS   *bool             `yaml:"require_tls,omitempty" json:"require_tls,omitempty"`
	TLSConfig    config.TLSConfig  `yaml:"tls_config,omitempty" json:"tls_config,omitempty"`
}

func NewEmailReceiverNode

func NewEmailReceiverNode(endpoint *alertingv1.EmailEndpoint) (*EmailConfig, error)

func WithEmailImplementation

func WithEmailImplementation(email *EmailConfig, impl *alertingv1.EndpointImplementation) (*EmailConfig, error)

func (*EmailConfig) UnmarshalYAML

func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type GlobalConfig

type GlobalConfig struct {
	// ResolveTimeout is the time after which an alert is declared resolved
	// if it has not been updated.
	ResolveTimeout model.Duration `yaml:"resolve_timeout" json:"resolve_timeout"`

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

	SMTPFrom         string       `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
	SMTPHello        string       `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
	SMTPSmarthost    cfg.HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
	SMTPAuthUsername string       `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
	// Changed from Secret to string to avoid issues with the yaml parser
	SMTPAuthPassword string `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
	// Changed from Secret to string to avoid issues with the yaml parser
	SMTPAuthSecret     string         `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
	SMTPAuthIdentity   string         `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
	SMTPRequireTLS     bool           `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"`
	SlackAPIURL        *cfg.SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
	SlackAPIURLFile    string         `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
	PagerdutyURL       *cfg.URL       `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
	OpsGenieAPIURL     *cfg.URL       `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
	OpsGenieAPIKey     cfg.Secret     `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
	OpsGenieAPIKeyFile string         `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"`
	WeChatAPIURL       *cfg.URL       `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
	WeChatAPISecret    cfg.Secret     `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
	WeChatAPICorpID    string         `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
	VictorOpsAPIURL    *cfg.URL       `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
	VictorOpsAPIKey    cfg.Secret     `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
	TelegramAPIUrl     *cfg.URL       `yaml:"telegram_api_url,omitempty" json:"telegram_api_url,omitempty"`
}

required due to https://github.com/rancher/opni/issues/542

func DefaultGlobalConfig

func DefaultGlobalConfig() GlobalConfig

type HTTPClientConfig

type HTTPClientConfig struct {
	// The HTTP basic authentication credentials for the targets.
	BasicAuth *commoncfg.BasicAuth `yaml:"basic_auth,omitempty" json:"basic_auth,omitempty"`
	// The HTTP authorization credentials for the targets.
	Authorization *commoncfg.Authorization `yaml:"authorization,omitempty" json:"authorization,omitempty"`
	// The OAuth2 client credentials used to fetch a token for the targets.
	OAuth2 *commoncfg.OAuth2 `yaml:"oauth2,omitempty" json:"oauth2,omitempty"`
	// The bearer token for the targets. Deprecated in favour of
	// Authorization.Credentials.
	BearerToken commoncfg.Secret `yaml:"bearer_token,omitempty" json:"bearer_token,omitempty"`
	// The bearer token file for the targets. Deprecated in favour of
	// Authorization.CredentialsFile.
	BearerTokenFile string `yaml:"bearer_token_file,omitempty" json:"bearer_token_file,omitempty"`
	// HTTP proxy server to use to connect to the targets.
	ProxyURL commoncfg.URL `yaml:"proxy_url,omitempty" json:"proxy_url,omitempty"`
	// TLSConfig to use to connect to the targets.
	TLSConfig commoncfg.TLSConfig `yaml:"tls_config,omitempty" json:"tls_config,omitempty"`
	// FollowRedirects specifies whether the client should follow HTTP 3xx redirects.
	// The omitempty flag is not set, because it would be hidden from the
	// marshalled configuration when set to false.
	FollowRedirects bool `yaml:"follow_redirects" json:"follow_redirects"`
}

required due to https://github.com/rancher/opni/issues/542

type OpniInternalRouting

type OpniInternalRouting struct {
	Content map[string]map[string]*OpniRoutingMetadata `yaml:"inline,omitempty" json:"inline,omitempty"`
}

conditionId --> endpointId matching the current configuration of Route

func NewDefaultOpniInternalRouting

func NewDefaultOpniInternalRouting() *OpniInternalRouting

func NewOpniInternalRoutingFrom

func NewOpniInternalRoutingFrom(raw string) (*OpniInternalRouting, error)

func (*OpniInternalRouting) Add

func (o *OpniInternalRouting) Add(
	conditionId string,
	endpointId string,
	metadata OpniRoutingMetadata) error

func (*OpniInternalRouting) DeepCopy

func (o *OpniInternalRouting) DeepCopy() (*OpniInternalRouting, error)

func (*OpniInternalRouting) Get

func (o *OpniInternalRouting) Get(conditionId, endpointId string) (*OpniRoutingMetadata, error)

func (*OpniInternalRouting) GetFromCondition

func (o *OpniInternalRouting) GetFromCondition(conditionId string) (map[string]*OpniRoutingMetadata, error)

func (*OpniInternalRouting) Marshal

func (o *OpniInternalRouting) Marshal() ([]byte, error)

func (*OpniInternalRouting) Parse

func (o *OpniInternalRouting) Parse(data string) error

func (*OpniInternalRouting) RemoveCondition

func (o *OpniInternalRouting) RemoveCondition(conditionId string) error

func (*OpniInternalRouting) RemoveEndpoint

func (o *OpniInternalRouting) RemoveEndpoint(conditionId string, endpointId string) error

func (*OpniInternalRouting) UpdateEndpoint

func (o *OpniInternalRouting) UpdateEndpoint(conditionId, notificationId string, metadata OpniRoutingMetadata) error

type OpniRoutingMetadata

type OpniRoutingMetadata struct {
	EndpointType string `yaml:"endpointType" json:"endpointType"`
	Position     *int   `yaml:"position" json:"position"`
}

type PagerdutyConfig added in v0.8.0

type PagerdutyConfig struct {
	*cfg.NotifierConfig `yaml:",inline" json:",inline"`

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

	// Change from secret to string since the string is stored in a kube secret anyways
	ServiceKey string `yaml:"service_key,omitempty" json:"service_key,omitempty"`
	// Change from secret to string since the string is stored in a kube secret anyways
	RoutingKey  string                `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
	URL         *cfg.URL              `yaml:"url,omitempty" json:"url,omitempty"`
	Client      string                `yaml:"client,omitempty" json:"client,omitempty"`
	ClientURL   string                `yaml:"client_url,omitempty" json:"client_url,omitempty"`
	Description string                `yaml:"description,omitempty" json:"description,omitempty"`
	Details     map[string]string     `yaml:"details,omitempty" json:"details,omitempty"`
	Images      []*cfg.PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
	Links       []*cfg.PagerdutyLink  `yaml:"links,omitempty" json:"links,omitempty"`
	Severity    string                `yaml:"severity,omitempty" json:"severity,omitempty"`
	Class       string                `yaml:"class,omitempty" json:"class,omitempty"`
	Component   string                `yaml:"component,omitempty" json:"component,omitempty"`
	Group       string                `yaml:"group,omitempty" json:"group,omitempty"`
}

PagerdutyConfig configures notifications via PagerDuty.

func NewPagerDutyReceiverNode added in v0.8.0

func NewPagerDutyReceiverNode(endpoint *alertingv1.PagerDutyEndpoint) (*PagerdutyConfig, error)

func WithPagerDutyImplementatino added in v0.8.0

func WithPagerDutyImplementatino(pg *PagerdutyConfig, impl *alertingv1.EndpointImplementation) (*PagerdutyConfig, error)

func (*PagerdutyConfig) UnmarshalYAML added in v0.8.0

func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Receiver

type Receiver struct {
	// A unique identifier for this receiver.
	Name string `yaml:"name" json:"name"`

	EmailConfigs     []*EmailConfig         `yaml:"email_configs,omitempty" json:"email_configs,omitempty"`
	PagerdutyConfigs []*PagerdutyConfig     `yaml:"pagerduty_configs,omitempty" json:"pagerduty_configs,omitempty"`
	SlackConfigs     []*SlackConfig         `yaml:"slack_configs,omitempty" json:"slack_configs,omitempty"`
	WebhookConfigs   []*cfg.WebhookConfig   `yaml:"webhook_configs,omitempty" json:"webhook_configs,omitempty"`
	OpsGenieConfigs  []*cfg.OpsGenieConfig  `yaml:"opsgenie_configs,omitempty" json:"opsgenie_configs,omitempty"`
	WechatConfigs    []*cfg.WechatConfig    `yaml:"wechat_configs,omitempty" json:"wechat_configs,omitempty"`
	PushoverConfigs  []*cfg.PushoverConfig  `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"`
	VictorOpsConfigs []*cfg.VictorOpsConfig `yaml:"victorops_configs,omitempty" json:"victorops_configs,omitempty"`
	SNSConfigs       []*cfg.SNSConfig       `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"`
	TelegramConfigs  []*cfg.TelegramConfig  `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"`
}

Receiver configuration provides configuration on how to contact a receiver. Required to overwrite certain fields in alertmanager's Receiver : https://github.com/rancher/opni/issues/544

func NewReceiverBase

func NewReceiverBase(conditionId string) *Receiver

NewReceiverBase has to have Name be conditionId

func (*Receiver) AddEndpoint

func (r *Receiver) AddEndpoint(
	alertEndpoint *alertingv1.AlertEndpoint,
	details *alertingv1.EndpointImplementation) (int, string, error)

func (*Receiver) IsEmpty

func (r *Receiver) IsEmpty() bool

func (*Receiver) UnmarshalYAML

func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error

type RoutingTree

type RoutingTree struct {
	Global       *GlobalConfig      `yaml:"global,omitempty" json:"global,omitempty"`
	Route        *cfg.Route         `yaml:"route,omitempty" json:"route,omitempty"`
	InhibitRules []*cfg.InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
	Receivers    []*Receiver        `yaml:"receivers,omitempty" json:"receivers,omitempty"`
	Templates    []string           `yaml:"templates" json:"templates"`
}

RoutingTree

When creating a new receiver (routingNode), our assumption is that name == conditionId When creating a new route to this routinegNode the assumption is that its receiver name matches the receiver and the conditionId the route is associated with.

Marshals/Unmarshals to github.com/prometheus/alertmanager/config/config.go's Config struct, but we don't use this struct directly due to : - package mismatched versions with prometheus/common - override marshalling of secrets that prevents us from putting them into a secret

RoutingTree must always marshal to AlertManager's config, otherwise backend will reject it

We also assume that EndpointImplementation will have the same config for each receiver for the same condition ID

func NewDefaultRoutingTree

func NewDefaultRoutingTree(managementUrl string) *RoutingTree

NewDefaultRoutingTree

This function cannot error, and will choose to panic instead

func NewRoutingTreeFrom

func NewRoutingTreeFrom(data string) (*RoutingTree, error)

func (*RoutingTree) AppendReceiver

func (r *RoutingTree) AppendReceiver(recv *Receiver)

func (*RoutingTree) AppendRoute

func (r *RoutingTree) AppendRoute(updatedRoute *cfg.Route)

func (*RoutingTree) CreateRoutingNodeForCondition

func (r *RoutingTree) CreateRoutingNodeForCondition(
	conditionId string,
	endpoints *alertingv1.FullAttachedEndpoints,
	internalRouting *OpniInternalRouting,
) error

CreateRoutingNodeForCondition Takes a list of endpoint details and attaches them to a route that fires on conditionId

Modifies the internalRouting struct in place

func (*RoutingTree) DeepCopy

func (r *RoutingTree) DeepCopy() (*RoutingTree, error)

func (*RoutingTree) DeleteIndividualEndpointNode

func (r *RoutingTree) DeleteIndividualEndpointNode(
	notificationId string,
	internalRouting *OpniInternalRouting,
) ([]string, error)

DeleteIndividualEndpointNode

Returns a list of deleted conditions (if deleting this endpoint means they no longer have)

func (*RoutingTree) DeleteReceiver

func (r *RoutingTree) DeleteReceiver(conditionId string) error

func (*RoutingTree) DeleteRoute

func (r *RoutingTree) DeleteRoute(conditionId string) error

func (*RoutingTree) DeleteRoutingNodeForCondition

func (r *RoutingTree) DeleteRoutingNodeForCondition(
	conditionId string,
	internalRouting *OpniInternalRouting,
) error

func (*RoutingTree) ExtractImplementationDetails

func (r *RoutingTree) ExtractImplementationDetails(conditionId, endpointType string, position int) (*alertingv1.EndpointImplementation, error)

does the opposite of WithXXXXImplementation

func (*RoutingTree) FindReceivers

func (r *RoutingTree) FindReceivers(id string) (int, error)

Assumptions: - id is unique among receivers - Receiver Name corresponds with Ids one-to-one

func (*RoutingTree) FindRoutes

func (r *RoutingTree) FindRoutes(conditionId string) (int, error)

Assumptions: - id is unique among receivers - Route Name corresponds with Ids one-to-one

func (*RoutingTree) GetReceivers

func (r *RoutingTree) GetReceivers() []*Receiver

func (*RoutingTree) GetRoutes

func (r *RoutingTree) GetRoutes() []*cfg.Route

func (*RoutingTree) IsEqual added in v0.7.0

func (r *RoutingTree) IsEqual(other *RoutingTree) (equal bool, reason string)

for our purposes we will only treat receivers and routes as opni config equality

func (*RoutingTree) Marshal

func (r *RoutingTree) Marshal() ([]byte, error)

func (*RoutingTree) Parse

func (r *RoutingTree) Parse(data string) error

func (*RoutingTree) SetDefaultSMTPFrom

func (r *RoutingTree) SetDefaultSMTPFrom()

func (*RoutingTree) SetDefaultSMTPServer

func (r *RoutingTree) SetDefaultSMTPServer()

func (*RoutingTree) UnsetSMTPServer

func (r *RoutingTree) UnsetSMTPServer()

func (*RoutingTree) UpdateIndividualEndpointNode

func (r *RoutingTree) UpdateIndividualEndpointNode(
	req *alertingv1.FullAttachedEndpoint,
	internalRouting *OpniInternalRouting,
) error

UpdateIndividualEndpointNode

req contains the new updated details

func (*RoutingTree) UpdateReceiver

func (r *RoutingTree) UpdateReceiver(id string, recv *Receiver) error

func (*RoutingTree) UpdateRoutingNodeForCondition

func (r *RoutingTree) UpdateRoutingNodeForCondition(
	conditionId string,
	endpoints *alertingv1.FullAttachedEndpoints,
	internalRouting *OpniInternalRouting,
) error

type SlackConfig

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

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

	// string since the string is stored in a kube secret anyways
	APIURL     string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
	APIURLFile string `yaml:"api_url_file,omitempty" json:"api_url_file,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"`
	Fields      []*cfg.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     []*cfg.SlackAction `yaml:"actions,omitempty" json:"actions,omitempty"`
}

func NewSlackReceiverNode

func NewSlackReceiverNode(endpoint *alertingv1.SlackEndpoint) (*SlackConfig, error)

func WithSlackImplementation

func WithSlackImplementation(
	slack *SlackConfig,
	impl *alertingv1.EndpointImplementation,
) (*SlackConfig, error)

func (*SlackConfig) UnmarshalYAML

func (c *SlackConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type TraversalOp

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

Jump to

Keyboard shortcuts

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