Class: ZabbixApi::Applications

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbixapi/classes/applications.rb

Constant Summary collapse

API_PARAMETERS =
%w(applicationids groupids hostids inherited itemids templated templateids expandData selectHosts selectItems)

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Applications

Returns a new instance of Applications.


6
7
8
# File 'lib/zabbixapi/classes/applications.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#add(data) ⇒ Object


15
16
17
# File 'lib/zabbixapi/classes/applications.rb', line 15

def add(data)
  create(data)
end

#create(data) ⇒ Object


10
11
12
13
# File 'lib/zabbixapi/classes/applications.rb', line 10

def create(data)
  result = @client.api_request(:method => "application.create", :params => [data])
  result.empty? ? nil : result['applicationids'][0].to_i
end

#delete(data) ⇒ Object


19
20
21
22
# File 'lib/zabbixapi/classes/applications.rb', line 19

def delete(data)
  result = @client.api_request(:method => "application.delete", :params => [data])
  result.empty? ? nil : result['applicationids'][0].to_i
end

#destroy(data) ⇒ Object


31
32
33
# File 'lib/zabbixapi/classes/applications.rb', line 31

def destroy(data)
  delete(data)
end

#get_full_data(data) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/zabbixapi/classes/applications.rb', line 35

def get_full_data(data)
  filter_params = {}
  request_data = data.dup # Duplicate data, as we modify it. Otherwise methods that use data after calling get_full_data (such as get_id) will fail.

  request_data.each { |key, value| filter_params[key] = request_data.delete(key) unless API_PARAMETERS.include?(key) }
  @client.api_request(:method => "application.get", :params => request_data.merge({:filter => filter_params, :output => "extend"}))
end

#get_id(data) ⇒ Object


43
44
45
46
47
48
# File 'lib/zabbixapi/classes/applications.rb', line 43

def get_id(data)
  result = get_full_data(data)
  applicationid = nil
  result.each { |app| applicationid = app['applicationid'].to_i if app['name'] == data[:name] }
  applicationid
end

#get_or_create(data) ⇒ Object


24
25
26
27
28
29
# File 'lib/zabbixapi/classes/applications.rb', line 24

def get_or_create(data)
  unless (appid = get_id(data))
    appid = create(data)
  end
  appid
end