class Fluent::Plugin::AzureLogAnalyticsOutput

Constants

DEFAULT_BUFFER_TYPE

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 44
def configure(conf)
  compat_parameters_convert(conf, :buffer)
  super
  raise Fluent::ConfigError, 'no customer_id' if @customer_id.empty?
  raise Fluent::ConfigError, 'no shared_key' if @shared_key.empty?
  raise Fluent::ConfigError, 'no log_type' if @log_type.empty?
  if not @log_type.match(/^[[:alpha:]]+$/)
    raise Fluent::ConfigError, 'log_type supports only alpha characters'
  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_azure-loganalytics.rb, line 73
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
  record.to_msgpack
end
formatted_to_msgpack_binary?() click to toggle source
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 83
def formatted_to_msgpack_binary?
  true
end
multi_workers_ready?() click to toggle source
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 87
def multi_workers_ready?
  true
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 68
def shutdown
  super
  # destroy
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 62
def start
  super
  # start
  @client=Azure::Loganalytics::Datacollectorapi::Client::new(@customer_id,@shared_key,@endpoint)
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_azure-loganalytics.rb, line 91
def write(chunk)
  records = []
  chunk.msgpack_each { |record|
    records.push(record)
  }
  begin
    res = @client.post_data(@log_type, records, @time_generated_field, @azure_resource_id)
    if not Azure::Loganalytics::Datacollectorapi::Client.is_success(res)
      log.fatal "DataCollector API request failure: error code: " +
              "#{res.code}, data=>" + Yajl.dump(records)
    end
  rescue Exception => ex
    log.fatal "Exception occured in posting to DataCollector API: " +
              "'#{ex}', data=>" + Yajl.dump(records)
  end
end