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



33
34
35
36
37
38
39
# File 'lib/zabbix-ruby-client/data.rb', line 33

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
29
30
31
# File 'lib/zabbix-ruby-client/data.rb', line 13

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