lib/zabbix-ruby-client/runner.rb in zabbix-ruby-client-0.0.19 vs lib/zabbix-ruby-client/runner.rb in zabbix-ruby-client-0.0.20
- old
+ new
@@ -19,12 +19,14 @@
)
@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.set_logger(File.join(@logsdir, 'zrc.log'), @config['loglevel'])
ZabbixRubyClient::Log.debug @config.inspect
+ zabbix_sender_version = `zabbix_sender -V | head -1`.split(/\s/)[2]
+ @is_22 = /v2\.2\./.match zabbix_sender_version
end
def collect
@tasks.each do |plugin|
@data.run_plugin(plugin['name'], plugin['args'])
@@ -37,17 +39,40 @@
end
end
def upload
file = @store.record(@data.merge)
+ command = "#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}"
+ ZabbixRubyClient::Log.debug command
begin
- res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}`
- if $?.to_i != 0
- @store.keepdata(file)
+ res = `#{command}`
+ if @is_22
+ case $?.to_i
+ when 0
+ ZabbixRubyClient::Log.debug "zabbix-sender: Data Sent"
+ when 1
+ @store.keepdata(file)
+ ZabbixRubyClient::Log.error "zabbix-sender: Sending failed"
+ ZabbixRubyClient::Log.error res
+ when 512
+ ZabbixRubyClient::Log.warn "zabbix-sender: Some values failed"
+ ZabbixRubyClient::Log.warn res
+ else
+ ZabbixRubyClient::Log.error "zabbix-sender: Something failed. #{$i}. code #{$?.to_i} was returned"
+ ZabbixRubyClient::Log.error res
+ end
+ else
+ if $?.to_i != 0
+ @store.keepdata(file)
+ ZabbixRubyClient::Log.error "zabbix-sender: Sending failed"
+ ZabbixRubyClient::Log.error res
+ else
+ ZabbixRubyClient::Log.debug "zabbix-sender: Data Sent"
+ end
end
rescue Exception => e
@store.keepdata(file)
- ZabbixRubyClient::Log.error "Sending failed."
+ ZabbixRubyClient::Log.error "zabbix-sender: broken."
ZabbixRubyClient::Log.error e.message
end
end
private