lib/zabbixapi/items.rb in zabbixapi-0.5.0b3 vs lib/zabbixapi/items.rb in zabbixapi-0.5.0b4
- old
+ new
@@ -1,16 +1,8 @@
class ZabbixApi
- class Items < Basic
+ class Items
- def api_method_name
- "item"
- end
-
- def api_identify
- "description"
- end
-
def initialize(client)
@client = client
@item_default_options = {
:description => nil,
:key_ => nil,
@@ -53,17 +45,43 @@
end
def create(data)
result = @client.api_request(:method => "item.create", :params => [merge_params(data)] )
result.empty? ? nil : result['itemids'][0].to_i
- end
+ end
+ def add(data)
+ create(data)
+ end
+
def get_full_data(data)
- get_full_data_filter(data)
+ @client.api_request(:method => "item.get", :params => {:filter => data, :output => "extend"})
end
+ 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
+
+ def create_or_update(data)
+ itemid = get_id(:description => data[:description], :hostid => data[:hostid])
+ itemid ? update(data.merge(:itemid => itemid)) : create(data)
+ end
+
+ def update(data)
+ result = @client.api_request(:method => "item.update", :params => data)
+ result.empty? ? nil : result['itemids'][0].to_i
+ end
+
def delete(data)
- delete_array(data)
+ result = @client.api_request(:method => "item.delete", :params => [data])
+ result.empty? ? nil : result['itemids'][0].to_i
+ end
+
+ def destroy(data)
+ delete(data)
end
end
end