Skip to content

Commit ca26a1f

Browse files
authored
INTMDB-373: Add support for Webhook and MicrosoftTeamsWebhookURL Notifications (#320)
1 parent c9f1e14 commit ca26a1f

File tree

2 files changed

+196
-24
lines changed

2 files changed

+196
-24
lines changed

mongodbatlas/alert_configurations.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,32 @@ type Threshold struct {
100100

101101
// Notification sends when an alert condition is detected.
102102
type Notification struct {
103-
APIToken string `json:"apiToken,omitempty"` // Slack API token or Bot token. Populated for the SLACK notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
104-
ChannelName string `json:"channelName,omitempty"` // Slack channel name. Populated for the SLACK notifications type.
105-
DatadogAPIKey string `json:"datadogApiKey,omitempty"` // Datadog API Key. Found in the Datadog dashboard. Populated for the DATADOG notifications type.
106-
DatadogRegion string `json:"datadogRegion,omitempty"` // Region that indicates which API URL to use
107-
DelayMin *int `json:"delayMin,omitempty"` // Number of minutes to wait after an alert condition is detected before sending out the first notification.
108-
EmailAddress string `json:"emailAddress,omitempty"` // Email address to which alert notifications are sent. Populated for the EMAIL notifications type.
109-
EmailEnabled *bool `json:"emailEnabled,omitempty"` // Flag indicating if email notifications should be sent. Populated for ORG, GROUP, and USER notifications types.
110-
FlowdockAPIToken string `json:"flowdockApiToken,omitempty"` // The Flowdock personal API token. Populated for the FLOWDOCK notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
111-
FlowName string `json:"flowName,omitempty"` // Flowdock flow namse in lower-case letters.
112-
IntervalMin int `json:"intervalMin,omitempty"` // Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved.
113-
MobileNumber string `json:"mobileNumber,omitempty"` // Mobile number to which alert notifications are sent. Populated for the SMS notifications type.
114-
OpsGenieAPIKey string `json:"opsGenieApiKey,omitempty"` // Opsgenie API Key. Populated for the OPS_GENIE notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
115-
OpsGenieRegion string `json:"opsGenieRegion,omitempty"` // Region that indicates which API URL to use.
116-
OrgName string `json:"orgName,omitempty"` // Flowdock organization name in lower-case letters. This is the name that appears after www.flowdock.com/app/ in the URL string. Populated for the FLOWDOCK notifications type.
117-
ServiceKey string `json:"serviceKey,omitempty"` // PagerDuty service key. Populated for the PAGER_DUTY notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
118-
SMSEnabled *bool `json:"smsEnabled,omitempty"` // Flag indicating if text message notifications should be sent. Populated for ORG, GROUP, and USER notifications types.
119-
TeamID string `json:"teamId,omitempty"` // Unique identifier of a team.
120-
TeamName string `json:"teamName,omitempty"` // Label for the team that receives this notification.
121-
TypeName string `json:"typeName,omitempty"` // Type of alert notification.
122-
Username string `json:"username,omitempty"` // Name of the Atlas user to which to send notifications. Only a user in the project that owns the alert configuration is allowed here. Populated for the USER notifications type.
123-
VictorOpsAPIKey string `json:"victorOpsApiKey,omitempty"` // VictorOps API key. Populated for the VICTOR_OPS notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
124-
VictorOpsRoutingKey string `json:"victorOpsRoutingKey,omitempty"` // VictorOps routing key. Populated for the VICTOR_OPS notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
125-
Roles []string `json:"roles,omitempty"` // The following roles grant privileges within a project.
126-
103+
APIToken string `json:"apiToken,omitempty"` // Slack API token or Bot token. Populated for the SLACK notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
104+
ChannelName string `json:"channelName,omitempty"` // Slack channel name. Populated for the SLACK notifications type.
105+
DatadogAPIKey string `json:"datadogApiKey,omitempty"` // Datadog API Key. Found in the Datadog dashboard. Populated for the DATADOG notifications type.
106+
DatadogRegion string `json:"datadogRegion,omitempty"` // Region that indicates which API URL to use
107+
DelayMin *int `json:"delayMin,omitempty"` // Number of minutes to wait after an alert condition is detected before sending out the first notification.
108+
EmailAddress string `json:"emailAddress,omitempty"` // Email address to which alert notifications are sent. Populated for the EMAIL notifications type.
109+
EmailEnabled *bool `json:"emailEnabled,omitempty"` // Flag indicating if email notifications should be sent. Populated for ORG, GROUP, and USER notifications types.
110+
FlowdockAPIToken string `json:"flowdockApiToken,omitempty"` // The Flowdock personal API token. Populated for the FLOWDOCK notifications type. If the token later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
111+
FlowName string `json:"flowName,omitempty"` // Flowdock flow namse in lower-case letters.
112+
IntervalMin int `json:"intervalMin,omitempty"` // Number of minutes to wait between successive notifications for unacknowledged alerts that are not resolved.
113+
MobileNumber string `json:"mobileNumber,omitempty"` // Mobile number to which alert notifications are sent. Populated for the SMS notifications type.
114+
OpsGenieAPIKey string `json:"opsGenieApiKey,omitempty"` // Opsgenie API Key. Populated for the OPS_GENIE notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the token.
115+
OpsGenieRegion string `json:"opsGenieRegion,omitempty"` // Region that indicates which API URL to use.
116+
OrgName string `json:"orgName,omitempty"` // Flowdock organization name in lower-case letters. This is the name that appears after www.flowdock.com/app/ in the URL string. Populated for the FLOWDOCK notifications type.
117+
ServiceKey string `json:"serviceKey,omitempty"` // PagerDuty service key. Populated for the PAGER_DUTY notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
118+
SMSEnabled *bool `json:"smsEnabled,omitempty"` // Flag indicating if text message notifications should be sent. Populated for ORG, GROUP, and USER notifications types.
119+
TeamID string `json:"teamId,omitempty"` // Unique identifier of a team.
120+
TeamName string `json:"teamName,omitempty"` // Label for the team that receives this notification.
121+
TypeName string `json:"typeName,omitempty"` // Type of alert notification.
122+
Username string `json:"username,omitempty"` // Name of the Atlas user to which to send notifications. Only a user in the project that owns the alert configuration is allowed here. Populated for the USER notifications type.
123+
VictorOpsAPIKey string `json:"victorOpsApiKey,omitempty"` // VictorOps API key. Populated for the VICTOR_OPS notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
124+
VictorOpsRoutingKey string `json:"victorOpsRoutingKey,omitempty"` // VictorOps routing key. Populated for the VICTOR_OPS notifications type. If the key later becomes invalid, Atlas sends an email to the project owner and eventually removes the key.
125+
Roles []string `json:"roles,omitempty"` // The following roles grant privileges within a project.
126+
MicrosoftTeamsWebhookURL string `json:"microsoftTeamsWebhookUrl,omitempty"` // Microsoft Teams Wewbhook URL
127+
WebhookSecret string `json:"webhookSecret,omitempty"` // Webhook Secret
128+
WebhookURL string `json:"webhookUrl,omitempty"` // Webhook URL
127129
}
128130

129131
// AlertConfigurationsResponse is the response from the AlertConfigurationsService.List.

mongodbatlas/alert_configurations_test.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,173 @@ func TestAlertConfiguration_ListMatcherFields(t *testing.T) {
676676
t.Error(diff)
677677
}
678678
}
679+
680+
func TestAlertConfiguration_GetAnAlertConfigTeams(t *testing.T) {
681+
client, mux, teardown := setup()
682+
defer teardown()
683+
684+
groupID := "535683b3794d371327b"
685+
alertConfigID := "57b76ddc96e8215c017ceafb"
686+
687+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
688+
testMethod(t, r, http.MethodGet)
689+
fmt.Fprint(w, `{
690+
"id": "533dc40ae4b00835ff81eaee",
691+
"groupId": "535683b3794d371327b",
692+
"eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
693+
"created": "2016-08-23T20:26:50Z",
694+
"updated": "2016-08-23T20:26:50Z",
695+
"enabled": true,
696+
"matchers": [
697+
{
698+
"fieldName": "HOSTNAME_AND_PORT",
699+
"operator": "EQUALS",
700+
"value": "mongo.example.com:27017"
701+
}
702+
],
703+
"notifications": [
704+
{
705+
"typeName": "MICROSOFT_TEAMS",
706+
"intervalMin": 5,
707+
"delayMin": 0,
708+
"microsoftTeamsWebhookUrl": "http://941a-47-225-212-178.ngrok.io",
709+
"roles" : ["GROUP_DATA_ACCESS_ADMIN", "GROUP_DATA_ACCESS_READ_ONLY"]
710+
}
711+
],
712+
"metricThreshold": {
713+
"metricName": "ASSERT_REGULAR",
714+
"operator": "LESS_THAN",
715+
"threshold": 99.0,
716+
"units": "RAW",
717+
"mode": "AVERAGE"
718+
}
719+
}`)
720+
})
721+
722+
alertConfiguration, _, err := client.AlertConfigurations.GetAnAlertConfig(ctx, groupID, alertConfigID)
723+
if err != nil {
724+
t.Fatalf("AlertConfigurations.GetAnAlertConfigTeams returned error: %v", err)
725+
}
726+
727+
expected := &AlertConfiguration{
728+
ID: "533dc40ae4b00835ff81eaee",
729+
GroupID: "535683b3794d371327b",
730+
EventTypeName: "OUTSIDE_METRIC_THRESHOLD",
731+
Created: "2016-08-23T20:26:50Z",
732+
Updated: "2016-08-23T20:26:50Z",
733+
Enabled: pointy.Bool(true),
734+
Matchers: []Matcher{
735+
{
736+
FieldName: "HOSTNAME_AND_PORT",
737+
Operator: "EQUALS",
738+
Value: "mongo.example.com:27017",
739+
},
740+
},
741+
Notifications: []Notification{
742+
{
743+
TypeName: "MICROSOFT_TEAMS",
744+
IntervalMin: 5,
745+
DelayMin: pointy.Int(0),
746+
MicrosoftTeamsWebhookURL: "http://941a-47-225-212-178.ngrok.io",
747+
Roles: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_DATA_ACCESS_READ_ONLY"},
748+
},
749+
},
750+
MetricThreshold: &MetricThreshold{
751+
MetricName: "ASSERT_REGULAR",
752+
Operator: "LESS_THAN",
753+
Threshold: 99.0,
754+
Units: "RAW",
755+
Mode: "AVERAGE",
756+
},
757+
}
758+
759+
if diff := deep.Equal(alertConfiguration, expected); diff != nil {
760+
t.Error(diff)
761+
}
762+
}
763+
764+
func TestAlertConfiguration_GetAnAlertConfigWebhook(t *testing.T) {
765+
client, mux, teardown := setup()
766+
defer teardown()
767+
768+
groupID := "535683b3794d371327b"
769+
alertConfigID := "57b76ddc96e8215c017ceafb"
770+
771+
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/alertConfigs/%s", groupID, alertConfigID), func(w http.ResponseWriter, r *http.Request) {
772+
testMethod(t, r, http.MethodGet)
773+
fmt.Fprint(w, `{
774+
"id": "533dc40ae4b00835ff81eaee",
775+
"groupId": "535683b3794d371327b",
776+
"eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
777+
"created": "2016-08-23T20:26:50Z",
778+
"updated": "2016-08-23T20:26:50Z",
779+
"enabled": true,
780+
"matchers": [
781+
{
782+
"fieldName": "HOSTNAME_AND_PORT",
783+
"operator": "EQUALS",
784+
"value": "mongo.example.com:27017"
785+
}
786+
],
787+
"notifications": [
788+
{
789+
"typeName": "WEBHOOK",
790+
"intervalMin": 5,
791+
"delayMin": 0,
792+
"webhookSecret": "SECRET",
793+
"webhookUrl": "http://941a-47-225-212-178.ngrok.io",
794+
"roles" : ["GROUP_DATA_ACCESS_ADMIN", "GROUP_DATA_ACCESS_READ_ONLY"]
795+
}
796+
],
797+
"metricThreshold": {
798+
"metricName": "ASSERT_REGULAR",
799+
"operator": "LESS_THAN",
800+
"threshold": 99.0,
801+
"units": "RAW",
802+
"mode": "AVERAGE"
803+
}
804+
}`)
805+
})
806+
807+
alertConfiguration, _, err := client.AlertConfigurations.GetAnAlertConfig(ctx, groupID, alertConfigID)
808+
if err != nil {
809+
t.Fatalf("AlertConfigurations.GetAnAlertConfig returned error: %v", err)
810+
}
811+
812+
expected := &AlertConfiguration{
813+
ID: "533dc40ae4b00835ff81eaee",
814+
GroupID: "535683b3794d371327b",
815+
EventTypeName: "OUTSIDE_METRIC_THRESHOLD",
816+
Created: "2016-08-23T20:26:50Z",
817+
Updated: "2016-08-23T20:26:50Z",
818+
Enabled: pointy.Bool(true),
819+
Matchers: []Matcher{
820+
{
821+
FieldName: "HOSTNAME_AND_PORT",
822+
Operator: "EQUALS",
823+
Value: "mongo.example.com:27017",
824+
},
825+
},
826+
Notifications: []Notification{
827+
{
828+
TypeName: "WEBHOOK",
829+
IntervalMin: 5,
830+
DelayMin: pointy.Int(0),
831+
WebhookSecret: "SECRET",
832+
WebhookURL: "http://941a-47-225-212-178.ngrok.io",
833+
Roles: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_DATA_ACCESS_READ_ONLY"},
834+
},
835+
},
836+
MetricThreshold: &MetricThreshold{
837+
MetricName: "ASSERT_REGULAR",
838+
Operator: "LESS_THAN",
839+
Threshold: 99.0,
840+
Units: "RAW",
841+
Mode: "AVERAGE",
842+
},
843+
}
844+
845+
if diff := deep.Equal(alertConfiguration, expected); diff != nil {
846+
t.Error(diff)
847+
}
848+
}

0 commit comments

Comments
 (0)