Permalink
Browse files

first

  • Loading branch information...
0 parents commit b53e8e1b8957e312a738af31b0f5bc36bd13716b Mary Cook committed Oct 7, 2009
Showing with 5,248 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +1 −0 1.txt
  3. +9 −0 2.txt
  4. +12 −0 3.txt
  5. +19 −0 README
  6. +5,129 −0 log.log
  7. +75 −0 main.rb
@@ -0,0 +1,3 @@
+load_test.xml
+apache.log
+urls.txt
@@ -0,0 +1 @@
+<HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="
@@ -0,0 +1,9 @@
+" enabled="true">
+ <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
+ <collectionProp name="Arguments.arguments"/>
+ </elementProp>
+ <stringProp name="HTTPSampler.domain"></stringProp>
+ <stringProp name="HTTPSampler.port"></stringProp>
+ <stringProp name="HTTPSampler.protocol"></stringProp>
+ <stringProp name="HTTPSampler.contentEncoding"></stringProp>
+ <stringProp name="HTTPSampler.path">
@@ -0,0 +1,12 @@
+</stringProp>
+ <stringProp name="HTTPSampler.method">GET</stringProp>
+ <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
+ <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
+ <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
+ <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
+ <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
+ <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
+ <stringProp name="HTTPSampler.mimetype"></stringProp>
+ <stringProp name="HTTPSampler.monitor">false</stringProp>
+ <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
+</HTTPSampler>
@@ -0,0 +1,19 @@
+Logtoload
+Takes an Apache log and turns it into:
+ 1. A list of URLs that were requested.
+ 2. An XML file that can be used in the xxx load tester.
+
+By: maryrosecook for the OTHER media
+http://maryrosecook.com
+maryrosecook@maryrosecook.com
+
+----
+
+Quick run: ruby main.rb "log.log" "urls.txt" "load_test.xml" false
+
+The script takes four command-line arguments:
+
+- filename for input log file (string, not nil)
+- filename for url list (string, or nil to not write file)
+- filename for load test xml (string, or nil to not write file)
+- whether to include URLs with params (true/false, not nil)
5,129 log.log
Oops, something went wrong.
@@ -0,0 +1,75 @@
+LOG_FILENAME = ARGV[0]
+URL_LIST_FILENAME = ARGV[1]
+LOAD_TEST_XML_FILENAME = ARGV[2]
+EXCLUDE_URLS_WITH_QUESTION_MARKS = Boolean(ARGV[3])
+
+def read_file_to_str(filename)
+ str = ""
+ file = File.new(filename, "r")
+ while line = file.gets
+ str += line
+ end
+
+ return str
+end
+
+def Boolean(string)
+ return true if string == true || string =~ /^true$/i
+ return false if string == false || string.nil? || string =~ /^false$/i
+ raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
+end
+
+if LOG_FILENAME
+ # get all urls requested in log file
+ urls = []
+ file = File.new(LOG_FILENAME, "r")
+ i = 0
+ while line = file.gets
+ if i > 0
+ line = line.gsub(/[^\]]*\]/, '')
+ line = line.gsub('"', '')
+ line = line.gsub(/ HTTP\/.*/, "")
+ line = line.gsub(/PROPFIND.*/, "")
+ line = line.gsub(/GET /, "")
+ line = line.gsub(/HEAD /, "")
+ line = line.gsub(/POST /, "")
+ line = line.gsub(/actionToken=[^\&]*\&/, "&")
+ line = line.strip
+ if line && line.length > 0
+ urls << line.strip unless EXCLUDE_URLS_WITH_QUESTION_MARKS && line.match(/\?/)
+ end
+ end
+
+ i += 1
+ end
+
+ # retain unique urls
+ unique_urls = urls.uniq
+
+ # write unique_urls to file
+ if URL_LIST_FILENAME
+ File.open(URL_LIST_FILENAME, 'w') do |f|
+ for url in unique_urls
+ f.write(url + "\n")
+ end
+ end
+ end
+
+ # put xml pieces into vars
+ part_1 = read_file_to_str("1.txt")
+ part_2 = read_file_to_str("2.txt")
+ part_3 = read_file_to_str("3.txt")
+
+ # for each url, make a new piece of xml and add it onto xml_str
+ xml_str = ""
+ for url in unique_urls
+ xml_str += part_1 + url + part_2 + url + part_3 + "\n\n"
+ end
+
+ # write xml_str to file
+ if LOAD_TEST_XML_FILENAME
+ File.open(LOAD_TEST_XML_FILENAME, 'w') do |f|
+ f.write(xml_str)
+ end
+ end
+end

0 comments on commit b53e8e1

Please sign in to comment.