Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (first paragraph seen after question) Download the following python program and test log file. parse_logs.py Download parse_logs.py test_log.log Download test_log.log (second paragraph seen after

1. (first paragraph seen after question) Download the following python program and test log file. parse_logs.py Download parse_logs.py test_log.log Download test_log.log (second paragraph seen after question) 2. Review the python code from parse_logs.py and run the program to see what it does. Compare the output to the test_log.log file. 3. In a Word Processor answer the following questions. A) Explain what this code is doing? What is it filtering for? B) Describe what programming concepts are being used in this program. C) Modify the python code to filter for some other aspect of the test_log.log file. Explain what changes you made to the file and what code you changed.

import os import re # Regex used to match relevant loglines (in this case, a specific IP address) line_regex = re.compile(r".*fwd=\"12.34.56.78\".*$") # Output file, where the matched loglines will be copied to output_filename = os.path.normpath("parsed_lines.log") # Overwrites the file, ensure we're starting out with a blank file with open(output_filename, "w") as out_file: out_file.write("") # Open output file in 'append' mode with open(output_filename, "a") as out_file: # Open input file in 'read' mode with open("test_log.log", "r") as in_file: # Loop over each log line for line in in_file: # If log line matches our regex, print to console, and output file if (line_regex.search(line)): print(line) out_file.write(line)

2015-10-02 17:16:15.572813+00:00 heroku router - - at=info method=GET path="/" host=testapp.herokuapp.com request_id=5a32a15f-fb80-4559-b52a-d3551408c088 fwd="11.22.33.44" dyno=web.1 connect=1ms service=5440ms status=200 bytes=8823 High Response Time 2015-10-02 17:16:15.833793+00:00 heroku router - - at=info method=GET path="/main.js" host=testapp.herokuapp.com request_id=46eaec8e-afda-4872-a249- 53a7f3c04f3c fwd="12.34.56.78" dyno=web.1 connect=1ms service=23ms status=200 bytes=12418 2015-10-02 17:16:24.270610+00:00 heroku router - - at=info method=GET path="/main.js" host=testapp.herokuapp.com request_id=2743a6f1-778f-4452-9fd7- c2a4c2473258 fwd="11.22.33.44" dyno=web.1 connect=1ms service=15ms status=304 bytes=236 2015-10-02 17:16:15.842297+00:00 heroku router - - at=info method=GET path="/styles.css" host=testapp.herokuapp.com request_id=85c5c3ed-c893-4e50-a99d- 8e01bac0c52b fwd="12.34.56.78" dyno=web.1 connect=0ms service=17ms status=200 bytes=2993 2015-10-02 17:16:24.271826+00:00 heroku router - - at=info method=GET path="/styles.css" host=testapp.herokuapp.com request_id=a409275e-3e27-4e14-b6fd- 59edac5a7792 fwd="11.22.33.44" dyno=web.1 connect=0ms service=9ms status=304 bytes=235 2015-10-02 17:16:16.486789+00:00 heroku router - - at=info method=GET path="/icons/ android-touch-icon.png" host=testapp.herokuapp.com request_id=1c16c27b-751e-483e- a0e5-014e47c7fb0f fwd="12.34.56.78" dyno=web.1 connect=0ms service=29ms status=404 bytes=239 2015-10-02 17:16:24.047899+00:00 heroku router - - at=info method=GET path="/" host=testapp.herokuapp.com request_id=c72f2ff7-c7c8-43ac-9d79-5ab7c9aeaae6 fwd="12.34.56.78" dyno=web.1 connect=0ms service=12ms status=304 bytes=236 2015-10-02 17:17:17.035437+00:00 heroku router - - at=error code=H13 desc="Connection closed without response" method=POST path="/api/1.0/player/weekly" host=testapp.herokuapp.com request_id=56ff999f-2e56-4bf7-8716-fb6765adc86e fwd="52.6.158.18" dyno=web.1 connect=1ms service=1325ms status=503 bytes=0 Critical

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

What is the use of bootstrap program?

Answered: 1 week ago

Question

What is a process and process table?

Answered: 1 week ago

Question

What is Industrial Economics and Theory of Firm?

Answered: 1 week ago