Aim

Sometime there is need to generate fake Apache Server Logs. Like you want to create a big data project, so you will need a large amount of data. You can perform analysis on that data and then you can produce useful results.

We will be using a Python library to generate fake Apache server logs

Prerequisite

  • Python 2.7 must be installed on you machine
  • virtualenv must be installed

What is Apache server log

A sample Apache logs looks something like this

167.164.149.210 - - [31/Aug/2020:00:26:01 +0530] "GET /apps/cart.jsp?appID=8844 HTTP/1.0" 200 5002 "http://www.romero-johnson.com/homepage/" "Mozilla/5.0 (Windows NT 6.2; it-IT; rv:1.9.1.20) Gecko/2014-10-16 05:22:05 Firefox/3.8"  

Each log contain very useful information about the request. If any component of the log is absent then it is written as hyphen(-)

  1. IP Address of the client
  2. The identity of the client determined by identd on the client's machine. Will return a hyphen (-) if this information is not available. In above log that information is missing.
  3. The userid of the client if the request was authenticated. In above log that information is missing.
  4. The time that the request was received.
  5. The request line that includes the HTTP method used, the requested resource path, and the HTTP protocol that the client used.
  6. The status code that the server sends back to the client.
  7. The size of the object requested.
  8. Referrer information
  9. UserAgent Information e.g. from which browser this request has been received.

Install Fake log generator

  • Clone the code base to your local machine from below repository
git clone https://github.com/self-tuts/Fake-Apache-Log-Generator.git
  • Move inside the code base
cd Fake-Apache-Log-Generator
pip install -r requirements.txt

Generate logs

  • Once the installation is complete. You can generate fake Apache server logs by running the apache-fake-log-gen.py file.
  • This file accepts many option

Generate n number of logs

  • suppose you want to generate 5 logs so n = 5
python apache-fake-log-gen.py -n 5
  • Output will be
209.37.80.163 - - [31/Aug/2020:00:58:20 +0530] "GET /wp-content HTTP/1.0" 200 4986 "http://davis-davis.com/main/" "Opera/8.77.(Windows 95; en-US) Presto/2.9.189 Version/11.00"
33.64.233.136 - - [31/Aug/2020:01:00:00 +0530] "GET /app/main/posts HTTP/1.0" 200 4963 "http://shepherd.org/" "Mozilla/5.0 (Windows NT 4.0) AppleWebKit/5310 (KHTML, like Gecko) Chrome/15.0.810.0 Safari/5310"
47.226.87.119 - - [31/Aug/2020:01:04:14 +0530] "GET /wp-admin HTTP/1.0" 200 4993 "http://burnett.info/homepage.php" "Mozilla/5.0 (Windows NT 4.0; sl-SI; rv:1.9.1.20) Gecko/2011-04-30 03:09:38 Firefox/15.0"
246.244.182.65 - - [31/Aug/2020:01:06:33 +0530] "POST /list HTTP/1.0" 200 5061 "http://www.fowler.com/home.html" "Mozilla/5.0 (Windows NT 5.01; sl-SI; rv:1.9.1.20) Gecko/2013-04-02 20:43:31 Firefox/3.8"
252.46.76.238 - - [31/Aug/2020:01:08:25 +0530] "GET /apps/cart.jsp?appID=4003 HTTP/1.0" 200 4901 "http://martinez-moon.com/main/" "Mozilla/5.0 (Windows 98; Win 9x 4.90; sl-SI; rv:1.9.1.20) Gecko/2015-06-20 12:17:42 Firefox/3.8"

Generate Apache logs and write that to an output file

  • You can use the -o option and then give the format as LOG. This will write a random access_log file in the current directory.
python apache-fake-log-gen.py -n 5 -o LOG

Generate Apache Server logs in certain interval

  • You can also mimic a scenario where Apache server logs are generated in regular time interval
  • You need to use -s option and give the value in seconds
  • Below command will generate logs in interval of 5 seconds. When 5 logs are generated then it will exit.
python apache-fake-log-gen.py -n 5 -s 1

Generate infinite amount of logs with certain interval

  • use the -n flag and give the value as 0
  • Using below command you can generate infinite amount of logs and logs will be generated in a time interval of 1 second
python apache-fake-log-gen.py -n 0 -s 1

Happy Coding

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x