Class: ZabbixRubyClient::Runner
- Inherits:
-
Object
- Object
- ZabbixRubyClient::Runner
- Defined in:
- lib/zabbix-ruby-client/runner.rb
Instance Method Summary collapse
- #collect ⇒ Object
-
#initialize(config, tasks) ⇒ Runner
constructor
A new instance of Runner.
- #show ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(config, tasks) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zabbix-ruby-client/runner.rb', line 5 def initialize(config, tasks) @config = config @tasks = tasks @store = ZabbixRubyClient::Store.new( @config['datadir'], @config['zabbix']['host'], @config['taskfile'], @config['keepdata'] ) @data = ZabbixRubyClient::Data.new(@config['host']) @logsdir = makedir(@config['logsdir'], 'logs') ZabbixRubyClient::Plugins.scan_dirs([ PLUGINDIR ] + @config['plugindirs']) ZabbixRubyClient::Log.set_logger(File.join(@logsdir, 'zrc.log'), 'info') ZabbixRubyClient::Log.debug @config.inspect end |
Instance Method Details
#collect ⇒ Object
23 24 25 26 27 |
# File 'lib/zabbix-ruby-client/runner.rb', line 23 def collect @tasks.each do |plugin| @data.run_plugin(plugin['name'], plugin['args']) end end |
#show ⇒ Object
29 30 31 32 33 |
# File 'lib/zabbix-ruby-client/runner.rb', line 29 def show @data.merge.each do |line| puts line end end |
#upload ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zabbix-ruby-client/runner.rb', line 35 def upload file = @store.record(@data.merge) begin res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}` if $?.to_i != 0 @store.keepdata(file) end rescue Exception => e @store.keepdata(file) logger.error "Sending failed." logger.error e. end end |