-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.py
More file actions
65 lines (50 loc) · 2.67 KB
/
Copy pathmanager.py
File metadata and controls
65 lines (50 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import file_handler as fh
import datetime
def display_report():
data = fh.read_file()
total_entries = len(data)
p_entry , n_entry , u_ip , failed , ip_set = fh.positive_negative_entries(data)
most_active_ip , active_ip_count , sus_ips = fh.count_ip(data)
print("=================================")
print("=================================")
print(" Log Analyzer Report ")
print("=================================")
print("Entries := ")
print(f" Total Entries : {total_entries}")
print(f" Passed Entries : {p_entry}")
print(f" Failed Entries : {n_entry}")
print(f" Failure Rate : {len(failed)/len(data) * 100} % ")
print(f" Most active ip : {most_active_ip} count {active_ip_count} \n")
print(f"Sus ips := ")
for i in sus_ips:
print(f" {i[0]} with count {i[1]}")
print("=================================")
further_input_for_processing = int(input("Choose from following options(1/2/3) : \n 1. Show failed logs , \n 2. Save report \n 3. None \n"))
if further_input_for_processing == 1:
for i in range (len(failed)) :
print(f"{i}. Failed Log: {failed[i]}" , end='')
elif further_input_for_processing == 2:
save_file(data , total_entries , p_entry , n_entry , failed , most_active_ip , active_ip_count , sus_ips)
print("Done!")
def save_file(data , total_entries , p_entry , n_entry , failed , most_active_ip , active_ip_count , sus_ips):
time_ = datetime.datetime.now().strftime("%d-%m-%Y_%H;%M;%S")
with open (f"Output/log_report_{time_}.txt" , 'x') as file:
file.write(f" Timed : {time_} \n")
file.write("================================= \n")
file.write("================================= \n")
file.write(" Log Analyzer Report \n")
file.write("================================= \n")
file.write("Entries := \n")
file.write(f" Total Entries : {total_entries} \n")
file.write(f" Passed Entries : {p_entry} \n")
file.write(f" Failed Entries : {n_entry} \n")
file.write(f" Failure Rate : {len(failed)/len(data) * 100} % \n")
file.write(f" Most active ip : {most_active_ip} count {active_ip_count} \n \n")
file.write(f"Sus ips := \n")
for i in sus_ips:
file.write(f" {i[0]} with count {i[1]} \n")
file.write("================================= \n")
file.write(f"Failed Logs : \n")
for i in range (len(failed)) :
file.write(f"{i}. Failed Log: {failed[i]}")
file.write("================================= \n")