Class: Rubix::Item
- Defined in:
- lib/rubix/models/item.rb
Constant Summary collapse
- TRAPPER_TYPE =
The numeric code for a Zabbix item of type ‘Zabbix trapper’. The item must have this type in order for the Zabbix server to listen and accept data submitted by
zabbix_sender
. 2.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 =
{ 0 => :float, # Numeric (float) 1 => :character, # Character 2 => :log_line, # Log 3 => :unsigned_int, # Numeric (unsigned) 4 => :text # Text }.freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#key ⇒ Object
Returns the value of attribute key.
-
#value_type ⇒ Object
Returns the value of attribute value_type.
Attributes inherited from Model
Class Method Summary collapse
- .build(item) ⇒ Object
- .find_request(options = {}) ⇒ Object
- .id_field ⇒ 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_request ⇒ Object
- #destroy_request ⇒ Object
-
#initialize(properties = {}) ⇒ Item
constructor
A new instance of Item.
-
#params ⇒ Object
CRUD ==.
- #update_request ⇒ Object
Methods included from Associations::HasManyApplications
#application_ids, #application_ids=, #applications, #applications=
Methods included from Associations::BelongsToHost
#host, #host=, #host_id, #host_id=
Methods inherited from Model
#before_update, #create, #destroy, find, find_or_create, #new_record?, #request, request, #resource_name, resource_name, #save, #update, #validate
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Item
Returns a new instance of Item.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rubix/models/item.rb', line 53 def initialize properties={} super(properties) @key = properties[:key] @description = properties[:description] self.value_type = properties[:value_type] self.host = properties[:host] self.host_id = properties[:host_id] self.applications = properties[:applications] self.application_ids = properties[:application_ids] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
50 51 52 |
# File 'lib/rubix/models/item.rb', line 50 def description @description end |
#key ⇒ Object
Returns the value of attribute key.
50 51 52 |
# File 'lib/rubix/models/item.rb', line 50 def key @key end |
#value_type ⇒ Object
Returns the value of attribute value_type.
51 52 53 |
# File 'lib/rubix/models/item.rb', line 51 def value_type @value_type end |
Class Method Details
.build(item) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubix/models/item.rb', line 70 def self.build item new({ :id => item['itemid'].to_i, :host_id => item['hostid'].to_i, :description => item['description'], :value_type => item['value_type'] ? self::VALUE_NAMES[item['value_type'].to_i] : :character, :application_ids => (item['applications'] || []).map { |app| app['applicationid'].to_i }, :key => item['key_'] }) end |
.find_request(options = {}) ⇒ Object
66 67 68 |
# File 'lib/rubix/models/item.rb', line 66 def self.find_request ={} request('item.get', 'hostids' => [[:host_id]], 'filter' => {'key_' => [:key], 'id' => [:id]}, "select_applications" => "refer", "output" => "extend") end |
.id_field ⇒ Object
81 82 83 |
# File 'lib/rubix/models/item.rb', line 81 def self.id_field 'itemid' 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
.
46 47 48 |
# File 'lib/rubix/models/item.rb', line 46 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
.
35 36 37 38 39 40 41 42 |
# File 'lib/rubix/models/item.rb', line 35 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_request ⇒ Object
116 117 118 |
# File 'lib/rubix/models/item.rb', line 116 def create_request request('item.create', params) end |
#destroy_request ⇒ Object
124 125 126 |
# File 'lib/rubix/models/item.rb', line 124 def destroy_request request('item.delete', [id]) end |
#params ⇒ Object
CRUD ==
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubix/models/item.rb', line 104 def params { :hostid => host_id, :description => (description || 'Unknown'), :type => self.class::TRAPPER_TYPE, :key_ => key, :value_type => self.class::VALUE_CODES[value_type], }.tap do |p| p[:applications] = application_ids if application_ids end end |
#update_request ⇒ Object
120 121 122 |
# File 'lib/rubix/models/item.rb', line 120 def update_request request('item.update', params.merge('itemid' => id)) end |