Skip to content

Commit 11406ad

Browse files
authored
Add alert source APIs (#543)
* Add default value to documentation on fields based on schema * Add alert source APIs
1 parent 014f59c commit 11406ad

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Feature
2+
body: Add `client.CreateOrUpdateAlertSource` and `client.UpdateAlertSourceStatus` to interface with the new generic alert source APIs
3+
time: 2025-05-14T14:42:47.635522-05:00

alert_source.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ func NewAlertSource(kind AlertSourceTypeEnum, id string) *AlertSourceExternalIde
1212
return &output
1313
}
1414

15+
func (client *Client) CreateOrUpdateAlertSource(input AlertSourceInput) (*AlertSource, error) {
16+
var m struct {
17+
Payload struct {
18+
AlertSource AlertSource
19+
Errors []Error
20+
} `graphql:"alertSourceUpsert(input: $input)"`
21+
}
22+
v := PayloadVariables{
23+
"input": input,
24+
}
25+
err := client.Mutate(&m, v, WithName("AlertSourceUpsert"))
26+
return &m.Payload.AlertSource, HandleErrors(err, m.Payload.Errors)
27+
}
28+
1529
func (client *Client) CreateAlertSourceService(input AlertSourceServiceCreateInput) (*AlertSourceService, error) {
1630
var m struct {
1731
Payload AlertSourceServiceCreatePayload `graphql:"alertSourceServiceCreate(input: $input)"`
@@ -51,6 +65,20 @@ func (client *Client) GetAlertSource(id ID) (*AlertSource, error) {
5165
return &q.Account.AlertSource, HandleErrors(err, nil)
5266
}
5367

68+
func (client *Client) UpdateAlertSourceStatus(input AlertSourceStatusUpdateInput) (*AlertSource, error) {
69+
var m struct {
70+
Payload struct {
71+
AlertSource AlertSource
72+
Errors []Error
73+
} `graphql:"alertSourceStatusUpdate(input: $input)"`
74+
}
75+
v := PayloadVariables{
76+
"input": input,
77+
}
78+
err := client.Mutate(&m, v, WithName("AlertSourceStatusUpdate"))
79+
return &m.Payload.AlertSource, HandleErrors(err, m.Payload.Errors)
80+
}
81+
5482
func (client *Client) DeleteAlertSourceService(id ID) error {
5583
var m struct {
5684
Payload BasePayload `graphql:"alertSourceServiceDelete(input: $input)"`

input.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import "github.com/relvacode/iso8601"
66
// AlertSourceExternalIdentifier Specifies the input needed to find an alert source with external information
77
type AlertSourceExternalIdentifier struct {
88
ExternalId string `json:"externalId" yaml:"externalId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The external id of the alert (Required)
9-
Type AlertSourceTypeEnum `json:"type" yaml:"type" example:"datadog"` // The type of the alert (Required)
9+
Type AlertSourceTypeEnum `json:"type" yaml:"type" example:"custom"` // The type of the alert (Required)
10+
}
11+
12+
// AlertSourceInput Input fields for the mutations to manage Alert Sources
13+
type AlertSourceInput struct {
14+
Description *Nullable[string] `json:"description,omitempty" yaml:"description,omitempty" example:"example_value"` // The description of the alert source (Optional)
15+
Identifier ExternalResourceIdentifierInput `json:"identifier" yaml:"identifier"` // The alert source identifier (Required)
16+
Name *Nullable[string] `json:"name,omitempty" yaml:"name,omitempty" example:"example_value"` // The name of the alert source (Optional)
17+
Url *Nullable[string] `json:"url,omitempty" yaml:"url,omitempty" example:"example_value"` // The url of the alert source (Optional)
1018
}
1119

1220
// AlertSourceServiceCreateInput Specifies the input used for attaching an alert source to a service
@@ -21,6 +29,12 @@ type AlertSourceServiceDeleteInput struct {
2129
Id ID `json:"id" yaml:"id" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the alert source service to be deleted (Required)
2230
}
2331

32+
// AlertSourceStatusUpdateInput Specifies the input fields used in the `alertSourceStatusUpdate` mutation
33+
type AlertSourceStatusUpdateInput struct {
34+
AlertSource ExternalResourceIdentifierInput `json:"alertSource" yaml:"alertSource"` // The alert source to be updated (Required)
35+
Status AlertSourceStatusTypeEnum `json:"status" yaml:"status" example:"alert"` // The new status of the alert source (Required)
36+
}
37+
2438
// AliasCreateInput The input for the `aliasCreate` mutation
2539
type AliasCreateInput struct {
2640
Alias string `json:"alias" yaml:"alias" example:"example_value"` // The alias you wish to create (Required)
@@ -792,6 +806,12 @@ type EventIntegrationUpdateInput struct {
792806
Name string `json:"name" yaml:"name" example:"example_value"` // The name of the event integration (Required)
793807
}
794808

809+
// ExternalResourceIdentifierInput Specifies the input fields to locate resouce created via API in OpsLevel
810+
type ExternalResourceIdentifierInput struct {
811+
ExternalId string `json:"externalId" yaml:"externalId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the resource in your system (Required)
812+
Integration IdentifierInput `json:"integration" yaml:"integration"` // The integration identifier (Required)
813+
}
814+
795815
// ExternalUuidMutationInput Specifies the input used for modifying a resource's external UUID
796816
type ExternalUuidMutationInput struct {
797817
ResourceId ID `json:"resourceId" yaml:"resourceId" example:"Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"` // The id of the resource (Required)

0 commit comments

Comments
 (0)