Class: ZabbixApi::Items
- Inherits:
-
Object
- Object
- ZabbixApi::Items
- Defined in:
- lib/zabbixapi/items.rb
Instance Method Summary collapse
- #add(data) ⇒ Object
- #create(data) ⇒ Object
- #create_or_update(data) ⇒ Object
- #delete(data) ⇒ Object
- #destroy(data) ⇒ Object
- #get_full_data(data) ⇒ Object
- #get_id(data) ⇒ Object
-
#initialize(options = {}) ⇒ Items
constructor
A new instance of Items.
- #merge_params(params) ⇒ Object
- #update(data) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Items
Returns a new instance of Items.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zabbixapi/items.rb', line 4 def initialize( = {}) @client = Client.new() @options = @item_default_options = { :description => nil, :key_ => nil, :hostid => nil, :delay => 60, :history => 60, :status => 0, :type => 7, :snmp_community => '', :snmp_oid => '', :value_type => 3, :data_type => 0, :trapper_hosts => 'localhost', :snmp_port => 161, :units => '', :multiplier => 0, :delta => 0, :snmpv3_securityname => '', :snmpv3_securitylevel => 0, :snmpv3_authpassphrase => '', :snmpv3_privpassphrase => '', :formula => 0, :trends => 365, :logtimefmt => '', :valuemapid => 0, :delay_flex => '', :authtype => 0, :username => '', :password => '', :publickey => '', :privatekey => '', :params => '', :ipmi_sensor => '' } end |
Instance Method Details
#add(data) ⇒ Object
53 54 55 |
# File 'lib/zabbixapi/items.rb', line 53 def add(data) create(data) end |
#create(data) ⇒ Object
48 49 50 51 |
# File 'lib/zabbixapi/items.rb', line 48 def create(data) result = @client.api_request(:method => "item.create", :params => [merge_params(data)] ) result.empty? ? nil : result['itemids'][0].to_i end |
#create_or_update(data) ⇒ Object
68 69 70 71 |
# File 'lib/zabbixapi/items.rb', line 68 def create_or_update(data) itemid = get_id(:description => data[:description], :hostid => data[:hostid]) itemid ? update(data.merge(:itemid => itemid)) : create(data) end |
#delete(data) ⇒ Object
78 79 80 81 |
# File 'lib/zabbixapi/items.rb', line 78 def delete(data) result = @client.api_request(:method => "item.delete", :params => [data]) result.empty? ? nil : result['itemids'][0].to_i end |
#destroy(data) ⇒ Object
83 84 85 |
# File 'lib/zabbixapi/items.rb', line 83 def destroy(data) delete(data) end |
#get_full_data(data) ⇒ Object
57 58 59 |
# File 'lib/zabbixapi/items.rb', line 57 def get_full_data(data) @client.api_request(:method => "item.get", :params => {:filter => data, :output => "extend"}) end |
#get_id(data) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/zabbixapi/items.rb', line 61 def get_id(data) result = get_full_data(data) itemid = nil result.each { |item| itemid = item['itemid'].to_i if item['name'] == data[:name] } itemid end |
#merge_params(params) ⇒ Object
43 44 45 46 |
# File 'lib/zabbixapi/items.rb', line 43 def merge_params(params) result = JSON.generate(@item_default_options).to_s + "," + JSON.generate(params).to_s JSON.parse(result.gsub('},{', ',')) end |
#update(data) ⇒ Object
73 74 75 76 |
# File 'lib/zabbixapi/items.rb', line 73 def update(data) result = @client.api_request(:method => "item.update", :params => data) result.empty? ? nil : result['itemids'][0].to_i end |