Class: ZabbixRubyClient::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbix-ruby-client/data.rb

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Data

Returns a new instance of Data.



7
8
9
10
11
# File 'lib/zabbix-ruby-client/data.rb', line 7

def initialize(host)
  @discover = {}
  @items = []
  @host = host
end

Instance Method Details

#mergeObject



30
31
32
33
34
35
36
# File 'lib/zabbix-ruby-client/data.rb', line 30

def merge
  time = Time.now.to_i
  @discover.reduce([]) do |a,(k,v)|
    a << "#{@host} #{k} #{time} { \"data\": [ #{v.join(', ')} ] }"
    a
  end + @items
end

#run_plugin(plugin, args = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zabbix-ruby-client/data.rb', line 13

def run_plugin(plugin, args = nil)
  Plugins.load(plugin) || logger.error( "Plugin #{plugin} not found.")
  if Plugins.loaded[plugin]
    begin
      @items += Plugins.loaded[plugin].send(:collect, @host, *args)
      if Plugins.loaded[plugin].respond_to?(:discover)
        key, value = Plugins.loaded[plugin].send(:discover, *args)
        @discover[key] ||= []
        @discover[key] << [ value ]
      end
    rescue Exception => e
      Log.fatal "Oops"
      Log.fatal e.message
    end
  end
end