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 22 23 24 |
# File 'lib/zabbirc/zabbix/resource/finders.rb', line 5 def find id, * = . = .reverse_merge({ :"#{model_name}ids" => id }) res = api.send(model_name).get ret = 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}" raise NotConnected, e else Connection.up! ret end |
#get(*options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zabbirc/zabbix/resource/finders.rb', line 26 def get * = . res = api.send(model_name).get ret = res.collect do |obj| self.new obj end rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED => e Zabbirc.logger.error "Zabbix::Resource#get: #{e}" raise NotConnected, e else Connection.up! ret end |