Skip to content

Commit d12e686

Browse files
jkroepkesimonpasquierSuperQ
authored andcommitted
jira integration (prometheus#3590)
* Initial jira integration Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de> Signed-off-by: Jan-Otto Kröpke <github@jkroepke.de> Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de> Co-authored-by: Simon Pasquier <spasquie@redhat.com> Co-authored-by: Ben Kochie <superq@gmail.com>
1 parent ee06e51 commit d12e686

File tree

12 files changed

+1496
-25
lines changed

12 files changed

+1496
-25
lines changed

asset/assets_vfsdata.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/config.go

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ func resolveFilepaths(baseDir string, cfg *Config) {
258258
for _, cfg := range receiver.MSTeamsConfigs {
259259
cfg.HTTPConfig.SetDirectory(baseDir)
260260
}
261+
for _, cfg := range receiver.JiraConfigs {
262+
cfg.HTTPConfig.SetDirectory(baseDir)
263+
}
261264
}
262265
}
263266

@@ -540,6 +543,17 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
540543
return fmt.Errorf("no msteams webhook URL or URLFile provided")
541544
}
542545
}
546+
for _, jira := range rcv.JiraConfigs {
547+
if jira.HTTPConfig == nil {
548+
jira.HTTPConfig = c.Global.HTTPConfig
549+
}
550+
if jira.APIURL == nil {
551+
if c.Global.JiraAPIURL == nil {
552+
return fmt.Errorf("no global Jira Cloud URL set")
553+
}
554+
jira.APIURL = c.Global.JiraAPIURL
555+
}
556+
}
543557

544558
names[rcv.Name] = struct{}{}
545559
}
@@ -742,29 +756,31 @@ type GlobalConfig struct {
742756

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

745-
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
746-
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
747-
SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
748-
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
749-
SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
750-
SMTPAuthPasswordFile string `yaml:"smtp_auth_password_file,omitempty" json:"smtp_auth_password_file,omitempty"`
751-
SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
752-
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
753-
SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"`
754-
SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
755-
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
756-
PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
757-
OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
758-
OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
759-
OpsGenieAPIKeyFile string `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"`
760-
WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
761-
WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
762-
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
763-
VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
764-
VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
765-
VictorOpsAPIKeyFile string `yaml:"victorops_api_key_file,omitempty" json:"victorops_api_key_file,omitempty"`
766-
TelegramAPIUrl *URL `yaml:"telegram_api_url,omitempty" json:"telegram_api_url,omitempty"`
767-
WebexAPIURL *URL `yaml:"webex_api_url,omitempty" json:"webex_api_url,omitempty"`
759+
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
760+
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
761+
SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
762+
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
763+
SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
764+
SMTPAuthPasswordFile string `yaml:"smtp_auth_password_file,omitempty" json:"smtp_auth_password_file,omitempty"`
765+
SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
766+
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
767+
SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"`
768+
SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
769+
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
770+
PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
771+
OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
772+
OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
773+
OpsGenieAPIKeyFile string `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"`
774+
WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
775+
WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
776+
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
777+
VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
778+
VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
779+
VictorOpsAPIKeyFile string `yaml:"victorops_api_key_file,omitempty" json:"victorops_api_key_file,omitempty"`
780+
TelegramAPIUrl *URL `yaml:"telegram_api_url,omitempty" json:"telegram_api_url,omitempty"`
781+
WebexAPIURL *URL `yaml:"webex_api_url,omitempty" json:"webex_api_url,omitempty"`
782+
SMTPTLSConfig *commoncfg.TLSConfig `yaml:"smtp_tls_config,omitempty" json:"smtp_tls_config,omitempty"`
783+
JiraAPIURL *URL `yaml:"jira_api_url,omitempty" json:"jira_api_url,omitempty"`
768784
}
769785

770786
// UnmarshalYAML implements the yaml.Unmarshaler interface for GlobalConfig.
@@ -909,6 +925,7 @@ type Receiver struct {
909925
TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"`
910926
WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"`
911927
MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"msteams_configs,omitempty"`
928+
JiraConfigs []*JiraConfig `yaml:"jira_configs,omitempty" json:"jira_configs,omitempty"`
912929
}
913930

914931
// UnmarshalYAML implements the yaml.Unmarshaler interface for Receiver.

config/notifiers.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
commoncfg "github.com/prometheus/common/config"
25+
"github.com/prometheus/common/model"
2526
"github.com/prometheus/common/sigv4"
2627
)
2728

@@ -172,6 +173,15 @@ var (
172173
Summary: `{{ template "msteams.default.summary" . }}`,
173174
Text: `{{ template "msteams.default.text" . }}`,
174175
}
176+
177+
DefaultJiraConfig = JiraConfig{
178+
NotifierConfig: NotifierConfig{
179+
VSendResolved: true,
180+
},
181+
Summary: `{{ template "jira.default.summary" . }}`,
182+
Description: `{{ template "jira.default.description" . }}`,
183+
Priority: `{{ template "jira.default.priority" . }}`,
184+
}
175185
)
176186

177187
// NotifierConfig contains base options common across all notifier configurations.
@@ -828,3 +838,41 @@ func (c *MSTeamsConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
828838

829839
return nil
830840
}
841+
842+
type JiraConfig struct {
843+
NotifierConfig `yaml:",inline" json:",inline"`
844+
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
845+
846+
APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"`
847+
848+
Project string `yaml:"project,omitempty" json:"project,omitempty"`
849+
Summary string `yaml:"summary,omitempty" json:"summary,omitempty"`
850+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
851+
Labels []string `yaml:"labels,omitempty" json:"labels,omitempty"`
852+
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
853+
IssueType string `yaml:"issue_type,omitempty" json:"issue_type,omitempty"`
854+
855+
ReopenTransition string `yaml:"reopen_transition,omitempty" json:"reopen_transition,omitempty"`
856+
ResolveTransition string `yaml:"resolve_transition,omitempty" json:"resolve_transition,omitempty"`
857+
WontFixResolution string `yaml:"wont_fix_resolution,omitempty" json:"wont_fix_resolution,omitempty"`
858+
ReopenDuration model.Duration `yaml:"reopen_duration,omitempty" json:"reopen_duration,omitempty"`
859+
860+
Fields map[string]any `yaml:"fields,omitempty" json:"custom_fields,omitempty"`
861+
}
862+
863+
func (c *JiraConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
864+
*c = DefaultJiraConfig
865+
type plain JiraConfig
866+
if err := unmarshal((*plain)(c)); err != nil {
867+
return err
868+
}
869+
870+
if c.Project == "" {
871+
return fmt.Errorf("missing project in jira_config")
872+
}
873+
if c.IssueType == "" {
874+
return fmt.Errorf("missing issue_type in jira_config")
875+
}
876+
877+
return nil
878+
}

config/receiver/receiver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/prometheus/alertmanager/notify"
2323
"github.com/prometheus/alertmanager/notify/discord"
2424
"github.com/prometheus/alertmanager/notify/email"
25+
"github.com/prometheus/alertmanager/notify/jira"
2526
"github.com/prometheus/alertmanager/notify/msteams"
2627
"github.com/prometheus/alertmanager/notify/opsgenie"
2728
"github.com/prometheus/alertmanager/notify/pagerduty"
@@ -92,6 +93,9 @@ func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg
9293
for i, c := range nc.MSTeamsConfigs {
9394
add("msteams", i, c, func(l log.Logger) (notify.Notifier, error) { return msteams.New(c, tmpl, l, httpOpts...) })
9495
}
96+
for i, c := range nc.JiraConfigs {
97+
add("jira", i, c, func(l log.Logger) (notify.Notifier, error) { return jira.New(c, tmpl, l, httpOpts...) })
98+
}
9599

96100
if errs.Len() > 0 {
97101
return nil, &errs

0 commit comments

Comments
 (0)