Class: Rubix::Item
- Includes:
- Associations::BelongsToHost, Associations::BelongsToTemplate, Associations::HasManyApplications
- Defined in:
- lib/rubix/models/item.rb
Constant Summary collapse
- TYPE_CODES =
The numeric codes for the various item types.
Items without a type will be set to ‘zabbix’.
{ :zabbix => 0, :snmpv1 => 1, :trapper => 2, :simple => 3, :snmpv2c => 4, :internal => 5, :snmpv3 => 6, :active => 7, :aggregate => 8, :httptest => 9, :external => 10, :db_monitor => 11, :ipmi => 12, :ssh => 13, :telnet => 14, :calculated => 15 }.freeze
- TYPE_NAMES =
TYPE_CODES.invert.freeze
- VALUE_CODES =
The numeric codes for the value types of a Zabbix item.
This Hash is used by ZabbixPipe#value_code_from_value to dynamically set the type of a value when creating a new Zabbix item.
{ :float => 0, # Numeric (float) :character => 1, # Character :log_line => 2, # Log :unsigned_int => 3, # Numeric (unsigned) :text => 4 # Text }.freeze
- VALUE_NAMES =
Text
VALUE_CODES.invert.freeze
- DATA_CODES =
The numeric codes for the data types of a Zabbix item.
The default will be
:decimal
{ :decimal => 0, :octal => 1, :hexadecimal => 2 }.freeze
- DATA_NAMES =
DATA_CODES.invert.freeze
- STATUS_CODES =
The numeric codes for the status of a Zabbix item.
The default will be
:active
{ :active => 0, :disabled => 1, :not_supported => 3 }.freeze
- STATUS_NAMES =
STATUS_CODES.invert.freeze
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_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Item
Returns a new instance of Item.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rubix/models/item.rb', line 95 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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rubix/models/item.rb', line 161 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
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rubix/models/item.rb', line 149 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
145 146 147 |
# File 'lib/rubix/models/item.rb', line 145 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
.
79 80 81 |
# File 'lib/rubix/models/item.rb', line 79 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
.
68 69 70 71 72 73 74 75 |
# File 'lib/rubix/models/item.rb', line 68 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 ==
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rubix/models/item.rb', line 123 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
107 108 109 |
# File 'lib/rubix/models/item.rb', line 107 def resource_name "#{self.class.resource_name} #{self.key || self.id}" end |
#time_series(options = {}) ⇒ Object
180 181 182 |
# File 'lib/rubix/models/item.rb', line 180 def time_series ={} TimeSeries.find(.merge(:item_id => self.id, :item => self)) end |