Class: Fluent::AzureFunctionsOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_azurefunctions.rb

Instance Method Summary collapse

Constructor Details

#initializeAzureFunctionsOutput



7
8
9
10
11
12
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 7

def initialize
  super
  require 'msgpack'
  require 'time'
  require 'fluent/plugin/azurefunctions/client'
end

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (ConfigError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 33

def configure(conf)
  super
  raise ConfigError, 'no endpoint' if @endpoint.empty?
  raise 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 ConfigError, 'time_field_name must be set if add_time_field is true'
  end
  if @add_tag_field and @tag_field_name.empty?
    raise ConfigError, 'tag_field_name must be set if add_tag_field is true'
  end
  @timef = TimeFormatter.new(@time_format, @localtime)
end

#format(tag, time, record) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 60

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

#shutdownObject



55
56
57
58
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 55

def shutdown
  super
  # destroy
end

#startObject



49
50
51
52
53
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 49

def start
  super
  # start
  @client=AzureFunctions::HTTPTriggerClient::new(@endpoint,@function_key)
end

#write(chunk) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fluent/plugin/out_azurefunctions.rb', line 89

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