mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 03:38:43 +00:00
Add support for opsgenie_api_key_file in the global Alertmanager configuration (#4666)
* add opsgenie_api_key_file Signed-off-by: mikechengwei <842725815@qq.com> * add opsgenie_api_key_file Signed-off-by: mikechengwei <842725815@qq.com> * optimize code * optimize code * optimize code
This commit is contained in:
parent
730295b500
commit
88b55bd5e0
3 changed files with 55 additions and 20 deletions
pkg/alertmanager
|
@ -1289,6 +1289,12 @@ func (gc *globalConfig) sanitize(amVersion semver.Version, logger log.Logger) er
|
|||
gc.SlackAPIURLFile = ""
|
||||
}
|
||||
}
|
||||
|
||||
if len(gc.OpsGenieAPIKeyFile) > 0 && !amVersion.GTE(semver.MustParse("0.24.0")) {
|
||||
msg := "'opsgenie_api_key_file' supported in AlertManager >= 0.24.0 only - dropping field from provided config"
|
||||
level.Warn(logger).Log("msg", msg, "current_version", amVersion.String())
|
||||
gc.OpsGenieAPIKeyFile = ""
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1370,6 +1370,8 @@ func TestSanitizeConfig(t *testing.T) {
|
|||
matcherV2SyntaxAllowed := semver.Version{Major: 0, Minor: 22}
|
||||
matcherV2SyntaxNotAllowed := semver.Version{Major: 0, Minor: 21}
|
||||
|
||||
versionOpsGenieAPIKeyFileAllowed := semver.Version{Major: 0, Minor: 24}
|
||||
versionOpsGenieAPIKeyFileNotAllowed := semver.Version{Major: 0, Minor: 23}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
againstVersion semver.Version
|
||||
|
@ -1620,6 +1622,32 @@ func TestSanitizeConfig(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test slack_api_url_file config",
|
||||
againstVersion: versionOpsGenieAPIKeyFileAllowed,
|
||||
in: &alertmanagerConfig{
|
||||
Global: &globalConfig{
|
||||
OpsGenieAPIKeyFile: "/test",
|
||||
},
|
||||
},
|
||||
expect: alertmanagerConfig{
|
||||
Global: &globalConfig{
|
||||
OpsGenieAPIKeyFile: "/test",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test slack_api_url_file is dropped for unsupported versions",
|
||||
againstVersion: versionOpsGenieAPIKeyFileNotAllowed,
|
||||
in: &alertmanagerConfig{
|
||||
Global: &globalConfig{
|
||||
OpsGenieAPIKeyFile: "/test",
|
||||
},
|
||||
},
|
||||
expect: alertmanagerConfig{
|
||||
Global: &globalConfig{},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.in.sanitize(tc.againstVersion, logger)
|
||||
|
|
|
@ -43,26 +43,27 @@ type globalConfig struct {
|
|||
|
||||
HTTPConfig *httpClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
|
||||
|
||||
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
|
||||
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
|
||||
SMTPSmarthost config.HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
|
||||
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
|
||||
SMTPAuthPassword string `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
|
||||
SMTPAuthSecret string `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
|
||||
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
|
||||
SMTPRequireTLS *bool `yaml:"smtp_require_tls,omitempty" json:"smtp_require_tls,omitempty"`
|
||||
SlackAPIURL *config.URL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
|
||||
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
|
||||
PagerdutyURL *config.URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
|
||||
HipchatAPIURL *config.URL `yaml:"hipchat_api_url,omitempty" json:"hipchat_api_url,omitempty"`
|
||||
HipchatAuthToken string `yaml:"hipchat_auth_token,omitempty" json:"hipchat_auth_token,omitempty"`
|
||||
OpsGenieAPIURL *config.URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
|
||||
OpsGenieAPIKey string `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
|
||||
WeChatAPIURL *config.URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
|
||||
WeChatAPISecret string `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
|
||||
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
|
||||
VictorOpsAPIURL *config.URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
|
||||
VictorOpsAPIKey string `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
|
||||
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
|
||||
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
|
||||
SMTPSmarthost config.HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
|
||||
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
|
||||
SMTPAuthPassword string `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
|
||||
SMTPAuthSecret string `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
|
||||
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
|
||||
SMTPRequireTLS *bool `yaml:"smtp_require_tls,omitempty" json:"smtp_require_tls,omitempty"`
|
||||
SlackAPIURL *config.URL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
|
||||
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
|
||||
PagerdutyURL *config.URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
|
||||
HipchatAPIURL *config.URL `yaml:"hipchat_api_url,omitempty" json:"hipchat_api_url,omitempty"`
|
||||
HipchatAuthToken string `yaml:"hipchat_auth_token,omitempty" json:"hipchat_auth_token,omitempty"`
|
||||
OpsGenieAPIURL *config.URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
|
||||
OpsGenieAPIKey string `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
|
||||
WeChatAPIURL *config.URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
|
||||
WeChatAPISecret string `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
|
||||
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
|
||||
VictorOpsAPIURL *config.URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
|
||||
VictorOpsAPIKey string `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
|
||||
OpsGenieAPIKeyFile string `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"`
|
||||
}
|
||||
|
||||
type route struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue