Review changes

This commit is contained in:
cemturker 2020-11-24 17:15:52 +01:00
parent 978acf3cd2
commit daf27fd6d0
4 changed files with 28 additions and 25 deletions

View File

@ -129,8 +129,8 @@ Note that you can also add environment variables in the configuration file (i.e.
| `alerting.mattermost.insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
| `alerting.messagebird` | Settings for alerts of type `messagebird` | `{}` |
| `alerting.messagebird.access-key` | Messagebird access key | Required `""` |
| `alerting.messagebird.originator` | The sender of the message | Required `""` |
| `alerting.messagebird.recipients` | The recipients of the message | Required `""` |
| `alerting.messagebird.from` | The sender of the message | Required `""` |
| `alerting.messagebird.to` | The recipients of the message | Required `""` |
| `alerting.custom` | Configuration for custom actions on failure or alerts | `{}` |
| `alerting.custom.url` | Custom alerting request url | Required `""` |
| `alerting.custom.method` | Request method | `GET` |
@ -319,8 +319,8 @@ Example of sending **sms** message alert by using Messagebird
alerting:
messagebird:
access-key: "..."
originator: "31619191918"
recipients: "31619191919"
to: "31619191918"
from: "31619191919,31619191920"
services:
- name: twinnation
interval: 30s

View File

@ -14,14 +14,14 @@ const (
// AlertProvider is the configuration necessary for sending an alert using Messagebird
type AlertProvider struct {
AccessKey string `yaml:"access-key"`
Originator string `yaml:"originator"`
Recipients string `yaml:"recipients"`
AccessKey string `yaml:"access-key"`
From string `yaml:"from"`
To string `yaml:"to"`
}
// IsValid returns whether the provider's configuration is valid
func (provider *AlertProvider) IsValid() bool {
return len(provider.AccessKey) > 0 && len(provider.Originator) > 0 && len(provider.Recipients) > 0
return len(provider.AccessKey) > 0 && len(provider.From) > 0 && len(provider.To) > 0
}
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
@ -37,8 +37,11 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
return &custom.AlertProvider{
URL: restAPIURL,
Method: http.MethodPost,
Body: fmt.Sprintf(`{ "originator": "%s", "recipients": "%s", "body": "%s"}`,
provider.Originator, provider.Recipients, message),
Body: fmt.Sprintf(`{
"originator": "%s",
"recipients": "%s",
"body": "%s"
}`, provider.From, provider.To, message),
Headers: map[string]string{
"Content-Type": "application/json",
"Authorization": fmt.Sprintf("AccessKey %s", provider.AccessKey),

View File

@ -13,9 +13,9 @@ func TestMessagebirdAlertProvider_IsValid(t *testing.T) {
t.Error("provider shouldn't have been valid")
}
validProvider := AlertProvider{
AccessKey: "1",
Originator: "1",
Recipients: "1",
AccessKey: "1",
From: "1",
To: "1",
}
if !validProvider.IsValid() {
t.Error("provider should've been valid")
@ -24,9 +24,9 @@ func TestMessagebirdAlertProvider_IsValid(t *testing.T) {
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
provider := AlertProvider{
AccessKey: "1",
Originator: "1",
Recipients: "1",
AccessKey: "1",
From: "1",
To: "1",
}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
if customAlertProvider == nil {
@ -39,9 +39,9 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
provider := AlertProvider{
AccessKey: "1",
Originator: "1",
Recipients: "1",
AccessKey: "1",
From: "1",
To: "1",
}
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
if customAlertProvider == nil {

View File

@ -368,8 +368,8 @@ alerting:
integration-key: "00000000000000000000000000000000"
messagebird:
access-key: "1"
originator: "31619191918"
recipients: "31619191919"
from: "31619191918"
to: "31619191919"
services:
- name: twinnation
url: https://twinnation.org/health
@ -416,11 +416,11 @@ services:
if config.Alerting.Messagebird.AccessKey != "1" {
t.Errorf("Messagebird access key should've been %s, but was %s", "1", config.Alerting.Messagebird.AccessKey)
}
if config.Alerting.Messagebird.Originator != "31619191918" {
t.Errorf("Messagebird originator should've been %s, but was %s", "31619191918", config.Alerting.Messagebird.Originator)
if config.Alerting.Messagebird.From != "31619191918" {
t.Errorf("Messagebird originator should've been %s, but was %s", "31619191918", config.Alerting.Messagebird.From)
}
if config.Alerting.Messagebird.Recipients != "31619191919" {
t.Errorf("Messagebird recipients should've been %s, but was %s", "31619191919", config.Alerting.Messagebird.Recipients)
if config.Alerting.Messagebird.To != "31619191919" {
t.Errorf("Messagebird recipients should've been %s, but was %s", "31619191919", config.Alerting.Messagebird.To)
}
if len(config.Services) != 1 {
t.Error("There should've been 1 service")