profile

package
v0.0.0-...-9f34937 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRouteProvided      = errors.New("no routes provided")
	ErrNeedTimeIntervalName = errors.New("time interval name must not be empty")
	ErrRootMissReceiver     = errors.New("root route must specify a default receiver")
	ErrRootMustNoMatcher    = errors.New("root route must not have any matchers")
	ErrRootMustNoMute       = errors.New("root route must not have any mute time intervals")
	ErrRootMustNoActive     = errors.New("root route must not have any active time intervals")
)
View Source
var (
	DefaultMessageConfig = MessageConfig{
		SendResolved: false,
		Subject:      `{{ template "message.default.subject" . }}`,
		HTML:         `{{ template "message.default.html" . }}`,
		Extras:       make(map[string]string),
	}
	// DefaultWebhookConfig defines default values for Webhook configurations.
	DefaultWebhookConfig = WebhookConfig{
		SendResolved: true,
		Subject:      `{{ template "webhook.default.subject" . }}`,
		Body:         `{{ template "webhook.default.body" . }}`,
	}
	// DefaultEmailConfig defines default values for Email configurations.
	DefaultEmailConfig = EmailConfig{
		SendResolved: false,
		HTML:         `{{ template "email.default.html" . }}`,
		Text:         ``,
		Subject:      `{{ template "email.default.subject" . }}`,
	}
)

Functions

func AppRouteName

func AppRouteName(aid string, rname string) string

func CopyMap

func CopyMap[K, V comparable](m map[K]V) map[K]V

func NewJsonParse

func NewJsonParse(jsonData []byte) (*conf.Parser, error)

NewJsonParse returns a new Koanf instance with the JSON parser loaded. Use koanf for unmarshalling JSON data to map[string]interface{}.

func ReceiverTypeValidator

func ReceiverTypeValidator(input ReceiverType) error

func TenantReceiverName

func TenantReceiverName(tid string, ori string) string

TenantReceiverName extends the receiver name with the tenant ID.

Types

type Config

type Config struct {
	Global       *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
	Route        *Route        `yaml:"route,omitempty" json:"route,omitempty"`
	InhibitRules []InhibitRule `yaml:"inhibitRules,omitempty" json:"inhibitRules,omitempty"`
	Receivers    []Receiver    `yaml:"receivers,omitempty" json:"receivers,omitempty"`
	Templates    []string      `yaml:"templates" json:"templates"`
	// time_interval指定了一个命名的时间间隔,该时间间隔可以在路由树中引用,以便在一天中的特定时间静音/激活特定路由。
	TimeIntervals []TimeInterval `yaml:"timeIntervals,omitempty" json:"timeIntervals,omitempty"`
}

Config 为根配置文件.所有配置的变化都会使体现在Config对象中.

func Load

func Load(bytes []byte) (c *Config, err error)

Load 加载主配置yaml文件

func NewConfig

func NewConfig(cfg *conf.Configuration) (c *Config, err error)

func (*Config) DeepClone

func (c *Config) DeepClone() (*Config, error)

DeepClone returns a deep clone of the config.

func (*Config) String

func (c *Config) String() string

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(bytes []byte) error

func (*Config) Validate

func (c *Config) Validate() error

type EmailConfig

type EmailConfig struct {
	SendResolved bool `yaml:"sendResolved" json:"sendResolved"`
	// Email address to notify.
	// To 一般采用模板的方式接收动态参数
	To           string            `yaml:"to,omitempty" json:"to,omitempty"`
	From         string            `yaml:"from,omitempty" json:"from,omitempty"`
	Subject      string            `yaml:"subject,omitempty" json:"subject,omitempty"`
	SmartHost    HostPort          `yaml:"smartHost,omitempty" json:"smartHost,omitempty"`
	AuthType     string            `yaml:"authType,omitempty" json:"authType,omitempty"`
	AuthUsername string            `yaml:"authUsername,omitempty" json:"authUsername,omitempty"`
	AuthPassword string            `yaml:"authPassword,omitempty" json:"authPassword,omitempty"`
	AuthSecret   string            `yaml:"authSecret,omitempty" json:"authSecret,omitempty"`
	AuthIdentity string            `yaml:"authIdentity,omitempty" json:"authIdentity,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:"requireTls,omitempty" json:"requireTls,omitempty"`
	TLSConfig    *conf.TLS         `yaml:"tls,omitempty" json:"tls,omitempty"`
}

EmailConfig configures notifications via mail.

func (*EmailConfig) Clone

func (c *EmailConfig) Clone() *EmailConfig

func (*EmailConfig) UnmarshalJSON

func (c *EmailConfig) UnmarshalJSON(bytes []byte) error

func (*EmailConfig) Validate

func (c *EmailConfig) Validate() error

type GlobalConfig

type GlobalConfig struct {
	// ResolveTimeout是声明警报的时间,如果警报没有更新,则在此之后警报被解决。
	ResolveTimeout time.Duration `yaml:"resolveTimeout" json:"resolveTimeout"`
	// SMTP 全局配置
	SMTPFrom             string    `yaml:"smtpFrom,omitempty" json:"smtpFrom,omitempty"`
	SMTPSmartHost        *HostPort `yaml:"smtpSmartHost,omitempty" json:"smtpSmartHost,omitempty"`
	SMTPAuthUsername     string    `yaml:"smtpAuthUsername,omitempty" json:"smtpAuthUsername,omitempty"`
	SMTPAuthPassword     string    `yaml:"smtpAuthPassword,omitempty" json:"smtpAuthPassword,omitempty"`
	SMTPAuthPasswordFile string    `yaml:"smtpAuthPasswordFile,omitempty" json:"smtpAuthPasswordFile,omitempty"`
	SMTPAuthSecret       string    `yaml:"smtpAuthSecret,omitempty" json:"smtpAuthSecret,omitempty"`
	SMTPAuthIdentity     string    `yaml:"smtpAuthIdentity,omitempty" json:"smtpAuthIdentity,omitempty"`
	SMTPRequireTLS       bool      `yaml:"smtpRequireTls" json:"smtpRequireTls,omitempty"`
}

GlobalConfig Global configuration defines basic configuration items.

func DefaultGlobalConfig

func DefaultGlobalConfig() GlobalConfig

DefaultGlobalConfig returns GlobalConfig with default values.

func (*GlobalConfig) UnmarshalJSON

func (g *GlobalConfig) UnmarshalJSON(data []byte) error

type HostPort

type HostPort struct {
	Host string `json:"host,omitempty"`
	Port string `json:"port,omitempty"`
}

HostPort represents a "host:port" network address.

func (HostPort) MarshalGQL

func (h HostPort) MarshalGQL(w io.Writer)

func (*HostPort) String

func (h *HostPort) String() string

func (*HostPort) UnmarshalGQL

func (h *HostPort) UnmarshalGQL(v interface{}) (err error)

func (*HostPort) UnmarshalText

func (h *HostPort) UnmarshalText(in []byte) (err error)

type InhibitRule

type InhibitRule struct {
	// SourceMatchers defines a set of label matchers that have to be fulfilled for source alerts.
	SourceMatchers label.Matchers `yaml:"sourceMatchers,omitempty" json:"sourceMatchers,omitempty"`
	// TargetMatchers defines a set of label matchers that have to be fulfilled for target alerts.
	TargetMatchers label.Matchers `yaml:"targetMatchers,omitempty" json:"targetMatchers,omitempty"`
	// A set of labels that must be equal between the source and target alert
	// for them to be a match.
	Equal []label.LabelName `yaml:"equal,omitempty" json:"equal,omitempty"`
}

InhibitRule 抑制规则.

type MessageConfig

type MessageConfig struct {
	SendResolved bool `yaml:"sendResolved" json:"sendResolved"`
	// To is user-ids.
	To      string `yaml:"to,omitempty" json:"to,omitempty"`
	Subject string `yaml:"subject,omitempty" json:"subject,omitempty"`
	HTML    string `yaml:"html,omitempty" json:"html,omitempty"`
	Text    string `yaml:"text,omitempty" json:"text,omitempty"`
	// URL is the url of message redirect.
	Redirect string `yaml:"url,omitempty" json:"url,omitempty"`
	// key-values
	Extras map[string]string `yaml:"extras,omitempty" json:"extras,omitempty"`
}

MessageConfig configures notifications via internal message.

func (*MessageConfig) Clone

func (c *MessageConfig) Clone() *MessageConfig

func (*MessageConfig) UnmarshalJSON

func (c *MessageConfig) UnmarshalJSON(bytes []byte) error

type Receiver

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

	// MessageConfigs indicates whether using the internal message system.
	MessageConfig  *MessageConfig   `yaml:"messageConfig,omitempty" json:"messageConfig,omitempty"`
	EmailConfigs   []*EmailConfig   `yaml:"emailConfigs,omitempty" json:"emailConfigs,omitempty"`
	WebhookConfigs []*WebhookConfig `yaml:"webhookConfigs,omitempty" json:"webhookConfigs,omitempty"`
}

Receiver configuration provides configuration on how to contact a receiver.

type ReceiverConfigs

type ReceiverConfigs interface {
	EmailConfig | WebhookConfig | MessageConfig
}

ReceiverConfigs is a union type for all receiver configs.

type ReceiverKey

type ReceiverKey struct {
	// Configured name of the receiver.
	Name string
	// Name of the integration of the receiver.
	Integration string
	// Index of the receiver with respect to the integration.
	// Every integration in a group may have 0..N configurations.
	Index uint32
}

ReceiverKey identifies a receiver with the position of a receiver group.

type ReceiverType

type ReceiverType string
const (
	ReceiverEmail   ReceiverType = "email"
	ReceiverMessage ReceiverType = "message"
	ReceiverWebhook ReceiverType = "webhook"
)

func (ReceiverType) MarshalGQL

func (r ReceiverType) MarshalGQL(w io.Writer)

MarshalGQL implements graphql.Marshaler interface.

func (ReceiverType) String

func (r ReceiverType) String() string

func (*ReceiverType) UnmarshalGQL

func (r *ReceiverType) UnmarshalGQL(val interface{}) error

UnmarshalGQL implements graphql.Unmarshaler interface.

func (ReceiverType) Values

func (r ReceiverType) Values() []string

type Route

type Route struct {
	Name                string            `yaml:"name,omitempty" json:"name,omitempty"`
	Receiver            string            `yaml:"receiver,omitempty" json:"receiver,omitempty"`
	GroupBy             []label.LabelName `yaml:"groupBy,omitempty" json:"groupBy,omitempty"`
	GroupByAll          bool              `yaml:"-" json:"-"`
	Matchers            label.Matchers    `yaml:"matchers,omitempty" json:"matchers,omitempty"`
	MuteTimeIntervals   []string          `yaml:"muteTimeIntervals,omitempty" json:"muteTimeIntervals,omitempty"`
	ActiveTimeIntervals []string          `yaml:"activeTimeIntervals,omitempty" json:"activeTimeIntervals,omitempty"`
	Continue            bool              `yaml:"continue" json:"continue,omitempty"`
	Routes              []*Route          `yaml:"routes,omitempty" json:"routes,omitempty"`

	GroupWait      *time.Duration `yaml:"groupWait,omitempty" json:"groupWait,omitempty"`
	GroupInterval  *time.Duration `yaml:"groupInterval,omitempty" json:"groupInterval,omitempty"`
	RepeatInterval *time.Duration `yaml:"repeatInterval,omitempty" json:"repeatInterval,omitempty"`
}

A Route is a node that contains definitions of how to handle alerts.

func (*Route) UnmarshalJSON

func (r *Route) UnmarshalJSON(data []byte) error

func (*Route) Validate

func (r *Route) Validate() error

type TimeInterval

type TimeInterval struct {
	Name          string                      `yaml:"name" json:"name"`
	TimeIntervals []timeinterval.TimeInterval `yaml:"timeIntervals" json:"timeIntervals"`
}

TimeInterval represents a named set of time intervals for which a route should be muted.

func (*TimeInterval) UnmarshalJSON

func (t *TimeInterval) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json interface.

type URL

type URL url.URL

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for URL.

func (URL) String

func (u URL) String() string

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler interface for URL.

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(data []byte) error

type WebhookConfig

type WebhookConfig struct {
	SendResolved bool `yaml:"sendResolved" json:"sendResolved"`
	// HTTPConfig configures the HTTP client used to send the webhook. Unmarshalled by custom logic.
	HTTPConfig    *httpx.ClientConfig `yaml:"httpConfig" json:"httpConfig"`
	HttpConfigOri *conf.Configuration `yaml:"-" json:"-"`
	// URL to send POST request to.
	URL *URL `yaml:"url" json:"url"`
	// MaxAlerts is the maximum number of alerts to be sent per webhook message.
	// Alerts exceeding this threshold will be truncated. Setting this to 0
	// allows an unlimited number of alerts.
	MaxAlerts uint64 `yaml:"maxAlerts" json:"maxAlerts"`
	// HTTP Headers.
	Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"`
	// Template for POST message body.
	Subject string `yaml:"subject,omitempty" json:"subject,omitempty"`
	// Body is a template with JSON-string. WebHook uses application/json content type.
	Body string `yaml:"body,omitempty" json:"body,omitempty"`
}

WebhookConfig configures notifications via a generic webhook.

Because the configuration of httpconfig is dynamic and requires initialization, the original configuration needs to be retained as `HttpConfigOri`. When OAuth2 is used, Webhook needs a token storage to store token, such as memory, redis, etc. The kind of storage depends on Run Mod: cluster or not.

func (*WebhookConfig) Clone

func (c *WebhookConfig) Clone() *WebhookConfig

Clone returns a deep clone of the WebhookConfig.

func (*WebhookConfig) UnmarshalJSON

func (c *WebhookConfig) UnmarshalJSON(data []byte) error

func (*WebhookConfig) Validate

func (c *WebhookConfig) Validate() error

Jump to

Keyboard shortcuts

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