2015-09-25 14:14:30 +00:00
|
|
|
// Copyright 2015 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-09-22 12:41:25 +00:00
|
|
|
"net/textproto"
|
2019-05-13 12:51:26 +00:00
|
|
|
"regexp"
|
2015-10-29 13:34:24 +00:00
|
|
|
"strings"
|
2022-12-07 21:13:03 +00:00
|
|
|
"text/template"
|
2016-02-26 08:35:00 +00:00
|
|
|
"time"
|
2017-07-27 08:48:24 +00:00
|
|
|
|
2019-05-13 12:51:26 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-07-27 08:48:24 +00:00
|
|
|
commoncfg "github.com/prometheus/common/config"
|
2021-07-30 08:11:43 +00:00
|
|
|
"github.com/prometheus/common/sigv4"
|
2015-09-25 14:14:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-12-17 12:05:06 +00:00
|
|
|
// DefaultWebhookConfig defines default values for Webhook configurations.
|
|
|
|
DefaultWebhookConfig = WebhookConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-11-08 12:54:38 +00:00
|
|
|
// DefaultWebexConfig defines default values for Webex configurations.
|
|
|
|
DefaultWebexConfig = WebexConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
|
|
|
Message: `{{ template "webex.default.message" . }}`,
|
|
|
|
}
|
|
|
|
|
2022-06-10 14:17:14 +00:00
|
|
|
// DefaultDiscordConfig defines default values for Discord configurations.
|
|
|
|
DefaultDiscordConfig = DiscordConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
|
|
|
Title: `{{ template "discord.default.title" . }}`,
|
|
|
|
Message: `{{ template "discord.default.message" . }}`,
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:10:38 +00:00
|
|
|
// DefaultEmailConfig defines default values for Email configurations.
|
|
|
|
DefaultEmailConfig = EmailConfig{
|
2015-12-17 12:05:06 +00:00
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: false,
|
|
|
|
},
|
2016-11-21 10:09:49 +00:00
|
|
|
HTML: `{{ template "email.default.html" . }}`,
|
2017-09-07 15:24:19 +00:00
|
|
|
Text: ``,
|
2015-11-20 14:10:38 +00:00
|
|
|
}
|
2015-11-26 17:19:46 +00:00
|
|
|
|
|
|
|
// DefaultEmailSubject defines the default Subject header of an Email.
|
|
|
|
DefaultEmailSubject = `{{ template "email.default.subject" . }}`
|
2015-11-20 14:10:38 +00:00
|
|
|
|
2018-07-05 07:54:28 +00:00
|
|
|
// 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 }}`,
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:10:38 +00:00
|
|
|
// DefaultPagerdutyConfig defines default values for PagerDuty configurations.
|
|
|
|
DefaultPagerdutyConfig = PagerdutyConfig{
|
2015-12-17 12:05:06 +00:00
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
2015-11-26 17:19:46 +00:00
|
|
|
Description: `{{ template "pagerduty.default.description" .}}`,
|
|
|
|
Client: `{{ template "pagerduty.default.client" . }}`,
|
|
|
|
ClientURL: `{{ template "pagerduty.default.clientURL" . }}`,
|
2015-11-20 14:10:38 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// DefaultSlackConfig defines default values for Slack configurations.
|
2015-09-25 14:14:30 +00:00
|
|
|
DefaultSlackConfig = SlackConfig{
|
2015-12-17 12:05:06 +00:00
|
|
|
NotifierConfig: NotifierConfig{
|
2016-01-05 18:01:21 +00:00
|
|
|
VSendResolved: false,
|
2015-12-17 12:05:06 +00:00
|
|
|
},
|
2018-10-23 09:22:23 +00:00
|
|
|
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" . }}`,
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2015-11-24 22:29:25 +00:00
|
|
|
|
|
|
|
// DefaultOpsGenieConfig defines default values for OpsGenie configurations.
|
|
|
|
DefaultOpsGenieConfig = OpsGenieConfig{
|
2015-12-17 12:05:06 +00:00
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
2016-07-12 12:36:20 +00:00
|
|
|
Message: `{{ template "opsgenie.default.message" . }}`,
|
2015-11-26 17:19:46 +00:00
|
|
|
Description: `{{ template "opsgenie.default.description" . }}`,
|
2015-11-30 10:21:08 +00:00
|
|
|
Source: `{{ template "opsgenie.default.source" . }}`,
|
2015-11-24 22:29:25 +00:00
|
|
|
// TODO: Add a details field with all the alerts.
|
|
|
|
}
|
2016-02-26 08:35:00 +00:00
|
|
|
|
2017-12-09 15:20:22 +00:00
|
|
|
// DefaultWechatConfig defines default values for wechat configurations.
|
|
|
|
DefaultWechatConfig = WechatConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
2018-03-02 08:49:41 +00:00
|
|
|
VSendResolved: false,
|
2017-12-09 15:20:22 +00:00
|
|
|
},
|
2019-05-15 02:47:20 +00:00
|
|
|
Message: `{{ template "wechat.default.message" . }}`,
|
|
|
|
ToUser: `{{ template "wechat.default.to_user" . }}`,
|
|
|
|
ToParty: `{{ template "wechat.default.to_party" . }}`,
|
|
|
|
ToTag: `{{ template "wechat.default.to_tag" . }}`,
|
|
|
|
AgentID: `{{ template "wechat.default.agent_id" . }}`,
|
2017-12-09 15:20:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-03 15:33:44 +00:00
|
|
|
// DefaultVictorOpsConfig defines default values for VictorOps configurations.
|
|
|
|
DefaultVictorOpsConfig = VictorOpsConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
2017-07-03 09:44:53 +00:00
|
|
|
MessageType: `CRITICAL`,
|
|
|
|
StateMessage: `{{ template "victorops.default.state_message" . }}`,
|
|
|
|
EntityDisplayName: `{{ template "victorops.default.entity_display_name" . }}`,
|
|
|
|
MonitoringTool: `{{ template "victorops.default.monitoring_tool" . }}`,
|
2016-07-03 15:33:44 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 08:35:00 +00:00
|
|
|
// DefaultPushoverConfig defines default values for Pushover configurations.
|
|
|
|
DefaultPushoverConfig = PushoverConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
|
|
|
Title: `{{ template "pushover.default.title" . }}`,
|
|
|
|
Message: `{{ template "pushover.default.message" . }}`,
|
|
|
|
URL: `{{ template "pushover.default.url" . }}`,
|
|
|
|
Priority: `{{ if eq .Status "firing" }}2{{ else }}0{{ end }}`, // emergency (firing) or normal
|
|
|
|
Retry: duration(1 * time.Minute),
|
|
|
|
Expire: duration(1 * time.Hour),
|
2018-12-18 14:15:30 +00:00
|
|
|
HTML: false,
|
2016-02-26 08:35:00 +00:00
|
|
|
}
|
2021-06-10 02:13:26 +00:00
|
|
|
|
|
|
|
// DefaultSNSConfig defines default values for SNS configurations.
|
|
|
|
DefaultSNSConfig = SNSConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
2021-06-16 19:41:30 +00:00
|
|
|
Subject: `{{ template "sns.default.subject" . }}`,
|
|
|
|
Message: `{{ template "sns.default.message" . }}`,
|
2021-06-10 02:13:26 +00:00
|
|
|
}
|
2022-02-22 16:51:02 +00:00
|
|
|
|
|
|
|
DefaultTelegramConfig = TelegramConfig{
|
|
|
|
NotifierConfig: NotifierConfig{
|
|
|
|
VSendResolved: true,
|
|
|
|
},
|
|
|
|
DisableNotifications: false,
|
|
|
|
Message: `{{ template "telegram.default.message" . }}`,
|
2022-06-03 10:04:19 +00:00
|
|
|
ParseMode: "HTML",
|
2022-02-22 16:51:02 +00:00
|
|
|
}
|
2015-11-20 14:10:38 +00:00
|
|
|
)
|
2015-10-09 10:03:15 +00:00
|
|
|
|
2015-12-17 12:05:06 +00:00
|
|
|
// NotifierConfig contains base options common across all notifier configurations.
|
|
|
|
type NotifierConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
VSendResolved bool `yaml:"send_resolved" json:"send_resolved"`
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 12:05:06 +00:00
|
|
|
func (nc *NotifierConfig) SendResolved() bool {
|
|
|
|
return nc.VSendResolved
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 12:54:38 +00:00
|
|
|
// WebexConfig configures notifications via Webex.
|
|
|
|
type WebexConfig struct {
|
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
2022-11-09 14:16:00 +00:00
|
|
|
APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
2022-11-08 12:54:38 +00:00
|
|
|
|
2022-12-15 15:48:01 +00:00
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
RoomID string `yaml:"room_id" json:"room_id"`
|
2022-11-08 12:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *WebexConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultWebexConfig
|
|
|
|
type plain WebexConfig
|
2022-11-09 14:16:00 +00:00
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RoomID == "" {
|
|
|
|
return fmt.Errorf("missing room_id on webex_config")
|
|
|
|
}
|
|
|
|
|
2022-12-15 15:48:01 +00:00
|
|
|
if c.HTTPConfig == nil || c.HTTPConfig.Authorization == nil {
|
|
|
|
return fmt.Errorf("missing webex_configs.http_config.authorization")
|
2022-11-09 18:26:06 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 14:16:00 +00:00
|
|
|
return nil
|
2022-11-08 12:54:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 14:17:14 +00:00
|
|
|
// DiscordConfig configures notifications via Discord.
|
|
|
|
type DiscordConfig struct {
|
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
|
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
WebhookURL *SecretURL `yaml:"webhook_url,omitempty" json:"webhook_url,omitempty"`
|
|
|
|
|
|
|
|
Title string `yaml:"title,omitempty" json:"title,omitempty"`
|
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *DiscordConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultDiscordConfig
|
|
|
|
type plain DiscordConfig
|
|
|
|
return unmarshal((*plain)(c))
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// EmailConfig configures notifications via mail.
|
2015-09-25 14:14:30 +00:00
|
|
|
type EmailConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2015-12-17 12:05:06 +00:00
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// Email address to notify.
|
2022-09-16 12:36:57 +00:00
|
|
|
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 HostPort `yaml:"smarthost,omitempty" json:"smarthost,omitempty"`
|
|
|
|
AuthUsername string `yaml:"auth_username,omitempty" json:"auth_username,omitempty"`
|
|
|
|
AuthPassword Secret `yaml:"auth_password,omitempty" json:"auth_password,omitempty"`
|
|
|
|
AuthPasswordFile string `yaml:"auth_password_file,omitempty" json:"auth_password_file,omitempty"`
|
|
|
|
AuthSecret Secret `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 commoncfg.TLSConfig `yaml:"tls_config,omitempty" json:"tls_config,omitempty"`
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
2015-10-11 10:34:05 +00:00
|
|
|
*c = DefaultEmailConfig
|
2015-09-25 14:14:30 +00:00
|
|
|
type plain EmailConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-10-29 13:34:24 +00:00
|
|
|
if c.To == "" {
|
|
|
|
return fmt.Errorf("missing to address in email config")
|
|
|
|
}
|
|
|
|
// Header names are case-insensitive, check for collisions.
|
2015-11-20 14:10:38 +00:00
|
|
|
normalizedHeaders := map[string]string{}
|
2015-10-29 13:34:24 +00:00
|
|
|
for h, v := range c.Headers {
|
2022-09-22 12:41:25 +00:00
|
|
|
normalized := textproto.CanonicalMIMEHeaderKey(h)
|
2015-11-20 14:10:38 +00:00
|
|
|
if _, ok := normalizedHeaders[normalized]; ok {
|
|
|
|
return fmt.Errorf("duplicate header %q in email config", normalized)
|
2015-10-29 13:34:24 +00:00
|
|
|
}
|
2015-11-20 14:10:38 +00:00
|
|
|
normalizedHeaders[normalized] = v
|
2015-10-29 13:34:24 +00:00
|
|
|
}
|
2015-11-20 14:10:38 +00:00
|
|
|
c.Headers = normalizedHeaders
|
2015-10-29 13:34:24 +00:00
|
|
|
|
2018-04-17 14:22:46 +00:00
|
|
|
return nil
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 14:10:38 +00:00
|
|
|
// PagerdutyConfig configures notifications via PagerDuty.
|
|
|
|
type PagerdutyConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2015-12-17 12:05:06 +00:00
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2022-10-14 12:55:59 +00:00
|
|
|
ServiceKey Secret `yaml:"service_key,omitempty" json:"service_key,omitempty"`
|
|
|
|
ServiceKeyFile string `yaml:"service_key_file,omitempty" json:"service_key_file,omitempty"`
|
|
|
|
RoutingKey Secret `yaml:"routing_key,omitempty" json:"routing_key,omitempty"`
|
|
|
|
RoutingKeyFile string `yaml:"routing_key_file,omitempty" json:"routing_key_file,omitempty"`
|
|
|
|
URL *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 []PagerdutyImage `yaml:"images,omitempty" json:"images,omitempty"`
|
|
|
|
Links []PagerdutyLink `yaml:"links,omitempty" json:"links,omitempty"`
|
|
|
|
Source string `yaml:"source,omitempty" json:"source,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"`
|
2015-11-20 14:10:38 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 08:45:53 +00:00
|
|
|
// PagerdutyLink is a link
|
|
|
|
type PagerdutyLink struct {
|
2019-10-29 09:46:40 +00:00
|
|
|
Href string `yaml:"href,omitempty" json:"href,omitempty"`
|
2018-10-02 08:45:53 +00:00
|
|
|
Text string `yaml:"text,omitempty" json:"text,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// PagerdutyImage is an image
|
|
|
|
type PagerdutyImage struct {
|
|
|
|
Src string `yaml:"src,omitempty" json:"src,omitempty"`
|
|
|
|
Alt string `yaml:"alt,omitempty" json:"alt,omitempty"`
|
2019-06-24 10:19:06 +00:00
|
|
|
Href string `yaml:"href,omitempty" json:"href,omitempty"`
|
2018-10-02 08:45:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 14:10:38 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultPagerdutyConfig
|
|
|
|
type plain PagerdutyConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-14 12:55:59 +00:00
|
|
|
if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" {
|
2017-11-07 10:07:27 +00:00
|
|
|
return fmt.Errorf("missing service or routing key in PagerDuty config")
|
2015-11-20 14:10:38 +00:00
|
|
|
}
|
2022-10-14 12:55:59 +00:00
|
|
|
if len(c.RoutingKey) > 0 && len(c.RoutingKeyFile) > 0 {
|
|
|
|
return fmt.Errorf("at most one of routing_key & routing_key_file must be configured")
|
|
|
|
}
|
|
|
|
if len(c.ServiceKey) > 0 && len(c.ServiceKeyFile) > 0 {
|
|
|
|
return fmt.Errorf("at most one of service_key & service_key_file must be configured")
|
|
|
|
}
|
2018-07-05 07:54:28 +00:00
|
|
|
if c.Details == nil {
|
|
|
|
c.Details = make(map[string]string)
|
|
|
|
}
|
2022-10-13 12:01:46 +00:00
|
|
|
if c.Source == "" {
|
|
|
|
c.Source = c.Client
|
|
|
|
}
|
2018-07-05 07:54:28 +00:00
|
|
|
for k, v := range DefaultPagerdutyDetails {
|
|
|
|
if _, ok := c.Details[k]; !ok {
|
|
|
|
c.Details[k] = v
|
|
|
|
}
|
|
|
|
}
|
2018-04-17 14:22:46 +00:00
|
|
|
return nil
|
2015-11-20 14:10:38 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 15:26:11 +00:00
|
|
|
// SlackAction configures a single Slack action that is sent with each notification.
|
2018-10-29 14:55:43 +00:00
|
|
|
// See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons
|
|
|
|
// for more information.
|
2018-05-14 15:26:11 +00:00
|
|
|
type SlackAction struct {
|
2018-10-29 14:55:43 +00:00
|
|
|
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"`
|
2018-05-14 15:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface for SlackAction.
|
|
|
|
func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain SlackAction
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Type == "" {
|
|
|
|
return fmt.Errorf("missing type in Slack action configuration")
|
|
|
|
}
|
|
|
|
if c.Text == "" {
|
2018-10-29 14:55:43 +00:00
|
|
|
return fmt.Errorf("missing text in Slack action configuration")
|
2018-05-14 15:26:11 +00:00
|
|
|
}
|
2018-10-29 14:55:43 +00:00
|
|
|
if c.URL != "" {
|
|
|
|
// Clear all message action fields.
|
|
|
|
c.Name = ""
|
|
|
|
c.Value = ""
|
|
|
|
c.ConfirmField = nil
|
|
|
|
} else if c.Name != "" {
|
|
|
|
c.URL = ""
|
|
|
|
} else {
|
|
|
|
return fmt.Errorf("missing name or url in Slack action configuration")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface for SlackConfirmationField.
|
|
|
|
func (c *SlackConfirmationField) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain SlackConfirmationField
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Text == "" {
|
|
|
|
return fmt.Errorf("missing text in Slack confirmation configuration")
|
2018-05-14 15:26:11 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-04-25 16:58:11 +00:00
|
|
|
// 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.
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface for SlackField.
|
|
|
|
func (c *SlackField) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
type plain SlackField
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.Title == "" {
|
|
|
|
return fmt.Errorf("missing title in Slack field configuration")
|
|
|
|
}
|
|
|
|
if c.Value == "" {
|
|
|
|
return fmt.Errorf("missing value in Slack field configuration")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// SlackConfig configures notifications via Slack.
|
2015-09-25 14:14:30 +00:00
|
|
|
type SlackConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2015-12-17 12:05:06 +00:00
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2021-04-02 01:57:55 +00:00
|
|
|
APIURL *SecretURL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
|
|
|
APIURLFile string `yaml:"api_url_file,omitempty" json:"api_url_file,omitempty"`
|
2015-09-25 14:14:30 +00:00
|
|
|
|
|
|
|
// Slack channel override, (like #other-channel or @username).
|
2017-06-20 17:09:14 +00:00
|
|
|
Channel string `yaml:"channel,omitempty" json:"channel,omitempty"`
|
|
|
|
Username string `yaml:"username,omitempty" json:"username,omitempty"`
|
|
|
|
Color string `yaml:"color,omitempty" json:"color,omitempty"`
|
|
|
|
|
2018-05-14 15:26:11 +00:00
|
|
|
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 []*SlackField `yaml:"fields,omitempty" json:"fields,omitempty"`
|
2020-07-24 12:58:59 +00:00
|
|
|
ShortFields bool `yaml:"short_fields" json:"short_fields,omitempty"`
|
2018-05-14 15:26:11 +00:00
|
|
|
Footer string `yaml:"footer,omitempty" json:"footer,omitempty"`
|
|
|
|
Fallback string `yaml:"fallback,omitempty" json:"fallback,omitempty"`
|
2018-10-23 09:22:23 +00:00
|
|
|
CallbackID string `yaml:"callback_id,omitempty" json:"callback_id,omitempty"`
|
2018-05-14 15:26:11 +00:00
|
|
|
IconEmoji string `yaml:"icon_emoji,omitempty" json:"icon_emoji,omitempty"`
|
|
|
|
IconURL string `yaml:"icon_url,omitempty" json:"icon_url,omitempty"`
|
2018-08-13 13:14:45 +00:00
|
|
|
ImageURL string `yaml:"image_url,omitempty" json:"image_url,omitempty"`
|
|
|
|
ThumbURL string `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"`
|
2020-07-24 12:58:59 +00:00
|
|
|
LinkNames bool `yaml:"link_names" json:"link_names,omitempty"`
|
2019-07-31 10:04:59 +00:00
|
|
|
MrkdwnIn []string `yaml:"mrkdwn_in,omitempty" json:"mrkdwn_in,omitempty"`
|
2018-05-14 15:26:11 +00:00
|
|
|
Actions []*SlackAction `yaml:"actions,omitempty" json:"actions,omitempty"`
|
2015-10-09 08:48:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *SlackConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultSlackConfig
|
|
|
|
type plain SlackConfig
|
2021-04-02 01:57:55 +00:00
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.APIURL != nil && len(c.APIURLFile) > 0 {
|
|
|
|
return fmt.Errorf("at most one of api_url & api_url_file must be configured")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-12 11:57:20 +00:00
|
|
|
// WebhookConfig configures notifications via a generic webhook.
|
2015-09-25 14:14:30 +00:00
|
|
|
type WebhookConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2015-12-17 12:05:06 +00:00
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2015-09-25 14:14:30 +00:00
|
|
|
// URL to send POST request to.
|
2023-03-03 14:31:14 +00:00
|
|
|
URL *SecretURL `yaml:"url" json:"url"`
|
|
|
|
URLFile string `yaml:"url_file" json:"url_file"`
|
2023-02-02 16:23:51 +00:00
|
|
|
|
2020-06-04 08:07:33 +00:00
|
|
|
// 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:"max_alerts" json:"max_alerts"`
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *WebhookConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
2015-12-17 12:05:06 +00:00
|
|
|
*c = DefaultWebhookConfig
|
2015-09-25 14:14:30 +00:00
|
|
|
type plain WebhookConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-03 14:31:14 +00:00
|
|
|
if c.URL == nil && c.URLFile == "" {
|
|
|
|
return fmt.Errorf("one of url or url_file must be configured")
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2023-03-03 14:31:14 +00:00
|
|
|
if c.URL != nil && c.URLFile != "" {
|
|
|
|
return fmt.Errorf("at most one of url & url_file must be configured")
|
|
|
|
}
|
|
|
|
if c.URL != nil {
|
|
|
|
if c.URL.Scheme != "https" && c.URL.Scheme != "http" {
|
|
|
|
return fmt.Errorf("scheme required for webhook url")
|
|
|
|
}
|
2017-12-07 14:01:16 +00:00
|
|
|
}
|
2018-04-17 14:22:46 +00:00
|
|
|
return nil
|
2015-09-25 14:14:30 +00:00
|
|
|
}
|
2015-11-24 22:29:25 +00:00
|
|
|
|
2017-12-09 15:20:22 +00:00
|
|
|
// WechatConfig configures notifications via Wechat.
|
|
|
|
type WechatConfig struct {
|
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
|
2018-02-06 14:43:49 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2020-07-06 13:56:42 +00:00
|
|
|
APISecret Secret `yaml:"api_secret,omitempty" json:"api_secret,omitempty"`
|
|
|
|
CorpID string `yaml:"corp_id,omitempty" json:"corp_id,omitempty"`
|
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
|
|
|
ToUser string `yaml:"to_user,omitempty" json:"to_user,omitempty"`
|
|
|
|
ToParty string `yaml:"to_party,omitempty" json:"to_party,omitempty"`
|
|
|
|
ToTag string `yaml:"to_tag,omitempty" json:"to_tag,omitempty"`
|
|
|
|
AgentID string `yaml:"agent_id,omitempty" json:"agent_id,omitempty"`
|
|
|
|
MessageType string `yaml:"message_type,omitempty" json:"message_type,omitempty"`
|
2017-12-09 15:20:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 13:56:42 +00:00
|
|
|
const wechatValidTypesRe = `^(text|markdown)$`
|
|
|
|
|
|
|
|
var wechatTypeMatcher = regexp.MustCompile(wechatValidTypesRe)
|
|
|
|
|
2017-12-09 15:20:22 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *WechatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultWechatConfig
|
|
|
|
type plain WechatConfig
|
2020-07-06 13:56:42 +00:00
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.MessageType == "" {
|
|
|
|
c.MessageType = "text"
|
|
|
|
}
|
|
|
|
|
|
|
|
if !wechatTypeMatcher.MatchString(c.MessageType) {
|
2022-03-25 16:59:51 +00:00
|
|
|
return errors.Errorf("weChat message type %q does not match valid options %s", c.MessageType, wechatValidTypesRe)
|
2020-07-06 13:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2017-12-09 15:20:22 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 22:29:25 +00:00
|
|
|
// OpsGenieConfig configures notifications via OpsGenie.
|
|
|
|
type OpsGenieConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2021-08-10 16:26:48 +00:00
|
|
|
APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"`
|
2021-10-21 07:29:03 +00:00
|
|
|
APIKeyFile string `yaml:"api_key_file,omitempty" json:"api_key_file,omitempty"`
|
2021-08-10 16:26:48 +00:00
|
|
|
APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
Description string `yaml:"description,omitempty" json:"description,omitempty"`
|
|
|
|
Source string `yaml:"source,omitempty" json:"source,omitempty"`
|
|
|
|
Details map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
|
2021-11-13 06:37:59 +00:00
|
|
|
Entity string `yaml:"entity,omitempty" json:"entity,omitempty"`
|
2021-08-10 16:26:48 +00:00
|
|
|
Responders []OpsGenieConfigResponder `yaml:"responders,omitempty" json:"responders,omitempty"`
|
2021-11-13 06:37:59 +00:00
|
|
|
Actions string `yaml:"actions,omitempty" json:"actions,omitempty"`
|
2021-08-10 16:26:48 +00:00
|
|
|
Tags string `yaml:"tags,omitempty" json:"tags,omitempty"`
|
|
|
|
Note string `yaml:"note,omitempty" json:"note,omitempty"`
|
|
|
|
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
|
|
|
|
UpdateAlerts bool `yaml:"update_alerts,omitempty" json:"update_alerts,omitempty"`
|
2015-11-24 22:29:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 21:32:20 +00:00
|
|
|
const opsgenieValidTypesRe = `^(team|teams|user|escalation|schedule)$`
|
2019-05-13 12:51:26 +00:00
|
|
|
|
|
|
|
var opsgenieTypeMatcher = regexp.MustCompile(opsgenieValidTypesRe)
|
|
|
|
|
2015-11-24 22:29:25 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *OpsGenieConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultOpsGenieConfig
|
|
|
|
type plain OpsGenieConfig
|
2019-05-13 12:51:26 +00:00
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-04 12:58:39 +00:00
|
|
|
if c.APIKey != "" && len(c.APIKeyFile) > 0 {
|
2021-10-21 07:29:03 +00:00
|
|
|
return fmt.Errorf("at most one of api_key & api_key_file must be configured")
|
|
|
|
}
|
|
|
|
|
2019-05-13 12:51:26 +00:00
|
|
|
for _, r := range c.Responders {
|
|
|
|
if r.ID == "" && r.Username == "" && r.Name == "" {
|
2022-03-25 16:59:51 +00:00
|
|
|
return errors.Errorf("opsGenieConfig responder %v has to have at least one of id, username or name specified", r)
|
2019-05-13 12:51:26 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 21:13:03 +00:00
|
|
|
if strings.Contains(r.Type, "{{") {
|
|
|
|
_, err := template.New("").Parse(r.Type)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Errorf("opsGenieConfig responder %v type is not a valid template: %v", r, err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r.Type = strings.ToLower(r.Type)
|
|
|
|
if !opsgenieTypeMatcher.MatchString(r.Type) {
|
|
|
|
return errors.Errorf("opsGenieConfig responder %v type does not match valid options %s", r, opsgenieValidTypesRe)
|
|
|
|
}
|
2019-05-13 12:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpsGenieConfigResponder struct {
|
|
|
|
// One of those 3 should be filled.
|
|
|
|
ID string `yaml:"id,omitempty" json:"id,omitempty"`
|
|
|
|
Name string `yaml:"name,omitempty" json:"name,omitempty"`
|
|
|
|
Username string `yaml:"username,omitempty" json:"username,omitempty"`
|
|
|
|
|
|
|
|
// team, user, escalation, schedule etc.
|
|
|
|
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
2015-11-24 22:29:25 +00:00
|
|
|
}
|
2016-02-26 08:35:00 +00:00
|
|
|
|
2016-07-03 15:33:44 +00:00
|
|
|
// VictorOpsConfig configures notifications via VictorOps.
|
|
|
|
type VictorOpsConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2016-07-03 15:33:44 +00:00
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2021-04-02 01:57:55 +00:00
|
|
|
APIKey Secret `yaml:"api_key,omitempty" json:"api_key,omitempty"`
|
2022-10-25 13:40:17 +00:00
|
|
|
APIKeyFile string `yaml:"api_key_file,omitempty" json:"api_key_file,omitempty"`
|
2019-01-15 10:59:05 +00:00
|
|
|
APIURL *URL `yaml:"api_url" json:"api_url"`
|
|
|
|
RoutingKey string `yaml:"routing_key" json:"routing_key"`
|
|
|
|
MessageType string `yaml:"message_type" json:"message_type"`
|
|
|
|
StateMessage string `yaml:"state_message" json:"state_message"`
|
|
|
|
EntityDisplayName string `yaml:"entity_display_name" json:"entity_display_name"`
|
|
|
|
MonitoringTool string `yaml:"monitoring_tool" json:"monitoring_tool"`
|
|
|
|
CustomFields map[string]string `yaml:"custom_fields,omitempty" json:"custom_fields,omitempty"`
|
2016-07-03 15:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *VictorOpsConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultVictorOpsConfig
|
|
|
|
type plain VictorOpsConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if c.RoutingKey == "" {
|
|
|
|
return fmt.Errorf("missing Routing key in VictorOps config")
|
|
|
|
}
|
2022-10-25 13:40:17 +00:00
|
|
|
if c.APIKey != "" && len(c.APIKeyFile) > 0 {
|
|
|
|
return fmt.Errorf("at most one of api_key & api_key_file must be configured")
|
|
|
|
}
|
2019-01-15 10:59:05 +00:00
|
|
|
|
|
|
|
reservedFields := []string{"routing_key", "message_type", "state_message", "entity_display_name", "monitoring_tool", "entity_id", "entity_state"}
|
|
|
|
|
|
|
|
for _, v := range reservedFields {
|
|
|
|
if _, ok := c.CustomFields[v]; ok {
|
2022-03-25 16:59:51 +00:00
|
|
|
return fmt.Errorf("victorOps config contains custom field %s which cannot be used as it conflicts with the fixed/static fields", v)
|
2019-01-15 10:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:22:46 +00:00
|
|
|
return nil
|
2016-07-03 15:33:44 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 08:35:00 +00:00
|
|
|
type duration time.Duration
|
|
|
|
|
|
|
|
func (d *duration) UnmarshalText(text []byte) error {
|
|
|
|
parsed, err := time.ParseDuration(string(text))
|
|
|
|
if err == nil {
|
|
|
|
*d = duration(parsed)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d duration) MarshalText() ([]byte, error) {
|
|
|
|
return []byte(time.Duration(d).String()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PushoverConfig struct {
|
2016-11-22 14:05:14 +00:00
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
2016-02-26 08:35:00 +00:00
|
|
|
|
2017-07-27 08:48:24 +00:00
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2023-01-18 22:33:42 +00:00
|
|
|
UserKey Secret `yaml:"user_key,omitempty" json:"user_key,omitempty"`
|
|
|
|
UserKeyFile string `yaml:"user_key_file,omitempty" json:"user_key_file,omitempty"`
|
|
|
|
Token Secret `yaml:"token,omitempty" json:"token,omitempty"`
|
|
|
|
TokenFile string `yaml:"token_file,omitempty" json:"token_file,omitempty"`
|
|
|
|
Title string `yaml:"title,omitempty" json:"title,omitempty"`
|
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
URL string `yaml:"url,omitempty" json:"url,omitempty"`
|
|
|
|
URLTitle string `yaml:"url_title,omitempty" json:"url_title,omitempty"`
|
2023-05-05 12:04:47 +00:00
|
|
|
Device string `yaml:"device,omitempty" json:"device,omitempty"`
|
2023-01-18 22:33:42 +00:00
|
|
|
Sound string `yaml:"sound,omitempty" json:"sound,omitempty"`
|
|
|
|
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
|
|
|
|
Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"`
|
|
|
|
Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"`
|
|
|
|
HTML bool `yaml:"html" json:"html,omitempty"`
|
2016-02-26 08:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *PushoverConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultPushoverConfig
|
|
|
|
type plain PushoverConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-18 22:33:42 +00:00
|
|
|
if c.UserKey == "" && c.UserKeyFile == "" {
|
|
|
|
return fmt.Errorf("one of user_key or user_key_file must be configured")
|
2016-02-26 08:35:00 +00:00
|
|
|
}
|
2023-01-18 22:33:42 +00:00
|
|
|
if c.UserKey != "" && c.UserKeyFile != "" {
|
|
|
|
return fmt.Errorf("at most one of user_key & user_key_file must be configured")
|
|
|
|
}
|
|
|
|
if c.Token == "" && c.TokenFile == "" {
|
|
|
|
return fmt.Errorf("one of token or token_file must be configured")
|
|
|
|
}
|
|
|
|
if c.Token != "" && c.TokenFile != "" {
|
|
|
|
return fmt.Errorf("at most one of token & token_file must be configured")
|
2016-02-26 08:35:00 +00:00
|
|
|
}
|
2018-04-17 14:22:46 +00:00
|
|
|
return nil
|
2016-02-26 08:35:00 +00:00
|
|
|
}
|
2021-06-10 02:13:26 +00:00
|
|
|
|
|
|
|
type SNSConfig struct {
|
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
|
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
2021-06-21 17:29:03 +00:00
|
|
|
APIUrl string `yaml:"api_url,omitempty" json:"api_url,omitempty"`
|
2021-06-23 14:00:47 +00:00
|
|
|
Sigv4 sigv4.SigV4Config `yaml:"sigv4" json:"sigv4"`
|
2021-06-10 02:13:26 +00:00
|
|
|
TopicARN string `yaml:"topic_arn,omitempty" json:"topic_arn,omitempty"`
|
|
|
|
PhoneNumber string `yaml:"phone_number,omitempty" json:"phone_number,omitempty"`
|
|
|
|
TargetARN string `yaml:"target_arn,omitempty" json:"target_arn,omitempty"`
|
2021-06-11 21:21:15 +00:00
|
|
|
Subject string `yaml:"subject,omitempty" json:"subject,omitempty"`
|
2021-06-10 02:13:26 +00:00
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
Attributes map[string]string `yaml:"attributes,omitempty" json:"attributes,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *SNSConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultSNSConfig
|
|
|
|
type plain SNSConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-16 19:27:19 +00:00
|
|
|
if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") {
|
2021-06-10 02:13:26 +00:00
|
|
|
return fmt.Errorf("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-02-22 16:51:02 +00:00
|
|
|
|
|
|
|
// TelegramConfig configures notifications via Telegram.
|
|
|
|
type TelegramConfig struct {
|
|
|
|
NotifierConfig `yaml:",inline" json:",inline"`
|
|
|
|
|
|
|
|
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
|
|
|
|
|
|
|
APIUrl *URL `yaml:"api_url" json:"api_url,omitempty"`
|
|
|
|
BotToken Secret `yaml:"bot_token,omitempty" json:"token,omitempty"`
|
2023-01-21 21:43:34 +00:00
|
|
|
BotTokenFile string `yaml:"bot_token_file,omitempty" json:"token_file,omitempty"`
|
2022-02-22 16:51:02 +00:00
|
|
|
ChatID int64 `yaml:"chat_id,omitempty" json:"chat,omitempty"`
|
|
|
|
Message string `yaml:"message,omitempty" json:"message,omitempty"`
|
|
|
|
DisableNotifications bool `yaml:"disable_notifications,omitempty" json:"disable_notifications,omitempty"`
|
|
|
|
ParseMode string `yaml:"parse_mode,omitempty" json:"parse_mode,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
|
|
func (c *TelegramConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
*c = DefaultTelegramConfig
|
|
|
|
type plain TelegramConfig
|
|
|
|
if err := unmarshal((*plain)(c)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-21 21:43:34 +00:00
|
|
|
if c.BotToken == "" && c.BotTokenFile == "" {
|
|
|
|
return fmt.Errorf("missing bot_token or bot_token_file on telegram_config")
|
|
|
|
}
|
|
|
|
if c.BotToken != "" && c.BotTokenFile != "" {
|
|
|
|
return fmt.Errorf("at most one of bot_token & bot_token_file must be configured")
|
2022-02-22 16:51:02 +00:00
|
|
|
}
|
|
|
|
if c.ChatID == 0 {
|
|
|
|
return fmt.Errorf("missing chat_id on telegram_config")
|
|
|
|
}
|
|
|
|
if c.ParseMode != "" &&
|
|
|
|
c.ParseMode != "Markdown" &&
|
|
|
|
c.ParseMode != "MarkdownV2" &&
|
|
|
|
c.ParseMode != "HTML" {
|
|
|
|
return fmt.Errorf("unknown parse_mode on telegram_config, must be Markdown, MarkdownV2, HTML or empty string")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|