-
Notifications
You must be signed in to change notification settings - Fork 1
/
customeralert.go
383 lines (329 loc) · 15.6 KB
/
customeralert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package metronome
import (
"context"
"net/http"
"net/url"
"time"
"github.com/Metronome-Industries/metronome-go/internal/apijson"
"github.com/Metronome-Industries/metronome-go/internal/apiquery"
"github.com/Metronome-Industries/metronome-go/internal/param"
"github.com/Metronome-Industries/metronome-go/internal/requestconfig"
"github.com/Metronome-Industries/metronome-go/option"
"github.com/Metronome-Industries/metronome-go/shared"
)
// CustomerAlertService contains methods and other services that help with
// interacting with the metronome API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewCustomerAlertService] method instead.
type CustomerAlertService struct {
Options []option.RequestOption
}
// NewCustomerAlertService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewCustomerAlertService(opts ...option.RequestOption) (r *CustomerAlertService) {
r = &CustomerAlertService{}
r.Options = opts
return
}
// Get the customer alert status and alert information for the specified customer
// and alert
func (r *CustomerAlertService) Get(ctx context.Context, body CustomerAlertGetParams, opts ...option.RequestOption) (res *CustomerAlertGetResponse, err error) {
opts = append(r.Options[:], opts...)
path := "customer-alerts/get"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Fetch all customer alert statuses and alert information for a customer
func (r *CustomerAlertService) List(ctx context.Context, params CustomerAlertListParams, opts ...option.RequestOption) (res *CustomerAlertListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "customer-alerts/list"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
}
// Reset state for an alert by customer id and force re-evaluation
func (r *CustomerAlertService) Reset(ctx context.Context, body CustomerAlertResetParams, opts ...option.RequestOption) (err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
path := "customer-alerts/reset"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, nil, opts...)
return
}
type CustomerAlert struct {
Alert CustomerAlertAlert `json:"alert,required"`
// The status of the customer alert. If the alert is archived, null will be
// returned.
CustomerStatus CustomerAlertCustomerStatus `json:"customer_status,required,nullable"`
// If present, indicates the reason the alert was triggered.
TriggeredBy string `json:"triggered_by,nullable"`
JSON customerAlertJSON `json:"-"`
}
// customerAlertJSON contains the JSON metadata for the struct [CustomerAlert]
type customerAlertJSON struct {
Alert apijson.Field
CustomerStatus apijson.Field
TriggeredBy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlert) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertJSON) RawJSON() string {
return r.raw
}
type CustomerAlertAlert struct {
// the Metronome ID of the alert
ID string `json:"id,required"`
// Name of the alert
Name string `json:"name,required"`
// Status of the alert
Status CustomerAlertAlertStatus `json:"status,required"`
// Threshold value of the alert policy
Threshold float64 `json:"threshold,required"`
// Type of the alert
Type CustomerAlertAlertType `json:"type,required"`
// Timestamp for when the alert was last updated
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
// An array of strings, representing a way to filter the credit grant this alert
// applies to, by looking at the credit_grant_type field on the credit grant. This
// field is only defined for CreditPercentage and CreditBalance alerts
CreditGrantTypeFilters []string `json:"credit_grant_type_filters"`
CreditType shared.CreditType `json:"credit_type,nullable"`
// A list of custom field filters for alert types that support advanced filtering
CustomFieldFilters []CustomerAlertAlertCustomFieldFilter `json:"custom_field_filters"`
// Scopes alert evaluation to a specific presentation group key on individual line
// items. Only present for spend alerts.
GroupKeyFilter CustomerAlertAlertGroupKeyFilter `json:"group_key_filter"`
// Only supported for invoice_total_reached alerts. A list of invoice types to
// evaluate.
InvoiceTypesFilter []string `json:"invoice_types_filter"`
// Prevents the creation of duplicates. If a request to create a record is made
// with a previously used uniqueness key, a new record will not be created and the
// request will fail with a 409 error.
UniquenessKey string `json:"uniqueness_key"`
JSON customerAlertAlertJSON `json:"-"`
}
// customerAlertAlertJSON contains the JSON metadata for the struct
// [CustomerAlertAlert]
type customerAlertAlertJSON struct {
ID apijson.Field
Name apijson.Field
Status apijson.Field
Threshold apijson.Field
Type apijson.Field
UpdatedAt apijson.Field
CreditGrantTypeFilters apijson.Field
CreditType apijson.Field
CustomFieldFilters apijson.Field
GroupKeyFilter apijson.Field
InvoiceTypesFilter apijson.Field
UniquenessKey apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlertAlert) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertAlertJSON) RawJSON() string {
return r.raw
}
// Status of the alert
type CustomerAlertAlertStatus string
const (
CustomerAlertAlertStatusEnabled CustomerAlertAlertStatus = "enabled"
CustomerAlertAlertStatusArchived CustomerAlertAlertStatus = "archived"
CustomerAlertAlertStatusDisabled CustomerAlertAlertStatus = "disabled"
)
func (r CustomerAlertAlertStatus) IsKnown() bool {
switch r {
case CustomerAlertAlertStatusEnabled, CustomerAlertAlertStatusArchived, CustomerAlertAlertStatusDisabled:
return true
}
return false
}
// Type of the alert
type CustomerAlertAlertType string
const (
CustomerAlertAlertTypeLowCreditBalanceReached CustomerAlertAlertType = "low_credit_balance_reached"
CustomerAlertAlertTypeSpendThresholdReached CustomerAlertAlertType = "spend_threshold_reached"
CustomerAlertAlertTypeMonthlyInvoiceTotalSpendThresholdReached CustomerAlertAlertType = "monthly_invoice_total_spend_threshold_reached"
CustomerAlertAlertTypeLowRemainingDaysInPlanReached CustomerAlertAlertType = "low_remaining_days_in_plan_reached"
CustomerAlertAlertTypeLowRemainingCreditPercentageReached CustomerAlertAlertType = "low_remaining_credit_percentage_reached"
CustomerAlertAlertTypeUsageThresholdReached CustomerAlertAlertType = "usage_threshold_reached"
CustomerAlertAlertTypeLowRemainingDaysForCommitSegmentReached CustomerAlertAlertType = "low_remaining_days_for_commit_segment_reached"
CustomerAlertAlertTypeLowRemainingCommitBalanceReached CustomerAlertAlertType = "low_remaining_commit_balance_reached"
CustomerAlertAlertTypeLowRemainingCommitPercentageReached CustomerAlertAlertType = "low_remaining_commit_percentage_reached"
CustomerAlertAlertTypeLowRemainingDaysForContractCreditSegmentReached CustomerAlertAlertType = "low_remaining_days_for_contract_credit_segment_reached"
CustomerAlertAlertTypeLowRemainingContractCreditBalanceReached CustomerAlertAlertType = "low_remaining_contract_credit_balance_reached"
CustomerAlertAlertTypeLowRemainingContractCreditPercentageReached CustomerAlertAlertType = "low_remaining_contract_credit_percentage_reached"
CustomerAlertAlertTypeLowRemainingContractCreditAndCommitBalanceReached CustomerAlertAlertType = "low_remaining_contract_credit_and_commit_balance_reached"
CustomerAlertAlertTypeInvoiceTotalReached CustomerAlertAlertType = "invoice_total_reached"
)
func (r CustomerAlertAlertType) IsKnown() bool {
switch r {
case CustomerAlertAlertTypeLowCreditBalanceReached, CustomerAlertAlertTypeSpendThresholdReached, CustomerAlertAlertTypeMonthlyInvoiceTotalSpendThresholdReached, CustomerAlertAlertTypeLowRemainingDaysInPlanReached, CustomerAlertAlertTypeLowRemainingCreditPercentageReached, CustomerAlertAlertTypeUsageThresholdReached, CustomerAlertAlertTypeLowRemainingDaysForCommitSegmentReached, CustomerAlertAlertTypeLowRemainingCommitBalanceReached, CustomerAlertAlertTypeLowRemainingCommitPercentageReached, CustomerAlertAlertTypeLowRemainingDaysForContractCreditSegmentReached, CustomerAlertAlertTypeLowRemainingContractCreditBalanceReached, CustomerAlertAlertTypeLowRemainingContractCreditPercentageReached, CustomerAlertAlertTypeLowRemainingContractCreditAndCommitBalanceReached, CustomerAlertAlertTypeInvoiceTotalReached:
return true
}
return false
}
type CustomerAlertAlertCustomFieldFilter struct {
Entity CustomerAlertAlertCustomFieldFiltersEntity `json:"entity,required"`
Key string `json:"key,required"`
Value string `json:"value,required"`
JSON customerAlertAlertCustomFieldFilterJSON `json:"-"`
}
// customerAlertAlertCustomFieldFilterJSON contains the JSON metadata for the
// struct [CustomerAlertAlertCustomFieldFilter]
type customerAlertAlertCustomFieldFilterJSON struct {
Entity apijson.Field
Key apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlertAlertCustomFieldFilter) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertAlertCustomFieldFilterJSON) RawJSON() string {
return r.raw
}
type CustomerAlertAlertCustomFieldFiltersEntity string
const (
CustomerAlertAlertCustomFieldFiltersEntityContract CustomerAlertAlertCustomFieldFiltersEntity = "Contract"
CustomerAlertAlertCustomFieldFiltersEntityCommit CustomerAlertAlertCustomFieldFiltersEntity = "Commit"
CustomerAlertAlertCustomFieldFiltersEntityContractCredit CustomerAlertAlertCustomFieldFiltersEntity = "ContractCredit"
)
func (r CustomerAlertAlertCustomFieldFiltersEntity) IsKnown() bool {
switch r {
case CustomerAlertAlertCustomFieldFiltersEntityContract, CustomerAlertAlertCustomFieldFiltersEntityCommit, CustomerAlertAlertCustomFieldFiltersEntityContractCredit:
return true
}
return false
}
// Scopes alert evaluation to a specific presentation group key on individual line
// items. Only present for spend alerts.
type CustomerAlertAlertGroupKeyFilter struct {
Key string `json:"key,required"`
Value string `json:"value,required"`
JSON customerAlertAlertGroupKeyFilterJSON `json:"-"`
}
// customerAlertAlertGroupKeyFilterJSON contains the JSON metadata for the struct
// [CustomerAlertAlertGroupKeyFilter]
type customerAlertAlertGroupKeyFilterJSON struct {
Key apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlertAlertGroupKeyFilter) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertAlertGroupKeyFilterJSON) RawJSON() string {
return r.raw
}
// The status of the customer alert. If the alert is archived, null will be
// returned.
type CustomerAlertCustomerStatus string
const (
CustomerAlertCustomerStatusOk CustomerAlertCustomerStatus = "ok"
CustomerAlertCustomerStatusInAlarm CustomerAlertCustomerStatus = "in_alarm"
CustomerAlertCustomerStatusEvaluating CustomerAlertCustomerStatus = "evaluating"
)
func (r CustomerAlertCustomerStatus) IsKnown() bool {
switch r {
case CustomerAlertCustomerStatusOk, CustomerAlertCustomerStatusInAlarm, CustomerAlertCustomerStatusEvaluating:
return true
}
return false
}
type CustomerAlertGetResponse struct {
Data CustomerAlert `json:"data,required"`
JSON customerAlertGetResponseJSON `json:"-"`
}
// customerAlertGetResponseJSON contains the JSON metadata for the struct
// [CustomerAlertGetResponse]
type customerAlertGetResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlertGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertGetResponseJSON) RawJSON() string {
return r.raw
}
type CustomerAlertListResponse struct {
Data []CustomerAlert `json:"data,required"`
NextPage string `json:"next_page,required,nullable"`
JSON customerAlertListResponseJSON `json:"-"`
}
// customerAlertListResponseJSON contains the JSON metadata for the struct
// [CustomerAlertListResponse]
type customerAlertListResponseJSON struct {
Data apijson.Field
NextPage apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CustomerAlertListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r customerAlertListResponseJSON) RawJSON() string {
return r.raw
}
type CustomerAlertGetParams struct {
// The Metronome ID of the alert
AlertID param.Field[string] `json:"alert_id,required" format:"uuid"`
// The Metronome ID of the customer
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
}
func (r CustomerAlertGetParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type CustomerAlertListParams struct {
// The Metronome ID of the customer
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
// Cursor that indicates where the next page of results should start.
NextPage param.Field[string] `query:"next_page"`
// Optionally filter by alert status. If absent, only enabled alerts will be
// returned.
AlertStatuses param.Field[[]CustomerAlertListParamsAlertStatus] `json:"alert_statuses"`
}
func (r CustomerAlertListParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// URLQuery serializes [CustomerAlertListParams]'s query parameters as
// `url.Values`.
func (r CustomerAlertListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type CustomerAlertListParamsAlertStatus string
const (
CustomerAlertListParamsAlertStatusEnabled CustomerAlertListParamsAlertStatus = "ENABLED"
CustomerAlertListParamsAlertStatusDisabled CustomerAlertListParamsAlertStatus = "DISABLED"
CustomerAlertListParamsAlertStatusArchived CustomerAlertListParamsAlertStatus = "ARCHIVED"
)
func (r CustomerAlertListParamsAlertStatus) IsKnown() bool {
switch r {
case CustomerAlertListParamsAlertStatusEnabled, CustomerAlertListParamsAlertStatusDisabled, CustomerAlertListParamsAlertStatusArchived:
return true
}
return false
}
type CustomerAlertResetParams struct {
// The Metronome ID of the alert
AlertID param.Field[string] `json:"alert_id,required" format:"uuid"`
// The Metronome ID of the customer
CustomerID param.Field[string] `json:"customer_id,required" format:"uuid"`
}
func (r CustomerAlertResetParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}