class Fluent::Plugin::AzureFunctionsOutput

Constants

DEFAULT_BUFFER_TYPE

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azurefunctions.rb, line 38
def configure(conf)
  compat_parameters_convert(conf, :buffer)
  super
  raise Fluent::ConfigError, 'no endpoint' if @endpoint.empty?
  raise Fluent::ConfigError, 'no function_key' if @function_key.empty?
  if not @key_names.nil?
    @key_names = @key_names.split(',')
  end
  if @add_time_field and @time_field_name.empty?
    raise Fluent::ConfigError, 'time_field_name must be set if add_time_field is true'
  end
  if @add_tag_field and @tag_field_name.empty?
    raise Fluent::ConfigError, 'tag_field_name must be set if add_tag_field is true'
  end
  @timef = Fluent::TimeFormatter.new(@time_format, @localtime)
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_azurefunctions.rb, line 66
def format(tag, time, record)
  if @add_time_field
    record[@time_field_name] = @timef.format(time)
  end
  if @add_tag_field
    record[@tag_field_name] = tag
  end

  r = {}
  r['.rid'] =  SecureRandom.uuid
  if @add_time_field
    r[@time_field_name] = @timef.format(time)
  end
  if @add_tag_field
    r[@tag_field_name] = tag
  end

  if not @key_names.nil?
    @key_names.each_with_index do |key, i|
      value = record.include?(key) ? record[key] : ''
      r[key] = value
    end
    record = r
  else
    record = record.merge(r)
  end
  record.to_msgpack
end
formatted_to_msgpack_binary?() click to toggle source
# File lib/fluent/plugin/out_azurefunctions.rb, line 95
def formatted_to_msgpack_binary?
  true
end
multi_workers_ready?() click to toggle source
# File lib/fluent/plugin/out_azurefunctions.rb, line 99
def multi_workers_ready?
  true
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azurefunctions.rb, line 61
def shutdown
  super
  # destroy
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azurefunctions.rb, line 55
def start
  super
  # start
  @client=AzureFunctions::HTTPTriggerClient::new(@endpoint,@function_key)
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_azurefunctions.rb, line 103
def write(chunk)
  chunk.msgpack_each { |record|
    payload = JSON.dump(record)
    unique_identifier = record[".rid"]
    #p "payload=#{payload}"
    #p "unique_identifier=#{unique_identifier}"
    begin
      @client.post(payload)
    rescue Exception => ex
      log.fatal "Error occured in posting to Azure Functions HTTP trigger function: "
              + "'#{ex}', .rid=>#{unique_identifier}, payload=>" + payload
    end
  }
end