Class: Rubix::Item
- Includes:
- Associations::BelongsToHost, Associations::BelongsToTemplate, Associations::HasManyApplications
- Defined in:
- lib/rubix/models/item.rb
Instance Attribute Summary
Attributes inherited from Model
Class Method Summary collapse
- .build(item) ⇒ Object
- .find_params(options = {}) ⇒ Object
- .get_params ⇒ Object
-
.value_code_from_value(value) ⇒ Object
Return the
value_type
‘s numeric code for a Zabbix item’s value type by examining the givenvalue
. -
.value_type_from_value(value) ⇒ Object
Return the
value_type
name (:float, :text, &c.) for a Zabbix item’s value type by examining the givenvalue
.
Instance Method Summary collapse
-
#create_params ⇒ Object
Requests ==.
-
#initialize(properties = {}) ⇒ Item
constructor
A new instance of Item.
- #resource_name ⇒ Object
- #time_series(options = {}) ⇒ Object
Methods included from Associations::HasManyApplications
#application_ids, #application_ids=, #applications, #applications=
Methods included from Associations::BelongsToTemplate
#template, #template=, #template_id, #template_id=
Methods included from Associations::BelongsToHost
#host, #host=, #host_id, #host_id=
Methods inherited from Model
#after_create, all, all_params, all_request, #before_destroy, #before_update, #create, #create_request, #destroy, #destroy_params, #destroy_request, each, find, find_or_create, find_request, #id_field, id_field, list, #new_record?, properties, request, #request, resource_name, #save, #to_hash, #update, #update_params, #update_request, #validate, web_request, zabbix_attr, zabbix_define, zabbix_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Item
Returns a new instance of Item.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubix/models/item.rb', line 91 def initialize properties={} super(properties) self.host = properties[:host] self.host_id = properties[:host_id] self.template = properties[:template] self.template_id = properties[:template_id] self.applications = properties[:applications] self.application_ids = properties[:application_ids] end |
Class Method Details
.build(item) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rubix/models/item.rb', line 157 def self.build item new({ :id => item[id_field].to_i, :host_id => item['hostid'].to_i, :description => item['description'], :type => TYPE_NAMES[item['type'].to_i], :value_type => VALUE_NAMES[item['value_type'].to_i], :data_type => DATA_NAMES[item['data_type'].to_i], :history => item['history'].to_i, :trends => item['trends'].to_i, :status => STATUS_NAMES[item['status'].to_i], :application_ids => (item['applications'] || []).map { |app| app['applicationid'].to_i }, :key => item['key_'], :units => item['units'], :frequency => item['delay'].to_i, :multiply_by => ((item['multiplier'].to_i == 1 && item['formula'].to_f != 0.0) ? item['formula'].to_f : nil) }) end |
.find_params(options = {}) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/rubix/models/item.rb', line 145 def self.find_params ={} super().merge({ :filter => { :key_ => [:key], :id => [:id] } }.tap do |o| o[:hostids] = [[:host_id]] if [:host_id] end ) end |
.get_params ⇒ Object
141 142 143 |
# File 'lib/rubix/models/item.rb', line 141 def self.get_params super().merge(:select_applications => :refer) end |
.value_code_from_value(value) ⇒ Object
Return the value_type
‘s numeric code for a Zabbix item’s value type by examining the given value
.
75 76 77 |
# File 'lib/rubix/models/item.rb', line 75 def self.value_code_from_value value self::VALUE_CODES[value_type_from_value(value)] end |
.value_type_from_value(value) ⇒ Object
Return the value_type
name (:float, :text, &c.) for a Zabbix item’s value type by examining the given value
.
64 65 66 67 68 69 70 71 |
# File 'lib/rubix/models/item.rb', line 64 def self.value_type_from_value value case when value =~ /\d+/ then :unsigned_int when value =~ /-?[\d\.]+/ then :float when value.include?("\n") then :text else :character end end |
Instance Method Details
#create_params ⇒ Object
Requests ==
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rubix/models/item.rb', line 119 def create_params { :hostid => host_id, :description => (description || 'Unknown'), :type => self.class::TYPE_CODES[type], :key_ => key, :value_type => self.class::VALUE_CODES[value_type], }.tap do |p| p[:applications] = application_ids if application_ids p[:units] = units if units p[:data_type] = self.class::DATA_CODES[data_type] if data_type p[:history] = history.to_i if history p[:trends] = trends.to_i if trends p[:status] = self.class::STATUS_CODES[status] if status p[:delay] = frequency if frequency if multiply_by && multiply_by.to_f != 0.0 p[:multiplier] = 1 p[:formula] = multiply_by.to_f end end end |
#resource_name ⇒ Object
103 104 105 |
# File 'lib/rubix/models/item.rb', line 103 def resource_name "#{self.class.resource_name} #{self.key || self.id}" end |
#time_series(options = {}) ⇒ Object
176 177 178 |
# File 'lib/rubix/models/item.rb', line 176 def time_series ={} TimeSeries.find(.merge(:item_id => self.id, :item => self)) end |