Class: Fluent::LogglySyslog
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::LogglySyslog
show all
- Defined in:
- lib/fluent/plugin/out_loggly_syslog.rb
Defined Under Namespace
Classes: SocketFailureError
Constant Summary
collapse
- DISCARD_STRING =
declare const string for nullifying token if we decide to discard records
'DISCARD'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#sockets ⇒ Object
Returns the value of attribute sockets.
4
5
6
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 4
def sockets
@sockets
end
|
Instance Method Details
26
27
28
29
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 26
def configure(conf)
super
end
|
#create_packet(tag, time, record, token) ⇒ Object
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
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 90
def create_packet(tag, time, record, token)
if @parse_json && record.dig('message')
begin
parsed_message = JSON.parse(record['message'])
record['log'] = parsed_message
record.delete('message')
rescue JSON::ParserError
end
end
pri = 134
version = 1
record_time = time ? Time.at(time) : Time.now
timestamp = record_time.to_datetime.rfc3339
hostname = @loggly_hostname || '-'
app_name = tag || '-'
procid = '-'
msgid = '-'
pen = 41058
tag = @loggly_tag ? " tag=\"#{@loggly_tag}\"" : ''
structured_data = "[#{token}@#{pen}#{tag}]"
msg = record.to_json
"<#{pri}>#{version} #{timestamp} #{hostname} #{app_name} #{procid} #{msgid} #{structured_data} #{msg}"
end
|
#create_socket(host, port) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 56
def create_socket(host, port)
log.info "initializing tcp socket for #{host}:#{port}"
begin
socket = TCPSocket.new(host, port)
log.debug "enabling ssl for socket #{host}:#{port}"
ssl = OpenSSL::SSL::SSLSocket.new(socket)
ssl.sync_close = true
ssl.connect
rescue => e
log.warn "failed to create tcp socket #{host}:#{port}: #{e}"
ssl = nil
end
ssl
end
|
42
43
44
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 42
def format(tag, time, record)
[tag, time, record].to_msgpack
end
|
#pick_token(record) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 73
def pick_token(record)
if record.dig('kubernetes', 'annotations', 'solarwinds_io/loggly_token')
token = record['kubernetes']['annotations']['solarwinds_io/loggly_token']
elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/loggly_token')
token = record['kubernetes']['namespace_annotations']['solarwinds_io/loggly_token']
elsif record.dig('kubernetes') && @discard_unannotated_pod_logs
token = DISCARD_STRING
else
token = @loggly_token
end
token
end
|
#send_to_loggly(packet) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 123
def send_to_loggly(packet)
@socket ||= create_socket(@loggly_host, @loggly_port)
if @socket.nil?
err_msg = "Unable to create socket with #{@loggly_host}:#{@loggly_port}"
raise SocketFailureError, err_msg
else
begin
@socket.puts packet
rescue => e
@socket = nil
err_msg = "Closing socket. #{e.class} writing to '#{@loggly_host}:#{@loggly_port}': #{e}"
raise SocketFailureError, err_msg, e.backtrace
end
end
end
|
#shutdown ⇒ Object
37
38
39
40
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 37
def shutdown
super
@socket.close
end
|
#start ⇒ Object
31
32
33
34
35
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 31
def start
super
@socket = create_socket(@loggly_host, @loggly_port)
end
|
#write(chunk) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/fluent/plugin/out_loggly_syslog.rb', line 46
def write(chunk)
chunk.msgpack_each { |(tag, time, record)|
token = pick_token(record)
unless token.eql? DISCARD_STRING
packet = create_packet(tag, time, record, token)
send_to_loggly(packet)
end
}
end
|