Skip to content

Commit

Permalink
feat: add phone call as alert channel types [sc-00] (#107)
Browse files Browse the repository at this point in the history
* feat: add phone call as alert channel types [sc-00]

* feat: use spaces [sc-00]
  • Loading branch information
maxigimenez committed Jun 29, 2023
1 parent 25bc090 commit 1cab48c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ const (
AlertTypeSMS = "SMS"
AlertTypePagerduty = "PAGERDUTY"
AlertTypeOpsgenie = "OPSGENIE"
AlertTypeCall = "CALL"
)

// AlertChannelSubscription represents a subscription to an alert channel.
Expand All @@ -663,6 +664,12 @@ type AlertChannelSMS struct {
Number string `json:"number"`
}

// AlertChannelCALL defines a type for a phone call alert channel
type AlertChannelCall struct {
Name string `json:"name"`
Number string `json:"number"`
}

// AlertChannelOpsgenie defines a type for an opsgenie alert channel
type AlertChannelOpsgenie struct {
Name string `json:"name"`
Expand Down Expand Up @@ -698,6 +705,7 @@ type AlertChannel struct {
Email *AlertChannelEmail `json:"-"`
Slack *AlertChannelSlack `json:"-"`
SMS *AlertChannelSMS `json:"-"`
CALL *AlertChannelCall `json:"-"`
Opsgenie *AlertChannelOpsgenie `json:"-"`
Webhook *AlertChannelWebhook `json:"-"`
Pagerduty *AlertChannelPagerduty `json:"-"`
Expand Down Expand Up @@ -796,6 +804,8 @@ func (a *AlertChannel) SetConfig(cfg interface{}) {
a.Email = cfg.(*AlertChannelEmail)
case *AlertChannelSMS:
a.SMS = cfg.(*AlertChannelSMS)
case *AlertChannelCall:
a.CALL = cfg.(*AlertChannelCall)
case *AlertChannelSlack:
a.Slack = cfg.(*AlertChannelSlack)
case *AlertChannelWebhook:
Expand All @@ -818,6 +828,8 @@ func (a *AlertChannel) GetConfig() (cfg map[string]interface{}) {
byts, err = json.Marshal(a.Email)
case AlertTypeSMS:
byts, err = json.Marshal(a.SMS)
case AlertTypeCall:
byts, err = json.Marshal(a.CALL)
case AlertTypeSlack:
byts, err = json.Marshal(a.Slack)
case AlertTypeOpsgenie:
Expand Down Expand Up @@ -846,6 +858,10 @@ func AlertChannelConfigFromJSON(channelType string, cfgJSON []byte) (interface{}
r := AlertChannelSMS{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeCall:
r := AlertChannelCall{}
json.Unmarshal(cfgJSON, &r)
return &r, nil
case AlertTypeSlack:
r := AlertChannelSlack{}
json.Unmarshal(cfgJSON, &r)
Expand Down
33 changes: 33 additions & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ func TestAlertChannelSMS(t *testing.T) {
}
}

func TestAlertChannelCALL(t *testing.T) {
ac := checkly.AlertChannel{
Type: checkly.AlertTypeCall,
}
cfg := checkly.AlertChannelCall{
Name: "foo",
Number: "0123456789",
}

ac.SetConfig(&cfg)

if ac.CALL == nil {
t.Error("Config shouldn't be nil")
return
}

if ac.CALL.Name != cfg.Name {
t.Errorf(
"Expected: `%s`, got: `%s`",
cfg.Name,
ac.CALL.Name,
)
}

if ac.CALL.Number != cfg.Number {
t.Errorf(
"Expected: `%s`, got: `%s`",
cfg.Number,
ac.CALL.Number,
)
}
}

func TestAlertChannelWebhook(t *testing.T) {
ac := checkly.AlertChannel{
Type: checkly.AlertTypeWebhook,
Expand Down

0 comments on commit 1cab48c

Please sign in to comment.