The server plugin helper manages various types of servers.
Here is an example:
require'fluent/plugin/input'moduleFluent::PluginclassExampleInput<InputFluent::Plugin.register_input('example', self)# 1. Load server helper helpers :server# Omit `configure`, `shutdown` and other plugin APIsdefstart# 2. Create serverserver_create(:title, @port)do|data|#3. Process dataendendendend
The launched server is managed by the plugin helper. No need of server shutdown code in plugin's shutdown method. The plugin shutdowns the launched servers automatically.
# TCP
server_create_connection(:title, @port) do |conn|
# on connection
# conn is Fluent::PluginHelper::Server::TCPCallbackSocket
source_addr = conn.remote_host
source_port = conn.remote_port
conn.data do |data|
conn.write(something)
end
end
# UDP (w/o socket)
server_create(:title, @port, proto: :udp, max_bytes: 2048) do |data|
# data is received data
end
# UDP (w/ socket)
server_create(:title, @port, proto: :udp, max_bytes: 2048) do |data, sock|
# data is received data
# sock is UDPSocket
end
# TCP (w/o connection)
server_create(:title, @port) do |data|
# data is received data
end
# TCP (w/ connection)
server_create(:title, @port) do |data, conn|
# data is received data
# conn is Fluent::PluginHelper::Server::TCPCallbackSocket
end
# TLS (w/o connection)
server_create(:title, @port, proto: :tls) do |data|
# data is received data
end
# TLS (w/ connection)
server_create(:title, @port, proto: :tls) do |data, conn|
# data is received data
# conn is Fluent::PluginHelper::Server::TLSCallbackSocket
end
<source>
@type forward
# other plugin parameters
<transport tls>
version TLSv1_2
ciphers ALL:!aNULL:!eNULL:!SSLv2
insecure false
# For Cert signed by public CA
ca_path /path/to/ca_file
cert_path /path/to/cert_path
private_key_path /path/to/priv_key
private_key_passphrase "passphrase"
client_cert_auth false
# For Cert signed by self signed CA
ca_path /path/to/ca_path
cert_path /path/to/cert_path
private_key_path /path/to/priv_key
private_key_passphrase "passphrase"
client_cert_auth false
</transport>
</source>
<source>
@type forward
# other plugin parameters
<transport tls>
version TLSv1_2
ciphers ALL:!aNULL:!eNULL:!SSLv2
insecure false
# For Cert generated
ca_cert_path /path/to/ca_cert
ca_private_key_path /path/to/ca_priv_key
ca_private_key_passphrase "ca_passphrase"
</transport>
</source>
Proc.new { |ok, ctx|
# check code
if cond
true
else
false
end
}
module Fluent
module Plugin
class InForwardCNChecker
def initialize
# Modify for actual common names
@allow_list = ['fluentd', 'fluentd-client', 'other-org']
end
def call(ok, ctx)
subject = ctx.chain.first.subject.to_a.find { |entry| entry.first == 'CN' }
if subject
@allow_list.include?(subject[1])
else
false
end
end
end
end
end
Fluent::Plugin::InForwardCNChecker.new