Class: ApiReference::Alert

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/alert.rb

Overview

Alerts within Orb monitor spending, usage, or credit balance and trigger webhooks when a threshold is exceeded. Alerts created through the API can be scoped to either customers or subscriptions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(id:, type:, created_at:, enabled:, thresholds:, customer:, plan:, subscription:, metric:, currency:, license_type: SKIP, grouping_keys: SKIP, price_filters: SKIP, threshold_overrides: SKIP, balance_alert_status: SKIP, additional_properties: nil) ⇒ Alert

Returns a new instance of Alert.



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
# File 'lib/api_reference/models/alert.rb', line 132

def initialize(id:, type:, created_at:, enabled:, thresholds:, customer:,
               plan:, subscription:, metric:, currency:, license_type: SKIP,
               grouping_keys: SKIP, price_filters: SKIP,
               threshold_overrides: SKIP, balance_alert_status: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id
  @type = type
  @created_at = created_at
  @enabled = enabled
  @thresholds = thresholds
  @customer = customer
  @plan = plan
  @subscription = subscription
  @metric = metric
  @license_type = license_type unless license_type == SKIP
  @currency = currency
  @grouping_keys = grouping_keys unless grouping_keys == SKIP
  @price_filters = price_filters unless price_filters == SKIP
  @threshold_overrides = threshold_overrides unless threshold_overrides == SKIP
  @balance_alert_status = balance_alert_status unless balance_alert_status == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#balance_alert_statusArray[BalanceAlertStatus]

The current status of the alert. This field is only present for credit balance alerts.

Returns:



81
82
83
# File 'lib/api_reference/models/alert.rb', line 81

def balance_alert_status
  @balance_alert_status
end

#created_atDateTime

The creation time of the resource in Orb.

Returns:

  • (DateTime)


26
27
28
# File 'lib/api_reference/models/alert.rb', line 26

def created_at
  @created_at
end

#currencyString

The name of the currency the credit balance or invoice cost is denominated in.

Returns:

  • (String)


60
61
62
# File 'lib/api_reference/models/alert.rb', line 60

def currency
  @currency
end

#customerCustomerMinified

The customer the alert applies to.

Returns:



39
40
41
# File 'lib/api_reference/models/alert.rb', line 39

def customer
  @customer
end

#enabledTrueClass | FalseClass

Whether the alert is enabled or disabled.

Returns:

  • (TrueClass | FalseClass)


30
31
32
# File 'lib/api_reference/models/alert.rb', line 30

def enabled
  @enabled
end

#grouping_keysArray[String]

The property keys to group cost alerts by. Only present for cost alerts with grouping enabled.

Returns:

  • (Array[String])


65
66
67
# File 'lib/api_reference/models/alert.rb', line 65

def grouping_keys
  @grouping_keys
end

#idString

Also referred to as alert_id in this documentation.

Returns:

  • (String)


18
19
20
# File 'lib/api_reference/models/alert.rb', line 18

def id
  @id
end

#license_typeLicenseTypeMinified

The license type the alert applies to. Only present for license alerts.

Returns:



55
56
57
# File 'lib/api_reference/models/alert.rb', line 55

def license_type
  @license_type
end

#metricBillableMetricMinified

The metric the alert applies to.



51
52
53
# File 'lib/api_reference/models/alert.rb', line 51

def metric
  @metric
end

#planPlanMinifiedWithVersion

The plan the alert applies to.



43
44
45
# File 'lib/api_reference/models/alert.rb', line 43

def plan
  @plan
end

#price_filtersArray[PriceFilter]

Filters scoping which prices are included in grouped cost alert evaluation.

Returns:



70
71
72
# File 'lib/api_reference/models/alert.rb', line 70

def price_filters
  @price_filters
end

#subscriptionSubscriptionMinified

The subscription the alert applies to.



47
48
49
# File 'lib/api_reference/models/alert.rb', line 47

def subscription
  @subscription
end

#threshold_overridesArray[ThresholdOverride]

Per-group threshold overrides. Each override maps a specific combination of grouping_keys values to a replacement threshold list. Only present for grouped cost alerts that have at least one override.

Returns:



76
77
78
# File 'lib/api_reference/models/alert.rb', line 76

def threshold_overrides
  @threshold_overrides
end

#thresholdsArray[Threshold]

The thresholds that define the conditions under which the alert will be triggered.

Returns:



35
36
37
# File 'lib/api_reference/models/alert.rb', line 35

def thresholds
  @thresholds
end

#typeObject

The type of alert. This must be a valid alert type.

Returns:

  • (Object)


22
23
24
# File 'lib/api_reference/models/alert.rb', line 22

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
# File 'lib/api_reference/models/alert.rb', line 159

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  type = hash.key?('type') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:AlertType), hash['type']
  ) : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  enabled = hash.key?('enabled') ? hash['enabled'] : nil
  # Parameter is an array, so we need to iterate through it
  thresholds = nil
  unless hash['thresholds'].nil?
    thresholds = []
    hash['thresholds'].each do |structure|
      thresholds << (Threshold.from_hash(structure) if structure)
    end
  end

  thresholds = nil unless hash.key?('thresholds')
  customer = CustomerMinified.from_hash(hash['customer']) if hash['customer']
  plan = PlanMinifiedWithVersion.from_hash(hash['plan']) if hash['plan']
  subscription = SubscriptionMinified.from_hash(hash['subscription']) if hash['subscription']
  metric = BillableMetricMinified.from_hash(hash['metric']) if hash['metric']
  currency = hash.key?('currency') ? hash['currency'] : nil
  license_type = LicenseTypeMinified.from_hash(hash['license_type']) if hash['license_type']
  grouping_keys = hash.key?('grouping_keys') ? hash['grouping_keys'] : SKIP
  # Parameter is an array, so we need to iterate through it
  price_filters = nil
  unless hash['price_filters'].nil?
    price_filters = []
    hash['price_filters'].each do |structure|
      price_filters << (PriceFilter.from_hash(structure) if structure)
    end
  end

  price_filters = SKIP unless hash.key?('price_filters')
  # Parameter is an array, so we need to iterate through it
  threshold_overrides = nil
  unless hash['threshold_overrides'].nil?
    threshold_overrides = []
    hash['threshold_overrides'].each do |structure|
      threshold_overrides << (ThresholdOverride.from_hash(structure) if structure)
    end
  end

  threshold_overrides = SKIP unless hash.key?('threshold_overrides')
  # Parameter is an array, so we need to iterate through it
  balance_alert_status = nil
  unless hash['balance_alert_status'].nil?
    balance_alert_status = []
    hash['balance_alert_status'].each do |structure|
      balance_alert_status << (BalanceAlertStatus.from_hash(structure) if structure)
    end
  end

  balance_alert_status = SKIP unless hash.key?('balance_alert_status')

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Alert.new(id: id,
            type: type,
            created_at: created_at,
            enabled: enabled,
            thresholds: thresholds,
            customer: customer,
            plan: plan,
            subscription: subscription,
            metric: metric,
            currency: currency,
            license_type: license_type,
            grouping_keys: grouping_keys,
            price_filters: price_filters,
            threshold_overrides: threshold_overrides,
            balance_alert_status: balance_alert_status,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/api_reference/models/alert.rb', line 84

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['type'] = 'type'
  @_hash['created_at'] = 'created_at'
  @_hash['enabled'] = 'enabled'
  @_hash['thresholds'] = 'thresholds'
  @_hash['customer'] = 'customer'
  @_hash['plan'] = 'plan'
  @_hash['subscription'] = 'subscription'
  @_hash['metric'] = 'metric'
  @_hash['license_type'] = 'license_type'
  @_hash['currency'] = 'currency'
  @_hash['grouping_keys'] = 'grouping_keys'
  @_hash['price_filters'] = 'price_filters'
  @_hash['threshold_overrides'] = 'threshold_overrides'
  @_hash['balance_alert_status'] = 'balance_alert_status'
  @_hash
end

.nullablesObject

An array for nullable fields



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/api_reference/models/alert.rb', line 116

def self.nullables
  %w[
    thresholds
    customer
    plan
    subscription
    metric
    license_type
    currency
    grouping_keys
    price_filters
    threshold_overrides
    balance_alert_status
  ]
end

.optionalsObject

An array for optional fields



105
106
107
108
109
110
111
112
113
# File 'lib/api_reference/models/alert.rb', line 105

def self.optionals
  %w[
    license_type
    grouping_keys
    price_filters
    threshold_overrides
    balance_alert_status
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Alert | Hash)

    value against the validation is performed.



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
# File 'lib/api_reference/models/alert.rb', line 251

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:AlertType)
                       .validate(value.type) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.enabled,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.thresholds,
                              ->(val) { Threshold.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.customer,
                              ->(val) { CustomerMinified.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.plan,
                              ->(val) { PlanMinifiedWithVersion.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.subscription,
                              ->(val) { SubscriptionMinified.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.metric,
                              ->(val) { BillableMetricMinified.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.currency,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:AlertType)
                     .validate(value['type']) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['enabled'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['thresholds'],
                            ->(val) { Threshold.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['customer'],
                            ->(val) { CustomerMinified.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['plan'],
                            ->(val) { PlanMinifiedWithVersion.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['subscription'],
                            ->(val) { SubscriptionMinified.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['metric'],
                            ->(val) { BillableMetricMinified.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['currency'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



327
328
329
330
331
332
333
334
335
336
337
# File 'lib/api_reference/models/alert.rb', line 327

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, type: #{@type.inspect}, created_at:"\
  " #{@created_at.inspect}, enabled: #{@enabled.inspect}, thresholds: #{@thresholds.inspect},"\
  " customer: #{@customer.inspect}, plan: #{@plan.inspect}, subscription:"\
  " #{@subscription.inspect}, metric: #{@metric.inspect}, license_type:"\
  " #{@license_type.inspect}, currency: #{@currency.inspect}, grouping_keys:"\
  " #{@grouping_keys.inspect}, price_filters: #{@price_filters.inspect}, threshold_overrides:"\
  " #{@threshold_overrides.inspect}, balance_alert_status: #{@balance_alert_status.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_custom_created_atObject



245
246
247
# File 'lib/api_reference/models/alert.rb', line 245

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_sObject

Provides a human-readable string representation of the object.



316
317
318
319
320
321
322
323
324
# File 'lib/api_reference/models/alert.rb', line 316

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, type: #{@type}, created_at: #{@created_at}, enabled:"\
  " #{@enabled}, thresholds: #{@thresholds}, customer: #{@customer}, plan: #{@plan},"\
  " subscription: #{@subscription}, metric: #{@metric}, license_type: #{@license_type},"\
  " currency: #{@currency}, grouping_keys: #{@grouping_keys}, price_filters:"\
  " #{@price_filters}, threshold_overrides: #{@threshold_overrides}, balance_alert_status:"\
  " #{@balance_alert_status}, additional_properties: #{@additional_properties}>"
end