13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/opstat-master/parsers.rb', line 13
def parse_and_save(params)
plugin = params[:plugin]
host = params[:host]
data = params[:plugin_data]['data']
time = Time.parse(params[:plugin_data]['timestamp'])
oplogger.info "Saving parsed data collected on #{time} from #{host.id}(plugin:#{plugin[:type]} #{host[:hostname]}) "
begin
reports = @parsers[plugin[:type]].parse_data(data: data, time: time)
rescue Exception => e
oplogger.error "current params #{params}"
raise e
end
if reports.nil? or reports.empty?
oplogger.warn "no report data parsed - empty report for #{plugin.type}?"
return
end
reports.each do |report|
default_tags = { :host_id => host.id, :plugin_id => plugin.id, :hostname => host[:hostname] }
report_data = report.select{|k,v| not k.to_s.starts_with?('OPSTAT_TAG_')}
report_tags = report.select{|k,v| k.to_s.starts_with?('OPSTAT_TAG_')}
report_tags ||= {}
measurement_tags = report_tags.merge(default_tags)
measurement = { :values => report_data, :timestamp => time.to_i, :tags => measurement_tags, :name => plugin.type }
Opstat::DB::Influx.instance.write_point(plugin.type, measurement)
end
end
|