Module: Zabbirc::Zabbix::Resource::Finders

Included in:
Base
Defined in:
lib/zabbirc/zabbix/resource/finders.rb

Instance Method Summary collapse

Instance Method Details

#find(id, *options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zabbirc/zabbix/resource/finders.rb', line 5

def find id, *options
  options = options.extract_options!
  options = options.reverse_merge({
                                      :"#{model_name}ids" => id
                                  })
  res = api.send(model_name).get options
  if res.size == 0
    nil
  elsif res.size > 1
    raise IDNotUniqueError, "#{model_name.camelize} ID `#{id}` is not unique"
  else
    self.new res.first
  end
rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED => e
  Zabbirc.logger.error "Zabbix::Resource#find: #{e}"
  nil
end

#get(*options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/zabbirc/zabbix/resource/finders.rb', line 23

def get *options
  options = options.extract_options!
  res = api.send(model_name).get options
  res.collect do |obj|
    self.new obj
  end
rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED => e
  Zabbirc.logger.error "Zabbix::Resource#get: #{e}"
  []
end