Class: Fluent::Plugin::LogentriesSSL::Output

Inherits:
Output
  • Object
show all
Includes:
Fluent::PluginHelper::Socket
Defined in:
lib/fluent/plugin/out_logentries_ssl.rb

Overview

The plugin implementation.

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 38

def configure(conf)
  super
  if @default_token.nil? && @token_path.nil?
    raise Fluent::ConfigError, 'Define :token_path or :default_token'
  end
  @apptokens = @token_path.nil? ? {} : load_tokens
end

#format(tag, _time, record) ⇒ Object



67
68
69
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 67

def format(tag, _time, record)
  [tag, record].to_msgpack
end

#formatted_to_msgpack_binaryObject

apparently needed for msgpack_each in :write fluent Issue-1342



53
54
55
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 53

def formatted_to_msgpack_binary
  true
end

#load_tokensObject



57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 57

def load_tokens
  begin
    tokens = YAML.load_file(@token_path)
  rescue StandardError => e
    raise Fluent::ConfigError,
          "Could not load #{@token_path}: #{e.message}"
  end
  tokens
end

#startObject



46
47
48
49
50
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 46

def start
  super
  log.trace "Creating connection to #{@le_host}"
  @_client = create_client
end

#tag_token(tag) ⇒ Object



71
72
73
74
75
76
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 71

def tag_token(tag)
  @apptokens.each do |name, token|
    return token if tag.casecmp(name).zero?
  end
  @default_token.nil? ? nil : @default_token
end

#write(chunk) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fluent/plugin/out_logentries_ssl.rb', line 78

def write(chunk)
  chunk.msgpack_each do |tag, record|
    token = tag_token(tag)
    next unless token
    data = @json ? record.to_json : record
    MessageHelper.split_record(token, "#{token} #{data} \n")
                 .each do |payload|
      with_retries { client.write(payload) }
    end
  end
end