Class: ApiReference::ThresholdOverride

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

Overview

A per-group threshold override on a grouped cost alert. An empty thresholds list means the group is silenced (never fires). A non-empty list fully replaces the default thresholds for that group.

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(group_values:, thresholds:, additional_properties: nil) ⇒ ThresholdOverride

Returns a new instance of ThresholdOverride.



42
43
44
45
46
47
48
49
# File 'lib/api_reference/models/threshold_override.rb', line 42

def initialize(group_values:, thresholds:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @group_values = group_values
  @thresholds = thresholds
  @additional_properties = additional_properties
end

Instance Attribute Details

#group_valuesArray[String]

The values of the grouping keys that identify this group. The list length matches the alert's grouping_keys.

Returns:

  • (Array[String])


17
18
19
# File 'lib/api_reference/models/threshold_override.rb', line 17

def group_values
  @group_values
end

#thresholdsArray[Threshold]

The thresholds applied to this group. An empty list means the group is silenced.

Returns:



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

def thresholds
  @thresholds
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  group_values = hash.key?('group_values') ? hash['group_values'] : 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')

  # 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.
  ThresholdOverride.new(group_values: group_values,
                        thresholds: thresholds,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
# File 'lib/api_reference/models/threshold_override.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['group_values'] = 'group_values'
  @_hash['thresholds'] = 'thresholds'
  @_hash
end

.nullablesObject

An array for nullable fields



38
39
40
# File 'lib/api_reference/models/threshold_override.rb', line 38

def self.nullables
  []
end

.optionalsObject

An array for optional fields



33
34
35
# File 'lib/api_reference/models/threshold_override.rb', line 33

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.group_values,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.thresholds,
                              ->(val) { Threshold.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['group_values'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['thresholds'],
                            ->(val) { Threshold.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



115
116
117
118
119
# File 'lib/api_reference/models/threshold_override.rb', line 115

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} group_values: #{@group_values.inspect}, thresholds: #{@thresholds.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



108
109
110
111
112
# File 'lib/api_reference/models/threshold_override.rb', line 108

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} group_values: #{@group_values}, thresholds: #{@thresholds},"\
  " additional_properties: #{@additional_properties}>"
end