Documentation ¶
Index ¶
- Variables
- func AppRouteName(aid string, rname string) string
- func CopyMap[K, V comparable](m map[K]V) map[K]V
- func NewJsonParse(jsonData []byte) (*conf.Parser, error)
- func ReceiverTypeValidator(input ReceiverType) error
- func TenantReceiverName(tid string, ori string) string
- type Config
- type EmailConfig
- type GlobalConfig
- type HostPort
- type InhibitRule
- type MessageConfig
- type Receiver
- type ReceiverConfigs
- type ReceiverKey
- type ReceiverType
- type Route
- type TimeInterval
- type URL
- type WebhookConfig
Constants ¶
This section is empty.
Variables ¶
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") )
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 CopyMap ¶
func CopyMap[K, V comparable](m map[K]V) map[K]V
func NewJsonParse ¶
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 ¶
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 (*Config) UnmarshalJSON ¶
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 ¶
HostPort represents a "host:port" network address.
func (HostPort) MarshalGQL ¶
func (*HostPort) UnmarshalGQL ¶
func (*HostPort) UnmarshalText ¶
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 ¶
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 ¶
func (URL) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for URL.
func (*URL) UnmarshalJSON ¶
UnmarshalJSON implements the json.Marshaler interface for URL.
func (*URL) UnmarshalText ¶
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