Skip to content

Instantly share code, notes, and snippets.

@darron
Created October 20, 2015 17:12
Show Gist options
  • Save darron/49022f4d52af400f1dc2 to your computer and use it in GitHub Desktop.
Save darron/49022f4d52af400f1dc2 to your computer and use it in GitHub Desktop.
Generate some CLF log lines and add it to a file one line at a time.
#!/usr/bin/env ruby
urls = %W(/homepage /page/subpage /page/about_us /section/two /dude /dudette)
ips = %W(127.0.0.1 192.168.0.1 192.168.1.4 192.168.2.3 192.168.5.5 192.168.7.1)
verbs = %W(GET POST PUT DELETE)
results = %W(200 404 403 301 302 500 200 200 200 200 200 200 200)
identities = %W(darron - - - - - - - - - -)
# 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
(1..1000).each do
File.open('log', 'a') do |file|
t = Time.new
timestring = t.strftime("%d/%b/%Y:%H:%M:%S")
bytes = rand(200..256000)
logline = "#{ips.sample} - #{identities.sample} [#{timestring} -0700] \"#{verbs.sample} #{urls.sample} HTTP/1.0\" #{results.sample} #{bytes}"
file.puts logline
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment