Skip to content

Commit 68a5ffc

Browse files
committed
feat: add ACLP list entities method
Add entity envelope in AlertDefinition GET, POST and PUT API responses. Add new method to list entities. Update tests.
1 parent 09803f2 commit 68a5ffc

7 files changed

+749
-207
lines changed

monitor_alert_definitions.go

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,54 @@ const (
1919
AlertDefinitionStatusFailed AlertDefinitionStatus = "failed"
2020
)
2121

22+
// AlertDefinitionScope represents the scope of an alert definition: "account", "entity", or "region". Defaults to "entity".
23+
type AlertDefinitionScope string
24+
25+
const (
26+
AlertDefinitionScopeAccount AlertDefinitionScope = "account"
27+
AlertDefinitionScopeEntity AlertDefinitionScope = "entity"
28+
AlertDefinitionScopeRegion AlertDefinitionScope = "region"
29+
)
30+
31+
// AlertDefinitionEntities represents entity metadata for an alert definition.
32+
// For entity scoped alerts, entities contains the URL to list entities, a count, and a has_more_resources flag.
33+
// For region/account scoped alerts, the entities are returned as an empty object.
34+
type AlertDefinitionEntities struct {
35+
URL string `json:"url"`
36+
Count int `json:"count"`
37+
HasMoreResources bool `json:"has_more_resources"`
38+
}
39+
40+
// AlertDefinitionEntity represents a single entity associated with an alert definition.
41+
type AlertDefinitionEntity struct {
42+
ID string `json:"id"`
43+
Label string `json:"label"`
44+
URL string `json:"url"`
45+
Type string `json:"type"`
46+
}
47+
2248
// AlertDefinition represents an ACLP Alert Definition object
2349
type AlertDefinition struct {
24-
ID int `json:"id"`
25-
Label string `json:"label"`
26-
Severity int `json:"severity"`
27-
Type string `json:"type"`
28-
ServiceType string `json:"service_type"`
29-
Status AlertDefinitionStatus `json:"status"`
30-
HasMoreResources bool `json:"has_more_resources"`
31-
RuleCriteria RuleCriteria `json:"rule_criteria"`
32-
TriggerConditions TriggerConditions `json:"trigger_conditions"`
33-
AlertChannels []AlertChannelEnvelope `json:"alert_channels"`
34-
Created *time.Time `json:"-"`
35-
Updated *time.Time `json:"-"`
36-
UpdatedBy string `json:"updated_by"`
37-
CreatedBy string `json:"created_by"`
38-
EntityIDs []string `json:"entity_ids"`
39-
Description string `json:"description"`
40-
Class string `json:"class"`
50+
ID int `json:"id"`
51+
Label string `json:"label"`
52+
Severity int `json:"severity"`
53+
Type string `json:"type"`
54+
ServiceType string `json:"service_type"`
55+
Status AlertDefinitionStatus `json:"status"`
56+
HasMoreResources bool `json:"has_more_resources"` // Deprecated: use Entities.HasMoreResources.
57+
RuleCriteria RuleCriteria `json:"rule_criteria"`
58+
TriggerConditions TriggerConditions `json:"trigger_conditions"`
59+
AlertChannels []AlertChannelEnvelope `json:"alert_channels"`
60+
Created *time.Time `json:"-"`
61+
Updated *time.Time `json:"-"`
62+
UpdatedBy string `json:"updated_by"`
63+
CreatedBy string `json:"created_by"`
64+
EntityIDs []string `json:"entity_ids"` // Deprecated: use Entities.url to list associated entities.
65+
Description string `json:"description"`
66+
Class string `json:"class"`
67+
Scope AlertDefinitionScope `json:"scope"`
68+
Regions []string `json:"regions"`
69+
Entities AlertDefinitionEntities `json:"entities"`
4170
}
4271

4372
// Backwards-compatible alias
@@ -143,6 +172,8 @@ type AlertDefinitionCreateOptions struct {
143172
TriggerConditions *TriggerConditions `json:"trigger_conditions,omitempty"`
144173
EntityIDs []string `json:"entity_ids,omitempty"`
145174
Description *string `json:"description,omitempty"`
175+
Scope AlertDefinitionScope `json:"scope,omitempty"`
176+
Regions []string `json:"regions,omitzero"`
146177
}
147178

148179
// AlertDefinitionUpdateOptions are the options used to update an alert definition.
@@ -155,6 +186,7 @@ type AlertDefinitionUpdateOptions struct {
155186
EntityIDs []string `json:"entity_ids,omitempty"`
156187
Description *string `json:"description,omitempty"`
157188
Status *AlertDefinitionStatus `json:"status,omitempty"`
189+
Regions []string `json:"regions,omitzero"`
158190
}
159191

160192
// UnmarshalJSON implements the json.Unmarshaler interface
@@ -268,3 +300,14 @@ func (c *Client) DeleteMonitorAlertDefinition(ctx context.Context, serviceType s
268300
e := formatAPIPath("monitor/services/%s/alert-definitions/%d", serviceType, alertID)
269301
return doDELETERequest(ctx, c, e)
270302
}
303+
304+
// ListMonitorAlertDefinitionEntities gets the entities associated with an ACLP Monitor Alert Definition.
305+
func (c *Client) ListMonitorAlertDefinitionEntities(
306+
ctx context.Context,
307+
serviceType string,
308+
alertID int,
309+
opts *ListOptions,
310+
) ([]AlertDefinitionEntity, error) {
311+
e := formatAPIPath("monitor/services/%s/alert-definitions/%d/entities", serviceType, alertID)
312+
return getPaginatedResults[AlertDefinitionEntity](ctx, c, e, opts)
313+
}

0 commit comments

Comments
 (0)