Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created June 11, 2020 16:15
Show Gist options
  • Save rtyler/32968c568369b9376ec602855273d191 to your computer and use it in GitHub Desktop.
Save rtyler/32968c568369b9376ec602855273d191 to your computer and use it in GitHub Desktop.
#!/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