Class: LogStash::Inputs::Logstash

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::PluginFactorySupport
Defined in:
lib/logstash/inputs/logstash.rb

Defined Under Namespace

Classes: QueueWrapper

Instance Method Summary collapse

Constructor Details

#initialize(*a) ⇒ Logstash

Returns a new instance of Logstash.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/logstash/inputs/logstash.rb', line 44

def initialize(*a)
  super

  if original_params.include?('codec')
    report_invalid_config! 'The `logstash` input does not have an externally-configurable `codec`'
  end

  logger.debug("initializing inner HTTP input plugin")
  @internal_http = plugin_factory.input('http').new(inner_http_input_options)
  logger.debug("inner HTTP input plugin has been initialized")
end

Instance Method Details

#closeObject



77
78
79
80
81
# File 'lib/logstash/inputs/logstash.rb', line 77

def close
  logger.debug("closing inner HTTP input plugin")
  @internal_http.close
  logger.debug('inner HTTP plugin has been closed')
end

#inner_http_input_optionsObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/logstash/inputs/logstash.rb', line 83

def inner_http_input_options
  @_inner_http_input_options ||= begin
    http_options = {
      # directly-configurable
      'host' => @host,
      'port' => @port,

      # non-configurable codec
      'codec' => plugin_factory.codec('json_lines').new(inner_json_lines_codec_options),
      'additional_codecs' => {},
      'response_headers' => { 'Accept' => 'application/x-ndjson' },

      # enrichment avoidance
      'ecs_compatibility'            => 'disabled',
      'remote_host_target_field'     => '[@metadata][void]',
      'request_headers_target_field' => '[@metadata][void]',
    }

    if @username
      http_options['user'] = @username
      http_options['password'] = @password || report_invalid_config!('`password` is REQUIRED when `username` is provided')
      logger.warn("transmitting credentials over non-secured connection") if @ssl_enabled == false
    elsif @password
      report_invalid_config!('`password` not allowed unless `username` is configured')
    end

    if @ssl_enabled == false
      rejected_ssl_settings = @original_params.keys.select { |k| k.start_with?('ssl_') } - %w(ssl_enabled)
      report_invalid_config!("Explicit SSL-related settings not supported because `ssl_enabled => false`: #{rejected_ssl_settings}") if rejected_ssl_settings.any?
    else
      http_options['ssl_enabled'] = true

      http_options['ssl_cipher_suites'] = @ssl_cipher_suites if @original_params.include?('ssl_cipher_suites')
      http_options['ssl_supported_protocols'] = @ssl_supported_protocols if @original_params.include?('ssl_supported_protocols')
      http_options['ssl_handshake_timeout'] = @ssl_handshake_timeout

      http_options.merge!(ssl_identity_options)
      http_options.merge!(ssl_trust_options)
    end

    http_options
  end
end

#inner_json_lines_codec_optionsObject



164
165
166
167
168
169
# File 'lib/logstash/inputs/logstash.rb', line 164

def inner_json_lines_codec_options
  @_inner_json_lines_codec_options ||= {
    # enrichment avoidance
    'ecs_compatibility' => 'disabled',
  }
end

#registerObject



56
57
58
59
60
# File 'lib/logstash/inputs/logstash.rb', line 56

def register
  logger.debug("registering inner HTTP input plugin")
  @internal_http.register
  logger.debug("inner HTTP input plugin has been registered")
end

#report_invalid_config!(message) ⇒ Object



171
172
173
# File 'lib/logstash/inputs/logstash.rb', line 171

def report_invalid_config!(message)
  fail(LogStash::ConfigurationError, message)
end

#run(queue) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/logstash/inputs/logstash.rb', line 62

def run(queue)
  logger.debug("starting inner HTTP input plugin")
  @internal_http.run(QueueWrapper.new(queue, method(:decorate)))
  logger.debug("inner HTTP input plugin has exited normally")
rescue => e
  logger.error("inner HTTP plugin has had an unrecoverable exception: #{e.message} at #{e.backtrace.first}")
  raise
end

#ssl_identity_optionsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/logstash/inputs/logstash.rb', line 127

def ssl_identity_options
  {}.tap do |identity_options|
    if @ssl_certificate && @ssl_keystore_path
      report_invalid_config!('SSL identity can be configured with EITHER `ssl_certificate` OR `ssl_keystore_*`, but not both')
    elsif @ssl_certificate
      identity_options['ssl_certificate'] = @ssl_certificate
      identity_options['ssl_key'] = @ssl_key || report_invalid_config!('`ssl_key` is required when `ssl_certificate` is configured')
      identity_options['ssl_key_passphrase'] = @ssl_key_passphrase unless @ssl_key_passphrase.nil?
    elsif @ssl_key
      report_invalid_config!('`ssl_key` is not allowed unless `ssl_certificate` is configured')
    elsif @ssl_key_passphrase
      report_invalid_config!('`ssl_key_passphrase` is not allowed unless `ssl_key` is configured')
    elsif @ssl_keystore_path
      identity_options['ssl_keystore_path'] = @ssl_keystore_path
      identity_options['ssl_keystore_password'] = @ssl_keystore_password || report_invalid_config!('`ssl_keystore_password` is REQUIRED when `ssl_keystore_path` is configured')
    elsif @ssl_keystore_password
      report_invalid_config!('`ssl_keystore_password` is not allowed unless `ssl_keystore_path` is configured')
    else
      report_invalid_config!('SSL identity MUST be configured with either `ssl_certificate`/`ssl_key` or `ssl_keystore_*`')
    end
  end
end

#ssl_trust_optionsObject



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/logstash/inputs/logstash.rb', line 150

def ssl_trust_options
  {
    'ssl_client_authentication' => @ssl_client_authentication,
  }.tap do |trust_options|
    if @ssl_certificate_authorities&.any?
      if @ssl_client_authentication == 'none'
        report_invalid_config!('`ssl_certificate_authorities` is not supported because `ssl_client_authentication => none`')
      end

      trust_options['ssl_certificate_authorities'] = @ssl_certificate_authorities
    end
  end
end

#stopObject



71
72
73
74
75
# File 'lib/logstash/inputs/logstash.rb', line 71

def stop
  logger.debug("stopping inner HTTP input plugin")
  @internal_http.stop
  logger.debug('inner HTTP plugin has been stopped')
end