Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created Jun 11, 2020
Embed
What would you like to do?
#!/usr/bin/env ruby
require 'json'
require 'socket'
require 'openssl'
def format_syslog(buffer)
'<13>1 2020-04-18T15:16:09.956153-07:00 coconut tyler - - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="505061"] ' + buffer + "\n"
end
def send_it!
host = 'localhost'
tcp_client = TCPSocket.new(host, 6514)
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
ssl_client.sync_close = true
ssl_client.hostname = host
ssl_client.connect
100.times do |count|
log = {
:meta => { :topic => "test" },
:time => Time.now.utc,
:count => count,
:thread => Thread.current.name,
}
sent = ssl_client.write format_syslog(log.to_json)
puts "Sent: #{count} #{sent}"
ssl_client.flush
tcp_client.flush
#$stdout.write "#{count} (#{Thread.current.name}) "
#$stdout.flush
end
ssl_client.sysclose
rescue => e
puts "What the heck happened!: #{e}"
raise
end
send_it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment