Class: Fluent::FTPOutput

Inherits:
TimeSlicedOutput
  • Object
show all
Includes:
Mixin::ConfigPlaceholders, SetTagKeyMixin, SetTimeKeyMixin
Defined in:
lib/fluent/plugin/out_ftp.rb

Instance Method Summary collapse

Constructor Details

#initializeFTPOutput

Returns a new instance of FTPOutput.



7
8
9
10
11
12
13
14
15
# File 'lib/fluent/plugin/out_ftp.rb', line 7

def initialize
  super
  require 'net/ftp'
  require 'zlib'
  require 'time'
  require 'tempfile'
  require 'open3'
  require 'pathname'
end

Instance Method Details

#configure(conf) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/out_ftp.rb', line 39

def configure(conf)
  super

  if format_json = conf['format_json']
    @format_json = true
  else
    @format_json = false
  end

  @timef = TimeFormatter.new(@time_format, @localtime)

  @ext = case @store_as
    when 'gzip' then 'gz'
    when 'lzo' then
      begin
        Open3.capture3('lzop -V')
      rescue Errno::ENOENT
        raise ConfigError, "'lzop' utility must be in PATH for LZO compression"
      end
      'lzo'
    when 'json' then 'json'
    else 'txt'
  end

  if @localtime
    @path_slicer = Proc.new { |path| Time.now.strftime(path) }
  else
    @path_slicer = Proc.new { |path| Time.now.utc.strftime(path) }
  end
end

#format(tag, time, record) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fluent/plugin/out_ftp.rb', line 77

def format(tag, time, record)
  if @include_time_key || !@format_json
    time_str = @timef.format(time)
  end

  # copied from each mixin because current TimeSlicedOutput can't support mixins.
  if @include_tag_key
    record[@tag_key] = tag
  end
  if @include_time_key
    record[@time_key] = time_str
  end

  if @format_json
    Yajl.dump(record) + "\n"
  else
    "#{time_str}\t#{tag}\t#{Yajl.dump(record)}\n"
  end
end

#placeholdersObject



35
36
37
# File 'lib/fluent/plugin/out_ftp.rb', line 35

def placeholders
  [:percent]
end

#startObject



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

def start
  super
  with_ftp_connection { |conn|
    # check valid connection here, nothing to do
  }
end

#write(chunk) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/fluent/plugin/out_ftp.rb', line 97

def write(chunk)
  with_ftp_connection { |conn|
    ftp_filename = gen_ftp_filename(conn, chunk.key)
    with_compression(@store_as, chunk) { |tmp_path|
      conn.putbinaryfile(tmp_path, ftp_filename)
    }
  }
end