Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore(channel-specs): Move channel specs to separate files (#12989)

praneeth-signoz47dd1fabf310
diff --git a/pkg/types/alertmanagertypes/channel_email.go b/pkg/types/alertmanagertypes/channel_email.go
new file mode 100644
index 0000000000..0f2e7af562
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_email.go
@@ -0,0 +1,62 @@
+package alertmanagertypes
+
+import (
+ "maps"
+ "net/textproto"
+ "slices"
+
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+)
+
+// ChannelEmailConfig carries no SMTP transport fields: the smarthost,
+// credentials and TLS settings come from the deployment's global config, so a
+// channel can only choose recipients and body.
+type ChannelEmailConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ To string `json:"to" required:"true"`
+ HTML valuer.UnsetOrNonEmptyString `json:"html"`
+ Headers map[string]string `json:"headers,omitempty"`
+}
+
+func (c ChannelEmailConfig) Validate() error {
+ if c.To == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.to is required for an email channel")
+ }
+
+ // A read reports header names as textproto canonicalizes them, turning
+ // "subject" into "Subject", so a name that is not already in that form is
+ // rejected rather than answered with one the caller never sent.
+ for _, header := range slices.Sorted(maps.Keys(c.Headers)) {
+ if canonical := textproto.CanonicalMIMEHeaderKey(header); canonical != header {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.headers name %q must be written as %q", header, canonical)
+ }
+ }
+
+ return nil
+}
+
+func (c ChannelEmailConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ EmailConfigs: []*config.EmailConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultEmailConfig.VSendResolved)},
+ To: c.To,
+ HTML: c.HTML.StringValue(),
+ Headers: c.Headers,
+ }},
+ }}, nil
+}
+
+func newChannelEmailConfigFromReceiver(_ string, receiver *Receiver) (ChannelSpec, error) {
+ email := receiver.EmailConfigs[0]
+ sendResolved := email.VSendResolved
+
+ return &ChannelEmailConfig{
+ SendResolved: &sendResolved,
+ To: email.To,
+ HTML: valuer.UnsetIfEmpty(email.HTML),
+ Headers: email.Headers,
+ }, nil
+}
diff --git a/pkg/types/alertmanagertypes/googlechat.go b/pkg/types/alertmanagertypes/channel_googlechat.go
similarity index 55%
rename from pkg/types/alertmanagertypes/googlechat.go
rename to pkg/types/alertmanagertypes/channel_googlechat.go
index 7719f0a814..b7e4a986cc 100644
--- a/pkg/types/alertmanagertypes/googlechat.go
+++ b/pkg/types/alertmanagertypes/channel_googlechat.go
@@ -5,10 +5,59 @@ import (
"strings"
"github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
"github.com/prometheus/alertmanager/config"
commoncfg "github.com/prometheus/common/config"
)
+type ChannelGoogleChatConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ WebhookURL string `json:"webhookUrl" required:"true" format:"password"`
+ Title valuer.UnsetOrNonEmptyString `json:"title"`
+ Text valuer.UnsetOrNonEmptyString `json:"text"`
+}
+
+func (c ChannelGoogleChatConfig) Validate() error {
+ if c.WebhookURL == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.webhookUrl is required for a googlechat channel")
+ }
+
+ return nil
+}
+
+func (c ChannelGoogleChatConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ webhookURL, err := parseSecretURL(c.WebhookURL)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Receiver{
+ Receiver: &config.Receiver{Name: displayName},
+ GoogleChatConfigs: []*GoogleChatReceiverConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultGoogleChatReceiverConfig.VSendResolved)},
+ WebhookURL: webhookURL,
+ Title: c.Title.StringValue(),
+ Text: c.Text.StringValue(),
+ }},
+ }, nil
+}
+
+func newChannelGoogleChatConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ googlechat := receiver.GoogleChatConfigs[0]
+ sendResolved := googlechat.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, googlechat.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelGoogleChatConfig{
+ SendResolved: &sendResolved,
+ WebhookURL: formatSecretURL(googlechat.WebhookURL),
+ Title: valuer.UnsetIfEmpty(googlechat.Title),
+ Text: valuer.UnsetIfEmpty(googlechat.Text),
+ }, nil
+}
+
type GoogleChatReceiverConfig struct {
config.NotifierConfig `yaml:",inline" json:",inline"`
diff --git a/pkg/types/alertmanagertypes/googlechat_test.go b/pkg/types/alertmanagertypes/channel_googlechat_test.go
similarity index 100%
rename from pkg/types/alertmanagertypes/googlechat_test.go
rename to pkg/types/alertmanagertypes/channel_googlechat_test.go
diff --git a/pkg/types/alertmanagertypes/incidentio.go b/pkg/types/alertmanagertypes/channel_incidentio.go
similarity index 70%
rename from pkg/types/alertmanagertypes/incidentio.go
rename to pkg/types/alertmanagertypes/channel_incidentio.go
index 2a06a54be0..65d86f670e 100644
--- a/pkg/types/alertmanagertypes/incidentio.go
+++ b/pkg/types/alertmanagertypes/channel_incidentio.go
@@ -6,10 +6,64 @@ import (
"strings"
"github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
"github.com/prometheus/alertmanager/config"
commoncfg "github.com/prometheus/common/config"
)
+type ChannelIncidentIOConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ URL string `json:"url" required:"true"`
+ Token string `json:"token" required:"true" format:"password"`
+ Title valuer.UnsetOrNonEmptyString `json:"title"`
+ Description valuer.UnsetOrNonEmptyString `json:"description"`
+ Metadata map[string]string `json:"metadata,omitempty"`
+}
+
+func (c ChannelIncidentIOConfig) Validate() error {
+ if c.URL == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.url is required for an incidentio channel")
+ }
+
+ if c.Token == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.token is required for an incidentio channel")
+ }
+
+ return nil
+}
+
+func (c ChannelIncidentIOConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ return &Receiver{
+ Receiver: &config.Receiver{Name: displayName},
+ IncidentIOConfigs: []*IncidentIOReceiverConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultIncidentIOReceiverConfig.VSendResolved)},
+ URL: c.URL,
+ Token: config.Secret(c.Token),
+ Title: c.Title.StringValue(),
+ Description: c.Description.StringValue(),
+ Metadata: c.Metadata,
+ }},
+ }, nil
+}
+
+func newChannelIncidentIOConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ incidentio := receiver.IncidentIOConfigs[0]
+ sendResolved := incidentio.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, incidentio.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelIncidentIOConfig{
+ SendResolved: &sendResolved,
+ URL: incidentio.URL,
+ Token: string(incidentio.Token),
+ Title: valuer.UnsetIfEmpty(incidentio.Title),
+ Description: valuer.UnsetIfEmpty(incidentio.Description),
+ Metadata: incidentio.Metadata,
+ }, nil
+}
+
// incidentIOEventsPathPrefix is the path of incident.io's HTTP alert source
// endpoint (Alert Events V2 API). The full URL is per-source:
// https://api.incident.io/v2/alert_events/http/<source_config_id>.
diff --git a/pkg/types/alertmanagertypes/incidentio_test.go b/pkg/types/alertmanagertypes/channel_incidentio_test.go
similarity index 100%
rename from pkg/types/alertmanagertypes/incidentio_test.go
rename to pkg/types/alertmanagertypes/channel_incidentio_test.go
diff --git a/pkg/types/alertmanagertypes/jira.go b/pkg/types/alertmanagertypes/channel_jira.go
similarity index 51%
rename from pkg/types/alertmanagertypes/jira.go
rename to pkg/types/alertmanagertypes/channel_jira.go
index 396cc39479..1fd030eb2b 100644
--- a/pkg/types/alertmanagertypes/jira.go
+++ b/pkg/types/alertmanagertypes/channel_jira.go
@@ -7,11 +7,147 @@ import (
"time"
"github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
"github.com/prometheus/alertmanager/config"
commoncfg "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
)
+type ChannelJiraConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ // Site is the Jira Cloud base URL, https://<site>.atlassian.net. Only Jira
+ // Cloud is supported; the REST base is derived from it.
+ Site string `json:"site" required:"true"`
+ Project string `json:"project" required:"true"`
+ IssueType string `json:"issueType" required:"true"`
+ Summary valuer.UnsetOrNonEmptyString `json:"summary"`
+ Description valuer.UnsetOrNonEmptyString `json:"description"`
+ Priority string `json:"priority"`
+ Labels []string `json:"labels,omitempty"`
+ ResolveTransition string `json:"resolveTransition"`
+ ReopenTransition string `json:"reopenTransition"`
+ ReopenDuration valuer.UnsetOrNonEmptyString `json:"reopenDuration"`
+ WontFixResolution string `json:"wontFixResolution"`
+ CustomFields map[string]any `json:"customFields,omitempty"`
+
+ Email string `json:"email" required:"true"`
+ APIToken string `json:"apiToken" required:"true" format:"password"`
+}
+
+func (c ChannelJiraConfig) Validate() error {
+ for _, required := range []struct {
+ value string
+ field string
+ }{
+ {c.Site, "site"},
+ {c.Project, "project"},
+ {c.IssueType, "issueType"},
+ {c.Email, "email"},
+ {c.APIToken, "apiToken"},
+ } {
+ if required.value == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.%s is required for a jira channel", required.field)
+ }
+ }
+
+ if !c.ReopenDuration.IsZero() {
+ reopenDuration, err := model.ParseDuration(c.ReopenDuration.StringValue())
+ if err != nil {
+ return errors.WrapInvalidInputf(err, ErrCodeAlertmanagerChannelInvalid, "config.spec.reopenDuration %q is not a valid duration", c.ReopenDuration)
+ }
+
+ // A read reports the duration as model.Duration formats it, collapsing
+ // "72h" into "3d", so a value that is not already in that form is rejected
+ // rather than answered with one the caller never sent.
+ if canonical := reopenDuration.String(); canonical != c.ReopenDuration.StringValue() {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.reopenDuration %q must be written as %q", c.ReopenDuration, canonical)
+ }
+ }
+
+ return nil
+}
+
+func (c ChannelJiraConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ // Seeded from upstream's default rather than a zero value: FollowRedirects
+ // and EnableHTTP2 marshal unconditionally, so a zero value would persist them
+ // as false and read back as a config ChannelJiraConfig cannot represent.
+ httpConfig := commoncfg.DefaultHTTPClientConfig
+ httpConfig.BasicAuth = &commoncfg.BasicAuth{
+ Username: c.Email,
+ Password: commoncfg.Secret(c.APIToken),
+ }
+
+ jira := &JiraReceiverConfig{
+ // JiraReceiverConfig seeds no send_resolved of its own, so unset means off.
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, false)},
+ Site: c.Site,
+ Project: c.Project,
+ IssueType: c.IssueType,
+ Summary: c.Summary.StringValue(),
+ Description: c.Description.StringValue(),
+ Priority: c.Priority,
+ Labels: c.Labels,
+ ResolveTransition: c.ResolveTransition,
+ ReopenTransition: c.ReopenTransition,
+ WontFixResolution: c.WontFixResolution,
+ CustomFields: c.CustomFields,
+ HTTPConfig: &httpConfig,
+ }
+
+ if !c.ReopenDuration.IsZero() {
+ reopenDuration, err := model.ParseDuration(c.ReopenDuration.StringValue())
+ if err != nil {
+ return nil, errors.WrapInvalidInputf(err, ErrCodeAlertmanagerChannelInvalid, "parse reopenDuration %q", c.ReopenDuration)
+ }
+ jira.ReopenDuration = reopenDuration
+ }
+
+ return &Receiver{
+ Receiver: &config.Receiver{Name: displayName},
+ JiraConfigs: []*JiraReceiverConfig{jira},
+ }, nil
+}
+
+func newChannelJiraConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ jira := receiver.JiraConfigs[0]
+ sendResolved := jira.VSendResolved
+
+ if err := rejectUnsupportedHTTPConfig(name, jira.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ if jira.HTTPConfig != nil && jira.HTTPConfig.Authorization != nil {
+ return nil, errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "channel %q sets http_config.authorization, which is not supported", name)
+ }
+
+ if err := rejectHTTPBasicAuthBeyondPassword(name, jira.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ spec := &ChannelJiraConfig{
+ SendResolved: &sendResolved,
+ Site: jira.Site,
+ Project: jira.Project,
+ IssueType: jira.IssueType,
+ Summary: valuer.UnsetIfEmpty(jira.Summary),
+ Description: valuer.UnsetIfEmpty(jira.Description),
+ Priority: jira.Priority,
+ Labels: jira.Labels,
+ ResolveTransition: jira.ResolveTransition,
+ ReopenTransition: jira.ReopenTransition,
+ ReopenDuration: valuer.UnsetIfEmpty(jira.ReopenDuration.String()),
+ WontFixResolution: jira.WontFixResolution,
+ CustomFields: jira.CustomFields,
+ }
+
+ if jira.HTTPConfig != nil && jira.HTTPConfig.BasicAuth != nil {
+ spec.Email = jira.HTTPConfig.BasicAuth.Username
+ spec.APIToken = string(jira.HTTPConfig.BasicAuth.Password)
+ }
+
+ return spec, nil
+}
+
const defaultJiraReopenDuration = model.Duration(3 * 24 * time.Hour)
// Service accounts authenticate against the api.atlassian.com gateway (keyed by
diff --git a/pkg/types/alertmanagertypes/jira_test.go b/pkg/types/alertmanagertypes/channel_jira_test.go
similarity index 100%
rename from pkg/types/alertmanagertypes/jira_test.go
rename to pkg/types/alertmanagertypes/channel_jira_test.go
diff --git a/pkg/types/alertmanagertypes/jsmops.go b/pkg/types/alertmanagertypes/channel_jsmops.go
similarity index 61%
rename from pkg/types/alertmanagertypes/jsmops.go
rename to pkg/types/alertmanagertypes/channel_jsmops.go
index 50d72acad4..5133d971ff 100644
--- a/pkg/types/alertmanagertypes/jsmops.go
+++ b/pkg/types/alertmanagertypes/channel_jsmops.go
@@ -2,10 +2,63 @@ package alertmanagertypes
import (
"github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
"github.com/prometheus/alertmanager/config"
commoncfg "github.com/prometheus/common/config"
)
+// ChannelJSMOpsConfig carries no API URL: JSM Ops is a single global gateway
+// keyed by the integration API key, which the notifier pins itself.
+type ChannelJSMOpsConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ APIKey string `json:"apiKey" required:"true" format:"password"`
+ Message valuer.UnsetOrNonEmptyString `json:"message"`
+ Description valuer.UnsetOrNonEmptyString `json:"description"`
+ Priority string `json:"priority"`
+ // Tags is the comma-separated list JSM Ops attaches to the alert.
+ Tags valuer.UnsetOrNonEmptyString `json:"tags"`
+}
+
+func (c ChannelJSMOpsConfig) Validate() error {
+ if c.APIKey == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiKey is required for a jsmops channel")
+ }
+
+ return nil
+}
+
+func (c ChannelJSMOpsConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ return &Receiver{
+ Receiver: &config.Receiver{Name: displayName},
+ JSMOpsConfigs: []*JSMOpsReceiverConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultJSMOpsReceiverConfig.VSendResolved)},
+ APIKey: config.Secret(c.APIKey),
+ Message: c.Message.StringValue(),
+ Description: c.Description.StringValue(),
+ Priority: c.Priority,
+ Tags: c.Tags.StringValue(),
+ }},
+ }, nil
+}
+
+func newChannelJSMOpsConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ jsmops := receiver.JSMOpsConfigs[0]
+ sendResolved := jsmops.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, jsmops.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelJSMOpsConfig{
+ SendResolved: &sendResolved,
+ APIKey: string(jsmops.APIKey),
+ Message: valuer.UnsetIfEmpty(jsmops.Message),
+ Description: valuer.UnsetIfEmpty(jsmops.Description),
+ Priority: jsmops.Priority,
+ Tags: valuer.UnsetIfEmpty(jsmops.Tags),
+ }, nil
+}
+
// JSMOpsAPIBaseURL is the native JSM Ops integration-events gateway. It is a
// single global host keyed by the integration API key (no region/cloud id in
// the path). The trailing slash is required: the Opsgenie notifier appends
diff --git a/pkg/types/alertmanagertypes/jsmops_test.go b/pkg/types/alertmanagertypes/channel_jsmops_test.go
similarity index 100%
rename from pkg/types/alertmanagertypes/jsmops_test.go
rename to pkg/types/alertmanagertypes/channel_jsmops_test.go
diff --git a/pkg/types/alertmanagertypes/channel_msteams.go b/pkg/types/alertmanagertypes/channel_msteams.go
new file mode 100644
index 0000000000..d375116f57
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_msteams.go
@@ -0,0 +1,55 @@
+package alertmanagertypes
+
+import (
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+)
+
+type ChannelMSTeamsConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ WebhookURL string `json:"webhookUrl" required:"true" format:"password"`
+ Title valuer.UnsetOrNonEmptyString `json:"title"`
+ Text valuer.UnsetOrNonEmptyString `json:"text"`
+}
+
+func (c ChannelMSTeamsConfig) Validate() error {
+ if c.WebhookURL == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.webhookUrl is required for an msteams channel")
+ }
+
+ return nil
+}
+
+func (c ChannelMSTeamsConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ webhookURL, err := parseSecretURL(c.WebhookURL)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ MSTeamsV2Configs: []*config.MSTeamsV2Config{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultMSTeamsV2Config.VSendResolved)},
+ WebhookURL: webhookURL,
+ Title: c.Title.StringValue(),
+ Text: c.Text.StringValue(),
+ }},
+ }}, nil
+}
+
+func newChannelMSTeamsConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ msteams := receiver.MSTeamsV2Configs[0]
+ sendResolved := msteams.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, msteams.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelMSTeamsConfig{
+ SendResolved: &sendResolved,
+ WebhookURL: formatSecretURL(msteams.WebhookURL),
+ Title: valuer.UnsetIfEmpty(msteams.Title),
+ Text: valuer.UnsetIfEmpty(msteams.Text),
+ }, nil
+}
diff --git a/pkg/types/alertmanagertypes/channel_opsgenie.go b/pkg/types/alertmanagertypes/channel_opsgenie.go
new file mode 100644
index 0000000000..4180b0ca8b
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_opsgenie.go
@@ -0,0 +1,71 @@
+package alertmanagertypes
+
+import (
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+)
+
+type ChannelOpsgenieConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ APIKey string `json:"apiKey" required:"true" format:"password"`
+ APIURL string `json:"apiUrl"`
+ Message valuer.UnsetOrNonEmptyString `json:"message"`
+ Description valuer.UnsetOrNonEmptyString `json:"description"`
+ Source valuer.UnsetOrNonEmptyString `json:"source"`
+ Details map[string]string `json:"details,omitempty"`
+ Priority string `json:"priority"`
+}
+
+func (c ChannelOpsgenieConfig) Validate() error {
+ if c.APIKey == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiKey is required for an opsgenie channel")
+ }
+
+ return nil
+}
+
+func (c ChannelOpsgenieConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ var apiURL *config.URL
+ if c.APIURL != "" {
+ parsed, err := parseUpstreamURL(c.APIURL)
+ if err != nil {
+ return nil, err
+ }
+ apiURL = parsed
+ }
+
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ OpsGenieConfigs: []*config.OpsGenieConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultOpsGenieConfig.VSendResolved)},
+ APIKey: config.Secret(c.APIKey),
+ APIURL: apiURL,
+ Message: c.Message.StringValue(),
+ Description: c.Description.StringValue(),
+ Source: c.Source.StringValue(),
+ Priority: c.Priority,
+ Details: c.Details,
+ }},
+ }}, nil
+}
+
+func newChannelOpsgenieConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ opsgenie := receiver.OpsGenieConfigs[0]
+ sendResolved := opsgenie.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, opsgenie.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelOpsgenieConfig{
+ SendResolved: &sendResolved,
+ APIKey: string(opsgenie.APIKey),
+ APIURL: formatUpstreamURL(opsgenie.APIURL),
+ Message: valuer.UnsetIfEmpty(opsgenie.Message),
+ Description: valuer.UnsetIfEmpty(opsgenie.Description),
+ Source: valuer.UnsetIfEmpty(opsgenie.Source),
+ Priority: opsgenie.Priority,
+ Details: opsgenie.Details,
+ }, nil
+}
diff --git a/pkg/types/alertmanagertypes/channel_pagerduty.go b/pkg/types/alertmanagertypes/channel_pagerduty.go
new file mode 100644
index 0000000000..d6ccd2241c
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_pagerduty.go
@@ -0,0 +1,92 @@
+package alertmanagertypes
+
+import (
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+)
+
+type ChannelPagerdutyConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ RoutingKey string `json:"routingKey" required:"true" format:"password"`
+ URL string `json:"url"`
+ Source valuer.UnsetOrNonEmptyString `json:"source"`
+ Client valuer.UnsetOrNonEmptyString `json:"client"`
+ ClientURL valuer.UnsetOrNonEmptyString `json:"clientUrl"`
+ Description valuer.UnsetOrNonEmptyString `json:"description"`
+ Severity string `json:"severity"`
+ Component string `json:"component"`
+ Group string `json:"group"`
+ Class string `json:"class"`
+ Details map[string]string `json:"details,omitempty"`
+}
+
+func (c ChannelPagerdutyConfig) Validate() error {
+ if c.RoutingKey == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.routingKey is required for a pagerduty channel")
+ }
+
+ return nil
+}
+
+func (c ChannelPagerdutyConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ var eventsURL *config.URL
+ if c.URL != "" {
+ parsed, err := parseUpstreamURL(c.URL)
+ if err != nil {
+ return nil, err
+ }
+ eventsURL = parsed
+ }
+
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ PagerdutyConfigs: []*config.PagerdutyConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultPagerdutyConfig.VSendResolved)},
+ RoutingKey: config.Secret(c.RoutingKey),
+ URL: eventsURL,
+ Source: c.Source.StringValue(),
+ Client: c.Client.StringValue(),
+ ClientURL: c.ClientURL.StringValue(),
+ Description: c.Description.StringValue(),
+ Severity: c.Severity,
+ Component: c.Component,
+ Group: c.Group,
+ Class: c.Class,
+ Details: newUpstreamDetails(c.Details),
+ }},
+ }}, nil
+}
+
+func newChannelPagerdutyConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ pagerduty := receiver.PagerdutyConfigs[0]
+ sendResolved := pagerduty.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, pagerduty.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ var details map[string]string
+ if len(pagerduty.Details) > 0 {
+ extracted, err := extractStringDetails(name, pagerduty.Details)
+ if err != nil {
+ return nil, err
+ }
+ details = extracted
+ }
+
+ return &ChannelPagerdutyConfig{
+ SendResolved: &sendResolved,
+ RoutingKey: string(pagerduty.RoutingKey),
+ URL: formatUpstreamURL(pagerduty.URL),
+ Source: valuer.UnsetIfEmpty(pagerduty.Source),
+ Client: valuer.UnsetIfEmpty(pagerduty.Client),
+ ClientURL: valuer.UnsetIfEmpty(pagerduty.ClientURL),
+ Description: valuer.UnsetIfEmpty(pagerduty.Description),
+ Severity: pagerduty.Severity,
+ Component: pagerduty.Component,
+ Group: pagerduty.Group,
+ Class: pagerduty.Class,
+ Details: details,
+ }, nil
+}
diff --git a/pkg/types/alertmanagertypes/channel_slack.go b/pkg/types/alertmanagertypes/channel_slack.go
new file mode 100644
index 0000000000..abf097e6e7
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_slack.go
@@ -0,0 +1,182 @@
+package alertmanagertypes
+
+import (
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/SigNoz/signoz/pkg/valuer"
+ "github.com/prometheus/alertmanager/config"
+)
+
+type ChannelSlackConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ APIURL string `json:"apiUrl" required:"true" format:"password"`
+ Channel string `json:"channel"`
+ Title valuer.UnsetOrNonEmptyString `json:"title"`
+ Text valuer.UnsetOrNonEmptyString `json:"text"`
+ Color valuer.UnsetOrNonEmptyString `json:"color"`
+ TitleLink valuer.UnsetOrNonEmptyString `json:"titleLink"`
+ Pretext valuer.UnsetOrNonEmptyString `json:"pretext"`
+ Fallback valuer.UnsetOrNonEmptyString `json:"fallback"`
+ Footer valuer.UnsetOrNonEmptyString `json:"footer"`
+ Fields []ChannelSlackField `json:"fields,omitempty"`
+ Actions []ChannelSlackAction `json:"actions,omitempty"`
+}
+
+type ChannelSlackField struct {
+ Title string `json:"title" required:"true"`
+ Value string `json:"value" required:"true"`
+ Short *bool `json:"short,omitempty"`
+}
+
+// ChannelSlackAction is a link button when URL is set, otherwise a message
+// button that needs Name. Upstream clears whichever side is not in use.
+type ChannelSlackAction struct {
+ Type string `json:"type" required:"true"`
+ Text string `json:"text" required:"true"`
+ URL string `json:"url"`
+ Style string `json:"style"`
+ Name string `json:"name"`
+ Value string `json:"value"`
+ Confirm *ChannelSlackConfirmation `json:"confirm,omitempty"`
+}
+
+type ChannelSlackConfirmation struct {
+ Text string `json:"text" required:"true"`
+ Title string `json:"title"`
+ OkText string `json:"okText"`
+ DismissText string `json:"dismissText"`
+}
+
+func (c ChannelSlackConfig) Validate() error {
+ if c.APIURL == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiUrl is required for a slack channel")
+ }
+
+ for i, field := range c.Fields {
+ if field.Title == "" || field.Value == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.fields[%d] requires title and value", i)
+ }
+ }
+
+ for i, action := range c.Actions {
+ if action.Type == "" || action.Text == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d] requires type and text", i)
+ }
+ if action.URL == "" && action.Name == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d] requires url or name", i)
+ }
+ if action.Confirm != nil && action.Confirm.Text == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d].confirm requires text", i)
+ }
+ }
+
+ return nil
+}
+
+func (c ChannelSlackConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ apiURL, err := parseSecretURL(c.APIURL)
+ if err != nil {
+ return nil, err
+ }
+
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ SlackConfigs: []*config.SlackConfig{{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultSlackConfig.VSendResolved)},
+ APIURL: apiURL,
+ Channel: c.Channel,
+ Title: c.Title.StringValue(),
+ Text: c.Text.StringValue(),
+ Color: c.Color.StringValue(),
+ TitleLink: c.TitleLink.StringValue(),
+ Pretext: c.Pretext.StringValue(),
+ Fallback: c.Fallback.StringValue(),
+ Footer: c.Footer.StringValue(),
+ Fields: newUpstreamSlackFields(c.Fields),
+ Actions: newUpstreamSlackActions(c.Actions),
+ }},
+ }}, nil
+}
+
+func newChannelSlackConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ slack := receiver.SlackConfigs[0]
+ sendResolved := slack.VSendResolved
+
+ if err := rejectAnyHTTPAuth(name, slack.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ return &ChannelSlackConfig{
+ SendResolved: &sendResolved,
+ APIURL: formatSecretURL(slack.APIURL),
+ Channel: slack.Channel,
+ Title: valuer.UnsetIfEmpty(slack.Title),
+ Text: valuer.UnsetIfEmpty(slack.Text),
+ Color: valuer.UnsetIfEmpty(slack.Color),
+ TitleLink: valuer.UnsetIfEmpty(slack.TitleLink),
+ Pretext: valuer.UnsetIfEmpty(slack.Pretext),
+ Fallback: valuer.UnsetIfEmpty(slack.Fallback),
+ Footer: valuer.UnsetIfEmpty(slack.Footer),
+ Fields: newChannelSlackFields(slack.Fields),
+ Actions: newChannelSlackActions(slack.Actions),
+ }, nil
+}
+
+func newUpstreamSlackFields(fields []ChannelSlackField) []*config.SlackField {
+ if len(fields) == 0 {
+ return nil
+ }
+
+ upstream := make([]*config.SlackField, 0, len(fields))
+ for _, field := range fields {
+ upstream = append(upstream, &config.SlackField{Title: field.Title, Value: field.Value, Short: field.Short})
+ }
+
+ return upstream
+}
+
+func newChannelSlackFields(upstream []*config.SlackField) []ChannelSlackField {
+ if len(upstream) == 0 {
+ return nil
+ }
+
+ fields := make([]ChannelSlackField, 0, len(upstream))
+ for _, field := range upstream {
+ fields = append(fields, ChannelSlackField{Title: field.Title, Value: field.Value, Short: field.Short})
+ }
+
+ return fields
+}
+
+func newUpstreamSlackActions(actions []ChannelSlackAction) []*config.SlackAction {
+ if len(actions) == 0 {
+ return nil
+ }
+
+ upstream := make([]*config.SlackAction, 0, len(actions))
+ for _, action := range actions {
+ upstreamAction := &config.SlackAction{Type: action.Type, Text: action.Text, URL: action.URL, Style: action.Style, Name: action.Name, Value: action.Value}
+ if action.Confirm != nil {
+ upstreamAction.ConfirmField = &config.SlackConfirmationField{Text: action.Confirm.Text, Title: action.Confirm.Title, OkText: action.Confirm.OkText, DismissText: action.Confirm.DismissText}
+ }
+ upstream = append(upstream, upstreamAction)
+ }
+
+ return upstream
+}
+
+func newChannelSlackActions(upstream []*config.SlackAction) []ChannelSlackAction {
+ if len(upstream) == 0 {
+ return nil
+ }
+
+ actions := make([]ChannelSlackAction, 0, len(upstream))
+ for _, upstreamAction := range upstream {
+ action := ChannelSlackAction{Type: upstreamAction.Type, Text: upstreamAction.Text, URL: upstreamAction.URL, Style: upstreamAction.Style, Name: upstreamAction.Name, Value: upstreamAction.Value}
+ if upstreamAction.ConfirmField != nil {
+ action.Confirm = &ChannelSlackConfirmation{Text: upstreamAction.ConfirmField.Text, Title: upstreamAction.ConfirmField.Title, OkText: upstreamAction.ConfirmField.OkText, DismissText: upstreamAction.ConfirmField.DismissText}
+ }
+ actions = append(actions, action)
+ }
+
+ return actions
+}
diff --git a/pkg/types/alertmanagertypes/channel_webhook.go b/pkg/types/alertmanagertypes/channel_webhook.go
new file mode 100644
index 0000000000..3de644f3cf
--- /dev/null
+++ b/pkg/types/alertmanagertypes/channel_webhook.go
@@ -0,0 +1,98 @@
+package alertmanagertypes
+
+import (
+ "github.com/SigNoz/signoz/pkg/errors"
+ "github.com/prometheus/alertmanager/config"
+ commoncfg "github.com/prometheus/common/config"
+)
+
+// ChannelWebhookConfig splits apart the two authentication modes the legacy API
+// overloaded onto one password field, where an empty username meant the password
+// was really a bearer token. Username or Password may be set without the other,
+// as upstream allows, but not together with BearerToken.
+type ChannelWebhookConfig struct {
+ SendResolved *bool `json:"sendResolved,omitempty"`
+ URL string `json:"url" required:"true" format:"password"`
+ Username string `json:"username"`
+ Password string `json:"password" format:"password"`
+ BearerToken string `json:"bearerToken" format:"password"`
+}
+
+func (c ChannelWebhookConfig) Validate() error {
+ if c.URL == "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.url is required for a webhook channel")
+ }
+
+ usesBasicAuth := c.Username != "" || c.Password != ""
+
+ if usesBasicAuth && c.BearerToken != "" {
+ return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.bearerToken cannot be combined with config.spec.username or config.spec.password")
+ }
+
+ return nil
+}
+
+func (c ChannelWebhookConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
+ webhook := &config.WebhookConfig{
+ NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultWebhookConfig.VSendResolved)},
+ URL: config.SecretTemplateURL(c.URL),
+ }
+
+ // Seeded from upstream's default rather than a zero value: FollowRedirects
+ // and EnableHTTP2 marshal unconditionally, so a zero value would persist
+ // them as false and read back as a config ChannelWebhookConfig cannot represent.
+ switch {
+ case c.Username != "" || c.Password != "":
+ httpConfig := commoncfg.DefaultHTTPClientConfig
+ httpConfig.BasicAuth = &commoncfg.BasicAuth{
+ Username: c.Username,
+ Password: commoncfg.Secret(c.Password),
+ }
+ webhook.HTTPConfig = &httpConfig
+ case c.BearerToken != "":
+ httpConfig := commoncfg.DefaultHTTPClientConfig
+ httpConfig.Authorization = &commoncfg.Authorization{
+ Type: bearerAuthorizationType,
+ Credentials: commoncfg.Secret(c.BearerToken),
+ }
+ webhook.HTTPConfig = &httpConfig
+ }
+
+ return &Receiver{Receiver: &config.Receiver{
+ Name: displayName,
+ WebhookConfigs: []*config.WebhookConfig{webhook},
+ }}, nil
+}
+
+func newChannelWebhookConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
+ upstream := receiver.WebhookConfigs[0]
+ sendResolved := upstream.VSendResolved
+ if err := rejectUnsupportedHTTPConfig(name, upstream.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ if err := rejectHTTPBasicAuthBeyondPassword(name, upstream.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ if err := rejectHTTPAuthorizationBeyondBearer(name, upstream.HTTPConfig); err != nil {
+ return nil, err
+ }
+
+ webhook := &ChannelWebhookConfig{
+ SendResolved: &sendResolved,
+ URL: string(upstream.URL),
+ }
+
+ if upstream.HTTPConfig != nil {
+ if basicAuth := upstream.HTTPConfig.BasicAuth; basicAuth != nil {
+ webhook.Username = basicAuth.Username
+ webhook.Password = string(basicAuth.Password)
+ }
+ if authorization := upstream.HTTPConfig.Authorization; authorization != nil {
+ webhook.BearerToken = string(authorization.Credentials)
+ }
+ }
+
+ return webhook, nil
+}
diff --git a/pkg/types/alertmanagertypes/channelconfig.go b/pkg/types/alertmanagertypes/channelconfig.go
index 464dbcb817..cd6be7a9e3 100644
--- a/pkg/types/alertmanagertypes/channelconfig.go
+++ b/pkg/types/alertmanagertypes/channelconfig.go
@@ -3,8 +3,6 @@ package alertmanagertypes
import (
"bytes"
"encoding/json"
- "maps"
- "net/textproto"
"net/url"
"reflect"
"slices"
@@ -14,7 +12,6 @@ import (
"github.com/SigNoz/signoz/pkg/valuer"
"github.com/prometheus/alertmanager/config"
commoncfg "github.com/prometheus/common/config"
- "github.com/prometheus/common/model"
"github.com/swaggest/jsonschema-go"
)
@@ -205,808 +202,6 @@ type ChannelSpec interface {
toUndefaultedReceiver(displayName string) (*Receiver, error)
}
-type ChannelSlackConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- APIURL string `json:"apiUrl" required:"true" format:"password"`
- Channel string `json:"channel"`
- Title valuer.UnsetOrNonEmptyString `json:"title"`
- Text valuer.UnsetOrNonEmptyString `json:"text"`
- Color valuer.UnsetOrNonEmptyString `json:"color"`
- TitleLink valuer.UnsetOrNonEmptyString `json:"titleLink"`
- Pretext valuer.UnsetOrNonEmptyString `json:"pretext"`
- Fallback valuer.UnsetOrNonEmptyString `json:"fallback"`
- Footer valuer.UnsetOrNonEmptyString `json:"footer"`
- Fields []ChannelSlackField `json:"fields,omitempty"`
- Actions []ChannelSlackAction `json:"actions,omitempty"`
-}
-
-type ChannelSlackField struct {
- Title string `json:"title" required:"true"`
- Value string `json:"value" required:"true"`
- Short *bool `json:"short,omitempty"`
-}
-
-// ChannelSlackAction is a link button when URL is set, otherwise a message
-// button that needs Name. Upstream clears whichever side is not in use.
-type ChannelSlackAction struct {
- Type string `json:"type" required:"true"`
- Text string `json:"text" required:"true"`
- URL string `json:"url"`
- Style string `json:"style"`
- Name string `json:"name"`
- Value string `json:"value"`
- Confirm *ChannelSlackConfirmation `json:"confirm,omitempty"`
-}
-
-type ChannelSlackConfirmation struct {
- Text string `json:"text" required:"true"`
- Title string `json:"title"`
- OkText string `json:"okText"`
- DismissText string `json:"dismissText"`
-}
-
-func (c ChannelSlackConfig) Validate() error {
- if c.APIURL == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiUrl is required for a slack channel")
- }
-
- for i, field := range c.Fields {
- if field.Title == "" || field.Value == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.fields[%d] requires title and value", i)
- }
- }
-
- for i, action := range c.Actions {
- if action.Type == "" || action.Text == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d] requires type and text", i)
- }
- if action.URL == "" && action.Name == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d] requires url or name", i)
- }
- if action.Confirm != nil && action.Confirm.Text == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.actions[%d].confirm requires text", i)
- }
- }
-
- return nil
-}
-
-func (c ChannelSlackConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- apiURL, err := parseSecretURL(c.APIURL)
- if err != nil {
- return nil, err
- }
-
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- SlackConfigs: []*config.SlackConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultSlackConfig.VSendResolved)},
- APIURL: apiURL,
- Channel: c.Channel,
- Title: c.Title.StringValue(),
- Text: c.Text.StringValue(),
- Color: c.Color.StringValue(),
- TitleLink: c.TitleLink.StringValue(),
- Pretext: c.Pretext.StringValue(),
- Fallback: c.Fallback.StringValue(),
- Footer: c.Footer.StringValue(),
- Fields: newUpstreamSlackFields(c.Fields),
- Actions: newUpstreamSlackActions(c.Actions),
- }},
- }}, nil
-}
-
-func newChannelSlackConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- slack := receiver.SlackConfigs[0]
- sendResolved := slack.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, slack.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelSlackConfig{
- SendResolved: &sendResolved,
- APIURL: formatSecretURL(slack.APIURL),
- Channel: slack.Channel,
- Title: valuer.UnsetIfEmpty(slack.Title),
- Text: valuer.UnsetIfEmpty(slack.Text),
- Color: valuer.UnsetIfEmpty(slack.Color),
- TitleLink: valuer.UnsetIfEmpty(slack.TitleLink),
- Pretext: valuer.UnsetIfEmpty(slack.Pretext),
- Fallback: valuer.UnsetIfEmpty(slack.Fallback),
- Footer: valuer.UnsetIfEmpty(slack.Footer),
- Fields: newChannelSlackFields(slack.Fields),
- Actions: newChannelSlackActions(slack.Actions),
- }, nil
-}
-
-func newUpstreamSlackFields(fields []ChannelSlackField) []*config.SlackField {
- if len(fields) == 0 {
- return nil
- }
-
- upstream := make([]*config.SlackField, 0, len(fields))
- for _, field := range fields {
- upstream = append(upstream, &config.SlackField{Title: field.Title, Value: field.Value, Short: field.Short})
- }
-
- return upstream
-}
-
-func newChannelSlackFields(upstream []*config.SlackField) []ChannelSlackField {
- if len(upstream) == 0 {
- return nil
- }
-
- fields := make([]ChannelSlackField, 0, len(upstream))
- for _, field := range upstream {
- fields = append(fields, ChannelSlackField{Title: field.Title, Value: field.Value, Short: field.Short})
- }
-
- return fields
-}
-
-func newUpstreamSlackActions(actions []ChannelSlackAction) []*config.SlackAction {
- if len(actions) == 0 {
- return nil
- }
-
- upstream := make([]*config.SlackAction, 0, len(actions))
- for _, action := range actions {
- upstreamAction := &config.SlackAction{Type: action.Type, Text: action.Text, URL: action.URL, Style: action.Style, Name: action.Name, Value: action.Value}
- if action.Confirm != nil {
- upstreamAction.ConfirmField = &config.SlackConfirmationField{Text: action.Confirm.Text, Title: action.Confirm.Title, OkText: action.Confirm.OkText, DismissText: action.Confirm.DismissText}
- }
- upstream = append(upstream, upstreamAction)
- }
-
- return upstream
-}
-
-func newChannelSlackActions(upstream []*config.SlackAction) []ChannelSlackAction {
- if len(upstream) == 0 {
- return nil
- }
-
- actions := make([]ChannelSlackAction, 0, len(upstream))
- for _, upstreamAction := range upstream {
- action := ChannelSlackAction{Type: upstreamAction.Type, Text: upstreamAction.Text, URL: upstreamAction.URL, Style: upstreamAction.Style, Name: upstreamAction.Name, Value: upstreamAction.Value}
- if upstreamAction.ConfirmField != nil {
- action.Confirm = &ChannelSlackConfirmation{Text: upstreamAction.ConfirmField.Text, Title: upstreamAction.ConfirmField.Title, OkText: upstreamAction.ConfirmField.OkText, DismissText: upstreamAction.ConfirmField.DismissText}
- }
- actions = append(actions, action)
- }
-
- return actions
-}
-
-// ChannelEmailConfig carries no SMTP transport fields: the smarthost,
-// credentials and TLS settings come from the deployment's global config, so a
-// channel can only choose recipients and body.
-type ChannelEmailConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- To string `json:"to" required:"true"`
- HTML valuer.UnsetOrNonEmptyString `json:"html"`
- Headers map[string]string `json:"headers,omitempty"`
-}
-
-func (c ChannelEmailConfig) Validate() error {
- if c.To == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.to is required for an email channel")
- }
-
- // A read reports header names as textproto canonicalizes them, turning
- // "subject" into "Subject", so a name that is not already in that form is
- // rejected rather than answered with one the caller never sent.
- for _, header := range slices.Sorted(maps.Keys(c.Headers)) {
- if canonical := textproto.CanonicalMIMEHeaderKey(header); canonical != header {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.headers name %q must be written as %q", header, canonical)
- }
- }
-
- return nil
-}
-
-func (c ChannelEmailConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- EmailConfigs: []*config.EmailConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultEmailConfig.VSendResolved)},
- To: c.To,
- HTML: c.HTML.StringValue(),
- Headers: c.Headers,
- }},
- }}, nil
-}
-
-func newChannelEmailConfigFromReceiver(_ string, receiver *Receiver) (ChannelSpec, error) {
- email := receiver.EmailConfigs[0]
- sendResolved := email.VSendResolved
-
- return &ChannelEmailConfig{
- SendResolved: &sendResolved,
- To: email.To,
- HTML: valuer.UnsetIfEmpty(email.HTML),
- Headers: email.Headers,
- }, nil
-}
-
-// ChannelWebhookConfig splits apart the two authentication modes the legacy API
-// overloaded onto one password field, where an empty username meant the password
-// was really a bearer token. Username or Password may be set without the other,
-// as upstream allows, but not together with BearerToken.
-type ChannelWebhookConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- URL string `json:"url" required:"true" format:"password"`
- Username string `json:"username"`
- Password string `json:"password" format:"password"`
- BearerToken string `json:"bearerToken" format:"password"`
-}
-
-func (c ChannelWebhookConfig) Validate() error {
- if c.URL == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.url is required for a webhook channel")
- }
-
- usesBasicAuth := c.Username != "" || c.Password != ""
-
- if usesBasicAuth && c.BearerToken != "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.bearerToken cannot be combined with config.spec.username or config.spec.password")
- }
-
- return nil
-}
-
-func (c ChannelWebhookConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- webhook := &config.WebhookConfig{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultWebhookConfig.VSendResolved)},
- URL: config.SecretTemplateURL(c.URL),
- }
-
- // Seeded from upstream's default rather than a zero value: FollowRedirects
- // and EnableHTTP2 marshal unconditionally, so a zero value would persist
- // them as false and read back as a config ChannelWebhookConfig cannot represent.
- switch {
- case c.Username != "" || c.Password != "":
- httpConfig := commoncfg.DefaultHTTPClientConfig
- httpConfig.BasicAuth = &commoncfg.BasicAuth{
- Username: c.Username,
- Password: commoncfg.Secret(c.Password),
- }
- webhook.HTTPConfig = &httpConfig
- case c.BearerToken != "":
- httpConfig := commoncfg.DefaultHTTPClientConfig
- httpConfig.Authorization = &commoncfg.Authorization{
- Type: bearerAuthorizationType,
- Credentials: commoncfg.Secret(c.BearerToken),
- }
- webhook.HTTPConfig = &httpConfig
- }
-
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- WebhookConfigs: []*config.WebhookConfig{webhook},
- }}, nil
-}
-
-func newChannelWebhookConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- upstream := receiver.WebhookConfigs[0]
- sendResolved := upstream.VSendResolved
- if err := rejectUnsupportedHTTPConfig(name, upstream.HTTPConfig); err != nil {
- return nil, err
- }
-
- if err := rejectHTTPBasicAuthBeyondPassword(name, upstream.HTTPConfig); err != nil {
- return nil, err
- }
-
- if err := rejectHTTPAuthorizationBeyondBearer(name, upstream.HTTPConfig); err != nil {
- return nil, err
- }
-
- webhook := &ChannelWebhookConfig{
- SendResolved: &sendResolved,
- URL: string(upstream.URL),
- }
-
- if upstream.HTTPConfig != nil {
- if basicAuth := upstream.HTTPConfig.BasicAuth; basicAuth != nil {
- webhook.Username = basicAuth.Username
- webhook.Password = string(basicAuth.Password)
- }
- if authorization := upstream.HTTPConfig.Authorization; authorization != nil {
- webhook.BearerToken = string(authorization.Credentials)
- }
- }
-
- return webhook, nil
-}
-
-type ChannelPagerdutyConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- RoutingKey string `json:"routingKey" required:"true" format:"password"`
- URL string `json:"url"`
- Source valuer.UnsetOrNonEmptyString `json:"source"`
- Client valuer.UnsetOrNonEmptyString `json:"client"`
- ClientURL valuer.UnsetOrNonEmptyString `json:"clientUrl"`
- Description valuer.UnsetOrNonEmptyString `json:"description"`
- Severity string `json:"severity"`
- Component string `json:"component"`
- Group string `json:"group"`
- Class string `json:"class"`
- Details map[string]string `json:"details,omitempty"`
-}
-
-func (c ChannelPagerdutyConfig) Validate() error {
- if c.RoutingKey == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.routingKey is required for a pagerduty channel")
- }
-
- return nil
-}
-
-func (c ChannelPagerdutyConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- var eventsURL *config.URL
- if c.URL != "" {
- parsed, err := parseUpstreamURL(c.URL)
- if err != nil {
- return nil, err
- }
- eventsURL = parsed
- }
-
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- PagerdutyConfigs: []*config.PagerdutyConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultPagerdutyConfig.VSendResolved)},
- RoutingKey: config.Secret(c.RoutingKey),
- URL: eventsURL,
- Source: c.Source.StringValue(),
- Client: c.Client.StringValue(),
- ClientURL: c.ClientURL.StringValue(),
- Description: c.Description.StringValue(),
- Severity: c.Severity,
- Component: c.Component,
- Group: c.Group,
- Class: c.Class,
- Details: newUpstreamDetails(c.Details),
- }},
- }}, nil
-}
-
-func newChannelPagerdutyConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- pagerduty := receiver.PagerdutyConfigs[0]
- sendResolved := pagerduty.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, pagerduty.HTTPConfig); err != nil {
- return nil, err
- }
-
- var details map[string]string
- if len(pagerduty.Details) > 0 {
- extracted, err := extractStringDetails(name, pagerduty.Details)
- if err != nil {
- return nil, err
- }
- details = extracted
- }
-
- return &ChannelPagerdutyConfig{
- SendResolved: &sendResolved,
- RoutingKey: string(pagerduty.RoutingKey),
- URL: formatUpstreamURL(pagerduty.URL),
- Source: valuer.UnsetIfEmpty(pagerduty.Source),
- Client: valuer.UnsetIfEmpty(pagerduty.Client),
- ClientURL: valuer.UnsetIfEmpty(pagerduty.ClientURL),
- Description: valuer.UnsetIfEmpty(pagerduty.Description),
- Severity: pagerduty.Severity,
- Component: pagerduty.Component,
- Group: pagerduty.Group,
- Class: pagerduty.Class,
- Details: details,
- }, nil
-}
-
-type ChannelOpsgenieConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- APIKey string `json:"apiKey" required:"true" format:"password"`
- APIURL string `json:"apiUrl"`
- Message valuer.UnsetOrNonEmptyString `json:"message"`
- Description valuer.UnsetOrNonEmptyString `json:"description"`
- Source valuer.UnsetOrNonEmptyString `json:"source"`
- Details map[string]string `json:"details,omitempty"`
- Priority string `json:"priority"`
-}
-
-func (c ChannelOpsgenieConfig) Validate() error {
- if c.APIKey == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiKey is required for an opsgenie channel")
- }
-
- return nil
-}
-
-func (c ChannelOpsgenieConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- var apiURL *config.URL
- if c.APIURL != "" {
- parsed, err := parseUpstreamURL(c.APIURL)
- if err != nil {
- return nil, err
- }
- apiURL = parsed
- }
-
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- OpsGenieConfigs: []*config.OpsGenieConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultOpsGenieConfig.VSendResolved)},
- APIKey: config.Secret(c.APIKey),
- APIURL: apiURL,
- Message: c.Message.StringValue(),
- Description: c.Description.StringValue(),
- Source: c.Source.StringValue(),
- Priority: c.Priority,
- Details: c.Details,
- }},
- }}, nil
-}
-
-func newChannelOpsgenieConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- opsgenie := receiver.OpsGenieConfigs[0]
- sendResolved := opsgenie.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, opsgenie.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelOpsgenieConfig{
- SendResolved: &sendResolved,
- APIKey: string(opsgenie.APIKey),
- APIURL: formatUpstreamURL(opsgenie.APIURL),
- Message: valuer.UnsetIfEmpty(opsgenie.Message),
- Description: valuer.UnsetIfEmpty(opsgenie.Description),
- Source: valuer.UnsetIfEmpty(opsgenie.Source),
- Priority: opsgenie.Priority,
- Details: opsgenie.Details,
- }, nil
-}
-
-type ChannelMSTeamsConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- WebhookURL string `json:"webhookUrl" required:"true" format:"password"`
- Title valuer.UnsetOrNonEmptyString `json:"title"`
- Text valuer.UnsetOrNonEmptyString `json:"text"`
-}
-
-func (c ChannelMSTeamsConfig) Validate() error {
- if c.WebhookURL == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.webhookUrl is required for an msteams channel")
- }
-
- return nil
-}
-
-func (c ChannelMSTeamsConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- webhookURL, err := parseSecretURL(c.WebhookURL)
- if err != nil {
- return nil, err
- }
-
- return &Receiver{Receiver: &config.Receiver{
- Name: displayName,
- MSTeamsV2Configs: []*config.MSTeamsV2Config{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, config.DefaultMSTeamsV2Config.VSendResolved)},
- WebhookURL: webhookURL,
- Title: c.Title.StringValue(),
- Text: c.Text.StringValue(),
- }},
- }}, nil
-}
-
-func newChannelMSTeamsConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- msteams := receiver.MSTeamsV2Configs[0]
- sendResolved := msteams.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, msteams.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelMSTeamsConfig{
- SendResolved: &sendResolved,
- WebhookURL: formatSecretURL(msteams.WebhookURL),
- Title: valuer.UnsetIfEmpty(msteams.Title),
- Text: valuer.UnsetIfEmpty(msteams.Text),
- }, nil
-}
-
-type ChannelGoogleChatConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- WebhookURL string `json:"webhookUrl" required:"true" format:"password"`
- Title valuer.UnsetOrNonEmptyString `json:"title"`
- Text valuer.UnsetOrNonEmptyString `json:"text"`
-}
-
-func (c ChannelGoogleChatConfig) Validate() error {
- if c.WebhookURL == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.webhookUrl is required for a googlechat channel")
- }
-
- return nil
-}
-
-func (c ChannelGoogleChatConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- webhookURL, err := parseSecretURL(c.WebhookURL)
- if err != nil {
- return nil, err
- }
-
- return &Receiver{
- Receiver: &config.Receiver{Name: displayName},
- GoogleChatConfigs: []*GoogleChatReceiverConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultGoogleChatReceiverConfig.VSendResolved)},
- WebhookURL: webhookURL,
- Title: c.Title.StringValue(),
- Text: c.Text.StringValue(),
- }},
- }, nil
-}
-
-func newChannelGoogleChatConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- googlechat := receiver.GoogleChatConfigs[0]
- sendResolved := googlechat.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, googlechat.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelGoogleChatConfig{
- SendResolved: &sendResolved,
- WebhookURL: formatSecretURL(googlechat.WebhookURL),
- Title: valuer.UnsetIfEmpty(googlechat.Title),
- Text: valuer.UnsetIfEmpty(googlechat.Text),
- }, nil
-}
-
-type ChannelJiraConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- // Site is the Jira Cloud base URL, https://<site>.atlassian.net. Only Jira
- // Cloud is supported; the REST base is derived from it.
- Site string `json:"site" required:"true"`
- Project string `json:"project" required:"true"`
- IssueType string `json:"issueType" required:"true"`
- Summary valuer.UnsetOrNonEmptyString `json:"summary"`
- Description valuer.UnsetOrNonEmptyString `json:"description"`
- Priority string `json:"priority"`
- Labels []string `json:"labels,omitempty"`
- ResolveTransition string `json:"resolveTransition"`
- ReopenTransition string `json:"reopenTransition"`
- ReopenDuration valuer.UnsetOrNonEmptyString `json:"reopenDuration"`
- WontFixResolution string `json:"wontFixResolution"`
- CustomFields map[string]any `json:"customFields,omitempty"`
-
- Email string `json:"email" required:"true"`
- APIToken string `json:"apiToken" required:"true" format:"password"`
-}
-
-func (c ChannelJiraConfig) Validate() error {
- for _, required := range []struct {
- value string
- field string
- }{
- {c.Site, "site"},
- {c.Project, "project"},
- {c.IssueType, "issueType"},
- {c.Email, "email"},
- {c.APIToken, "apiToken"},
- } {
- if required.value == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.%s is required for a jira channel", required.field)
- }
- }
-
- if !c.ReopenDuration.IsZero() {
- reopenDuration, err := model.ParseDuration(c.ReopenDuration.StringValue())
- if err != nil {
- return errors.WrapInvalidInputf(err, ErrCodeAlertmanagerChannelInvalid, "config.spec.reopenDuration %q is not a valid duration", c.ReopenDuration)
- }
-
- // A read reports the duration as model.Duration formats it, collapsing
- // "72h" into "3d", so a value that is not already in that form is rejected
- // rather than answered with one the caller never sent.
- if canonical := reopenDuration.String(); canonical != c.ReopenDuration.StringValue() {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.reopenDuration %q must be written as %q", c.ReopenDuration, canonical)
- }
- }
-
- return nil
-}
-
-func (c ChannelJiraConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- // Seeded from upstream's default rather than a zero value: FollowRedirects
- // and EnableHTTP2 marshal unconditionally, so a zero value would persist them
- // as false and read back as a config ChannelJiraConfig cannot represent.
- httpConfig := commoncfg.DefaultHTTPClientConfig
- httpConfig.BasicAuth = &commoncfg.BasicAuth{
- Username: c.Email,
- Password: commoncfg.Secret(c.APIToken),
- }
-
- jira := &JiraReceiverConfig{
- // JiraReceiverConfig seeds no send_resolved of its own, so unset means off.
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, false)},
- Site: c.Site,
- Project: c.Project,
- IssueType: c.IssueType,
- Summary: c.Summary.StringValue(),
- Description: c.Description.StringValue(),
- Priority: c.Priority,
- Labels: c.Labels,
- ResolveTransition: c.ResolveTransition,
- ReopenTransition: c.ReopenTransition,
- WontFixResolution: c.WontFixResolution,
- CustomFields: c.CustomFields,
- HTTPConfig: &httpConfig,
- }
-
- if !c.ReopenDuration.IsZero() {
- reopenDuration, err := model.ParseDuration(c.ReopenDuration.StringValue())
- if err != nil {
- return nil, errors.WrapInvalidInputf(err, ErrCodeAlertmanagerChannelInvalid, "parse reopenDuration %q", c.ReopenDuration)
- }
- jira.ReopenDuration = reopenDuration
- }
-
- return &Receiver{
- Receiver: &config.Receiver{Name: displayName},
- JiraConfigs: []*JiraReceiverConfig{jira},
- }, nil
-}
-
-func newChannelJiraConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- jira := receiver.JiraConfigs[0]
- sendResolved := jira.VSendResolved
-
- if err := rejectUnsupportedHTTPConfig(name, jira.HTTPConfig); err != nil {
- return nil, err
- }
-
- if jira.HTTPConfig != nil && jira.HTTPConfig.Authorization != nil {
- return nil, errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "channel %q sets http_config.authorization, which is not supported", name)
- }
-
- if err := rejectHTTPBasicAuthBeyondPassword(name, jira.HTTPConfig); err != nil {
- return nil, err
- }
-
- spec := &ChannelJiraConfig{
- SendResolved: &sendResolved,
- Site: jira.Site,
- Project: jira.Project,
- IssueType: jira.IssueType,
- Summary: valuer.UnsetIfEmpty(jira.Summary),
- Description: valuer.UnsetIfEmpty(jira.Description),
- Priority: jira.Priority,
- Labels: jira.Labels,
- ResolveTransition: jira.ResolveTransition,
- ReopenTransition: jira.ReopenTransition,
- ReopenDuration: valuer.UnsetIfEmpty(jira.ReopenDuration.String()),
- WontFixResolution: jira.WontFixResolution,
- CustomFields: jira.CustomFields,
- }
-
- if jira.HTTPConfig != nil && jira.HTTPConfig.BasicAuth != nil {
- spec.Email = jira.HTTPConfig.BasicAuth.Username
- spec.APIToken = string(jira.HTTPConfig.BasicAuth.Password)
- }
-
- return spec, nil
-}
-
-// ChannelJSMOpsConfig carries no API URL: JSM Ops is a single global gateway
-// keyed by the integration API key, which the notifier pins itself.
-type ChannelJSMOpsConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- APIKey string `json:"apiKey" required:"true" format:"password"`
- Message valuer.UnsetOrNonEmptyString `json:"message"`
- Description valuer.UnsetOrNonEmptyString `json:"description"`
- Priority string `json:"priority"`
- // Tags is the comma-separated list JSM Ops attaches to the alert.
- Tags valuer.UnsetOrNonEmptyString `json:"tags"`
-}
-
-func (c ChannelJSMOpsConfig) Validate() error {
- if c.APIKey == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.apiKey is required for a jsmops channel")
- }
-
- return nil
-}
-
-func (c ChannelJSMOpsConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- return &Receiver{
- Receiver: &config.Receiver{Name: displayName},
- JSMOpsConfigs: []*JSMOpsReceiverConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultJSMOpsReceiverConfig.VSendResolved)},
- APIKey: config.Secret(c.APIKey),
- Message: c.Message.StringValue(),
- Description: c.Description.StringValue(),
- Priority: c.Priority,
- Tags: c.Tags.StringValue(),
- }},
- }, nil
-}
-
-func newChannelJSMOpsConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- jsmops := receiver.JSMOpsConfigs[0]
- sendResolved := jsmops.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, jsmops.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelJSMOpsConfig{
- SendResolved: &sendResolved,
- APIKey: string(jsmops.APIKey),
- Message: valuer.UnsetIfEmpty(jsmops.Message),
- Description: valuer.UnsetIfEmpty(jsmops.Description),
- Priority: jsmops.Priority,
- Tags: valuer.UnsetIfEmpty(jsmops.Tags),
- }, nil
-}
-
-type ChannelIncidentIOConfig struct {
- SendResolved *bool `json:"sendResolved,omitempty"`
- URL string `json:"url" required:"true"`
- Token string `json:"token" required:"true" format:"password"`
- Title valuer.UnsetOrNonEmptyString `json:"title"`
- Description valuer.UnsetOrNonEmptyString `json:"description"`
- Metadata map[string]string `json:"metadata,omitempty"`
-}
-
-func (c ChannelIncidentIOConfig) Validate() error {
- if c.URL == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.url is required for an incidentio channel")
- }
-
- if c.Token == "" {
- return errors.NewInvalidInputf(ErrCodeAlertmanagerChannelInvalid, "config.spec.token is required for an incidentio channel")
- }
-
- return nil
-}
-
-func (c ChannelIncidentIOConfig) toUndefaultedReceiver(displayName string) (*Receiver, error) {
- return &Receiver{
- Receiver: &config.Receiver{Name: displayName},
- IncidentIOConfigs: []*IncidentIOReceiverConfig{{
- NotifierConfig: config.NotifierConfig{VSendResolved: resolveSendResolved(c.SendResolved, DefaultIncidentIOReceiverConfig.VSendResolved)},
- URL: c.URL,
- Token: config.Secret(c.Token),
- Title: c.Title.StringValue(),
- Description: c.Description.StringValue(),
- Metadata: c.Metadata,
- }},
- }, nil
-}
-
-func newChannelIncidentIOConfigFromReceiver(name string, receiver *Receiver) (ChannelSpec, error) {
- incidentio := receiver.IncidentIOConfigs[0]
- sendResolved := incidentio.VSendResolved
-
- if err := rejectAnyHTTPAuth(name, incidentio.HTTPConfig); err != nil {
- return nil, err
- }
-
- return &ChannelIncidentIOConfig{
- SendResolved: &sendResolved,
- URL: incidentio.URL,
- Token: string(incidentio.Token),
- Title: valuer.UnsetIfEmpty(incidentio.Title),
- Description: valuer.UnsetIfEmpty(incidentio.Description),
- Metadata: incidentio.Metadata,
- }, nil
-}
-
// ════════════════════════════════════════════════════════════════════════
// Helpers
// ════════════════════════════════════════════════════════════════════════