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
- 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
22.214.171.124 - - [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:126.96.36.199) 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(-)
- IP Address of the client
- 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.
- The userid of the client if the request was authenticated. In above log that information is missing.
- The time that the request was received.
- The request line that includes the HTTP method used, the requested resource path, and the HTTP protocol that the client used.
- The status code that the server sends back to the client.
- The size of the object requested.
- Referrer information
- 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
- create and activate the virutalenv Create Python2.7 virtual environment
- Install the dependencies
pip install -r requirements.txt
- 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
188.8.131.52 - - [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" 184.108.40.206 - - [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" 220.127.116.11 - - [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:18.104.22.168) 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:22.214.171.124) 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:126.96.36.199) 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