Class: Fluent::Plugin::ExecOutput

Inherits:
Output show all
Defined in:
lib/fluent/plugin/out_exec.rb

Constant Summary

Constants inherited from Output

Output::CHUNKING_FIELD_WARN_NUM, Output::CHUNK_KEY_PATTERN, Output::CHUNK_KEY_PLACEHOLDER_PATTERN, Output::CHUNK_TAG_PLACEHOLDER_PATTERN, Output::FORMAT_COMPRESSED_MSGPACK_STREAM, Output::FORMAT_COMPRESSED_MSGPACK_STREAM_TIME_INT, Output::FORMAT_MSGPACK_STREAM, Output::FORMAT_MSGPACK_STREAM_TIME_INT, Output::TIMESTAMP_CHECK_BASE_TIME, Output::TIME_KEY_PLACEHOLDER_THRESHOLDS

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from Output

#as_secondary, #buffer, #chunk_key_tag, #chunk_key_time, #chunk_keys, #delayed_commit, #delayed_commit_timeout, #emit_count, #emit_records, #in_tests, #num_errors, #output_enqueue_thread_waiting, #retry, #rollback_count, #secondary, #timekey_zone, #write_count

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Output

#acts_as_secondary, #after_shutdown, #after_start, #before_shutdown, #close, #commit_write, #emit_buffered, #emit_events, #emit_sync, #enqueue_thread_run, #enqueue_thread_wait, #execute_chunking, #extract_placeholders, #flush_thread_run, #flush_thread_wakeup, #force_flush, #formatted_to_msgpack_binary, #generate_format_proc, #get_placeholders_keys, #get_placeholders_tag, #get_placeholders_time, #handle_stream_simple, #handle_stream_with_custom_format, #handle_stream_with_standard_format, #implement?, #initialize, #interrupt_flushes, #metadata, #metadata_for_test, #next_flush_time, #placeholder_validate!, #placeholder_validators, #prefer_buffered_processing, #prefer_delayed_commit, #process, #retry_state, #rollback_write, #shutdown, #start, #stop, #submit_flush_all, #submit_flush_once, #support_in_v12_style?, #terminate, #try_flush, #try_rollback_all, #try_rollback_write, #try_write, #write_guard

Methods included from UniqueId::Mixin

#dump_unique_id_hex, #generate_unique_id

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included, #initialize, #start, #terminate

Methods included from Fluent::PluginId

#plugin_id, #plugin_id_configured?, #plugin_id_for_test?

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configured?, #has_router?, #initialize, #inspect, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, included, #initialize, lookup_type, register_type

Constructor Details

This class inherits a constructor from Fluent::Plugin::Output

Instance Method Details

#compat_parameters_default_chunk_keyObject



51
52
53
# File 'lib/fluent/plugin/out_exec.rb', line 51

def compat_parameters_default_chunk_key
  'time'
end

#configure(conf) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fluent/plugin/out_exec.rb', line 55

def configure(conf)
  compat_parameters_convert(conf, :buffer, default_chunk_key: 'time')

  super

  @formatter = case @format
               when :tsv
                 if @keys.empty?
                   raise Fluent::ConfigError, "keys option is required on exec output for tsv format"
                 end
                 Fluent::ExecUtil::TSVFormatter.new(@keys)
               when :json
                 Fluent::ExecUtil::JSONFormatter.new
               when :msgpack
                 Fluent::ExecUtil::MessagePackFormatter.new
               end

  if @time_key
    if @time_format
      tf = Fluent::TimeFormatter.new(@time_format, @localtime, @timezone)
      @time_format_proc = tf.method(:format)
    else
      @time_format_proc = Proc.new { |time| time.to_s }
    end
  end
end

#format(tag, time, record) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fluent/plugin/out_exec.rb', line 82

def format(tag, time, record)
  out = ''
  if @time_key
    record[@time_key] = @time_format_proc.call(time)
  end
  if @tag_key
    record[@tag_key] = tag
  end
  @formatter.call(record, out)
  out
end

#write(chunk) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fluent/plugin/out_exec.rb', line 94

def write(chunk)
  if chunk.respond_to?(:path)
    prog = "#{@command} #{chunk.path}"
  else
    tmpfile = Tempfile.new("fluent-plugin-exec-")
    tmpfile.binmode
    chunk.write_to(tmpfile)
    tmpfile.close
    prog = "#{@command} #{tmpfile.path}"
  end

  system(prog)
  ecode = $?.to_i
  tmpfile.delete if tmpfile

  if ecode != 0
    raise "command returns #{ecode}: #{prog}"
  end
end