Class: ZabbixRubyClient::Runner

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

Instance Method Summary collapse

Constructor Details

#initialize(config, tasks) ⇒ Runner



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zabbix-ruby-client/runner.rb', line 10

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

#collectObject



28
29
30
31
32
# File 'lib/zabbix-ruby-client/runner.rb', line 28

def collect
  @tasks.each do |plugin|
    @data.run_plugin(plugin['name'], plugin['args'])
  end
end

#showObject



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

def show
  @data.merge.each do |line|
    puts line
  end
end

#uploadObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/zabbix-ruby-client/runner.rb', line 40

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)
    ZabbixRubyClient::Log.error "Sending failed."
    ZabbixRubyClient::Log.error e.message
  end
end