Question: log _ analyzer.py import re from datetime import datetime import csv class LogEntry: def _ _ init _ _ ( self , event _ time,
log
analyzer.py
import re
from datetime import datetime
import csv
class LogEntry:
def
init
self
event
time, internal
ip
port
number, protocol, action, rule
id
source
ip
country country
name
:
self.event
time
datetimestrptime
event
time,
Y
m
d
H:
M:
S
Z
self.internal
ip
internal
ip
self.port
number
port
number
self.protocol
protocol
self.action
action
self.rule
id
rule
id
self.source
ip
source
ip
self.country
country
self.country
name
country
name
@property
def ipv
class
self
:
first
octet
int
self
source
ip
split
if
first
octet
:
return
A
elif
first
octet
:
return
B
elif
first
octet
:
return
C
elif
first
octet
:
return
D
else:
return 'Unknown'
test
log
analyzer.py
import unittest
from log
analyzer import LogEntry
class TestLogEntry
unittest
TestCase
:
def test
event
time
conversion
self
:
log
entry
LogEntry
event
time
:
:
UTC internal
ip
port
number
protocol
TCP
action
ALLOW rule
id
source
ip
country
US
country
name
United States"
self.assertEqual
log
entry.event
time.month,
self.assertEqual
log
entry.event
time.hour,
def test
ipv
class
self
:
log
entry
a
LogEntry
:
:
UTC
TCP
ALLOW
US
United States"
log
entry
b
LogEntry
:
:
UTC
TCP
ALLOW
US
United States"
log
entry
c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
