Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new file named log _ analyzer.py in the directory you created for this application. This file will be a module that you will

Create a new file named log_analyzer.py in the directory you created for this application. This file will be a module that you will include into your main directive code.
In the log_analyzer.py file, create a new Python class named LogEntry. Each object of class LogEntry will represent one line in the CSV file.
The LogEntry class will have the following attributes: event_time, internal_ip, port_number, protocol, action, rule_id, source_ip, country, and country_name. The other fields are optional.
The CSV file contains a string with the date and time information. In the initializer for the LogEntry class, use the Python datetime package to ensure that the value for event_date is stored as a datetime object. (This will be important later.)
Add a property to the LogEntry class called ipv4_class that uses a regular expression to examine the source_ip and returns the string value of the IPv4 address class (which will be either A,B,C, or D) based on the public IP address range. For example, the source_ip 11.177.69.220 will return A and the source_ip 173.205.219.112 will return C.
Think: How can you find just the first component of an IPv4 address?
Write Unit Tests for the LogEntry Class
Create a new file named test_log_analyzer.py in the directory you created for this application. Write several unit tests that evaluate the following functionality of your LogEntry class:
1. Ensure that the event_time string is properly converted to a datetime object.
a. For example, you could create a new instance of LogEntry with a string value of 2022-01-0108:29:25 UTC for the event_time. You could then assert that the month of the resulting datetime object ==1.
b. You could also assert that the hour of the resulting datetime object ==8.
2. Ensure that the ipv4_class returns the correct IPv4 address class
a. For example, you can assert that the ipv4_class ==D for the source_ip 229.163.4.51
Write several tests (asserts) for each of the above scenarios to ensure your class is behaving correctly. Make sure all your tests pass before moving on.
THINK: What else could go wrong when converting the CSV to objects of class LogEntry?

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 And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

2. What is the business value of security and control?

Answered: 1 week ago

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago