Class: Fluent::Plugin::SyslogInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_syslog.rb

Constant Summary collapse

DEFAULT_PARSER =
'syslog'
SYSLOG_REGEXP =
/^\<([0-9]+)\>(.*)/
FACILITY_MAP =
{
  0   => 'kern',
  1   => 'user',
  2   => 'mail',
  3   => 'daemon',
  4   => 'auth',
  5   => 'syslog',
  6   => 'lpr',
  7   => 'news',
  8   => 'uucp',
  9   => 'cron',
  10  => 'authpriv',
  11  => 'ftp',
  12  => 'ntp',
  13  => 'audit',
  14  => 'alert',
  15  => 'at',
  16  => 'local0',
  17  => 'local1',
  18  => 'local2',
  19  => 'local3',
  20  => 'local4',
  21  => 'local5',
  22  => 'local6',
  23  => 'local7'
}
SEVERITY_MAP =
{
  0  => 'emerg',
  1  => 'alert',
  2  => 'crit',
  3  => 'err',
  4  => 'warn',
  5  => 'notice',
  6  => 'info',
  7  => 'debug'
}

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Input

#emit_records, #emit_size, #initialize, #metric_callback, #statistics

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included, #initialize, #terminate

Methods included from Fluent::PluginId

#initialize, #plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir, #stop

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #initialize, #inspect, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type

Constructor Details

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

Instance Method Details

#configure(conf) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/fluent/plugin/in_syslog.rb', line 119

def configure(conf)
  compat_parameters_convert(conf, :parser)

  super

  if conf.has_key?('priority_key')
    log.warn "priority_key is deprecated. Use severity_key instead"
  end

  @use_default = false

  @parser = parser_create
  @parser_parse_priority = @parser.respond_to?(:with_priority) && @parser.with_priority

  if @include_source_host
    if @source_address_key
      raise Fluent::ConfigError, "specify either source_address_key or include_source_host"
    end
    @source_address_key = @source_host_key
  end
  if @source_hostname_key
    if @resolve_hostname.nil?
      @resolve_hostname = true
    elsif !@resolve_hostname # user specifies "false" in config
      raise Fluent::ConfigError, "resolve_hostname must be true with source_hostname_key"
    end
  end

  @_event_loop_run_timeout = @blocking_timeout

  protocol = @protocol_type || @transport_config.protocol
  if @send_keepalive_packet && protocol == :udp
    raise Fluent::ConfigError, "send_keepalive_packet is available for tcp/tls"
  end
end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/fluent/plugin/in_syslog.rb', line 155

def multi_workers_ready?
  true
end

#startObject



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fluent/plugin/in_syslog.rb', line 159

def start
  super

  log.info "listening syslog socket on #{@bind}:#{@port} with #{@protocol_type || @transport_config.protocol}"
  case @protocol_type || @transport_config.protocol
  when :udp then start_udp_server
  when :tcp then start_tcp_server
  when :tls then start_tcp_server(tls: true)
  else
    raise "BUG: invalid transport value: #{@protocol_type || @transport_config.protocol}"
  end
end

#start_tcp_server(tls: false) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/fluent/plugin/in_syslog.rb', line 178

def start_tcp_server(tls: false)
  octet_count_frame = @frame_type == :octet_count

  delimiter = octet_count_frame ? " " : @delimiter
  delimiter_size = delimiter.size
  server_create_connection(
    tls ? :in_syslog_tls_server : :in_syslog_tcp_server, @port,
    bind: @bind,
    resolve_name: @resolve_hostname,
    send_keepalive_packet: @send_keepalive_packet
  ) do |conn|
    conn.data do |data|
      buffer = conn.buffer
      buffer << data
      pos = 0
      if octet_count_frame
        while idx = buffer.index(delimiter, pos)
          num = Integer(buffer[pos..idx])
          msg = buffer[idx + delimiter_size, num]
          if msg.size != num
            break
          end

          pos = idx + delimiter_size + num
          message_handler(msg, conn)
        end
      else
        while idx = buffer.index(delimiter, pos)
          msg = buffer[pos...idx]
          pos = idx + delimiter_size
          message_handler(msg, conn)
        end
      end
      buffer.slice!(0, pos) if pos > 0
    end
  end
end

#start_udp_serverObject



172
173
174
175
176
# File 'lib/fluent/plugin/in_syslog.rb', line 172

def start_udp_server
  server_create_udp(:in_syslog_udp_server, @port, bind: @bind, max_bytes: @message_length_limit, resolve_name: @resolve_hostname) do |data, sock|
    message_handler(data.chomp, sock)
  end
end