Skip to content

Commit

Permalink
add service.alert_grouping_params field
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott McAllister committed Dec 18, 2020
1 parent 8796b5a commit 7edbc92
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 16 deletions.
46 changes: 30 additions & 16 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,36 @@ type IncidentUrgencyRule struct {
// Service represents something you monitor (like a web service, email service, or database service).
type Service struct {
APIObject
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
AutoResolveTimeout *uint `json:"auto_resolve_timeout"`
AcknowledgementTimeout *uint `json:"acknowledgement_timeout"`
CreateAt string `json:"created_at,omitempty"`
Status string `json:"status,omitempty"`
LastIncidentTimestamp string `json:"last_incident_timestamp,omitempty"`
Integrations []Integration `json:"integrations,omitempty"`
EscalationPolicy EscalationPolicy `json:"escalation_policy,omitempty"`
Teams []Team `json:"teams,omitempty"`
IncidentUrgencyRule *IncidentUrgencyRule `json:"incident_urgency_rule,omitempty"`
SupportHours *SupportHours `json:"support_hours,omitempty"`
ScheduledActions []ScheduledAction `json:"scheduled_actions"`
AlertCreation string `json:"alert_creation,omitempty"`
AlertGrouping string `json:"alert_grouping,omitempty"`
AlertGroupingTimeout *uint `json:"alert_grouping_timeout,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
AutoResolveTimeout *uint `json:"auto_resolve_timeout"`
AcknowledgementTimeout *uint `json:"acknowledgement_timeout"`
CreateAt string `json:"created_at,omitempty"`
Status string `json:"status,omitempty"`
LastIncidentTimestamp string `json:"last_incident_timestamp,omitempty"`
Integrations []Integration `json:"integrations,omitempty"`
EscalationPolicy EscalationPolicy `json:"escalation_policy,omitempty"`
Teams []Team `json:"teams,omitempty"`
IncidentUrgencyRule *IncidentUrgencyRule `json:"incident_urgency_rule,omitempty"`
SupportHours *SupportHours `json:"support_hours,omitempty"`
ScheduledActions []ScheduledAction `json:"scheduled_actions"`
AlertCreation string `json:"alert_creation,omitempty"`
AlertGrouping string `json:"alert_grouping,omitempty"`
AlertGroupingTimeout *uint `json:"alert_grouping_timeout,omitempty"`
AlertGroupingParameters *AlertGroupingParameters `json:"alert_grouping_parameters,omitempty"`
}

// AlertGroupingParameters defines how alerts on the servicewill be automatically grouped into incidents
type AlertGroupingParameters struct {
Type string `json:"type"`
Config AlertGroupParamsConfig `json:"config"`
}

// AlertGroupParamsConfig is the config object on alert_grouping_parameters
type AlertGroupParamsConfig struct {
Timeout uint `json:"timeout,omitempty"`
Aggregate string `json:"aggregate,omitempty"`
Fields []string `json:"fields,omitempty"`
}

// ListServiceOptions is the data structure used when calling the ListServices API endpoint.
Expand Down
103 changes: 103 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,109 @@ func TestService_Create(t *testing.T) {
testEqual(t, want, res)
}

// Create Service with AlertGroupingParameters of type time
func TestService_CreateWithAlertGroupParamsTime(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
w.Write([]byte(`{"service": {"id": "1","name":"foo"}}`))
})

var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
input := Service{
Name: "foo",
AlertGroupingParameters: &AlertGroupingParameters{
Type: "time",
Config: AlertGroupParamsConfig{
Timeout: 2,
},
},
}
res, err := client.CreateService(input)

want := &Service{
APIObject: APIObject{
ID: "1",
},
Name: "foo",
}

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

// Create Service with AlertGroupingParameters of type content_based
func TestService_CreateWithAlertGroupParamsContentBased(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
w.Write([]byte(`{"service": {"id": "1","name":"foo"}}`))
})

var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
input := Service{
Name: "foo",
AlertGroupingParameters: &AlertGroupingParameters{
Type: "content_based",
Config: AlertGroupParamsConfig{
Aggregate: "any",
Fields: []string{"source", "component"},
},
},
}
res, err := client.CreateService(input)

want := &Service{
APIObject: APIObject{
ID: "1",
},
Name: "foo",
}

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

// Create Service with AlertGroupingParameters of type intelligent
func TestService_CreateWithAlertGroupParamsIntelligent(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
w.Write([]byte(`{"service": {"id": "1","name":"foo"}}`))
})

var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
input := Service{
Name: "foo",
AlertGroupingParameters: &AlertGroupingParameters{
Type: "intelligent",
},
}
res, err := client.CreateService(input)

want := &Service{
APIObject: APIObject{
ID: "1",
},
Name: "foo",
}

if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}

// Update Service
func TestService_Update(t *testing.T) {
setup()
Expand Down

0 comments on commit 7edbc92

Please sign in to comment.