Sha256: 46634935858aad584ec026a7490be97ad8475b3bf9820e56ca66e5f93190284b
Contents?: true
Size: 1.07 KB
Versions: 7
Compression:
Stored size: 1.07 KB
Contents
require "zabbix-ruby-client/logger" require "zabbix-ruby-client/plugins" module ZabbixRubyClient class Data def initialize(host) @discover = {} @items = [] @host = host end 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 end end end def merge time = Time.now.to_i @discover.reduce([]) do |a,(k,v)| a << "#{@host} #{k} #{time} { \"data\": [ #{v.join(', ')} ] }" a end + @items end end end
Version data entries
7 entries across 7 versions & 1 rubygems