lib/fluent/plugin/out_grassland.rb in fluent-plugin-grassland-0.0.4 vs lib/fluent/plugin/out_grassland.rb in fluent-plugin-grassland-0.0.5

- old
+ new

@@ -2,11 +2,11 @@ class GrasslandOutput < Fluent::BufferedOutput Fluent::Plugin.register_output('grassland', self) attr_accessor :random attr_accessor :kinesis - attr_accessor :stream_name, :access_key_id, :secret_access_key, :region, :sessionToken, :partitionKeys + attr_accessor :id, :stream_name, :access_key_id, :secret_access_key, :region, :sessionToken, :partitionKeys def initialize super require 'aws-sdk' require 'base64' @@ -16,11 +16,11 @@ require 'uri' @random = Random.new end config_param :apiuri, :string, :default => 'https://grassland.biz/credentials' - config_param :id, :string, :default => 'nil' + # config_param :id, :string, :default => 'nil' config_param :key, :string, :default => 'nil' config_param :debug, :bool, :default => false config_param :resetCredentialTimer, :integer, :default => 86400 # config_param :resetCredentialTimer, :integer, :default => 20 @@ -70,10 +70,11 @@ end end def setCredential() credential = get_json("#{@apiuri}?key=#{@key}") + @id = credential['id'] @stream_name = credential['streamName'] @access_key_id = credential['accessKeyId'] @secret_access_key = credential['secretAccessKey'] @region = credential['region'] @sessionToken = credential['SessionToken'] @@ -107,20 +108,23 @@ end end def format(tag, time, record) # print(record) - ['dt', 'uid', 'd'].each do |key| + ['dt', 'd'].each do |key| unless record.has_key?(key) puts "input data error: '#{key}' is required" return "" end end unless record.has_key?('pt') record['pt'] = time end unless record.has_key?('cid') record['cid'] = @id + end + unless record.has_key?('uid') + record['uid'] = '0' end record['pk'] = record['cid'] + record['dt'] return "#{record.to_json}," end