i need to create a top 5 of interfaces that went up/down based on %LINK-3-UPDOWN from a log file. and also need to count the amount of ICMP packets that are stopped based on amount of %SEC-6-IPACCESSLOGDP. log file looks like this:
Sep 22 15:12:09 145.89.109.1 : %SEC-6-IPACCESSLOGP: list 120 denied tcp 80.82.77.33(0) -> 145.89.109.49(0), 1 packet Sep 22 16:11:15 145.89.109.11 28w6d: %LINK-3-UPDOWN: Interface GigabitEthernet1/20, changed state to up Sep 22 16:11:15 145.89.109.11 28w6d: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/20, changed state to up Sep 22 15:16:09 145.89.109.1 : %SEC-6-IPACCESSLOGP: list 120 denied tcp 216.158.238.186(0) -> 145.89.109.49(0), 1 packet Sep 22 15:17:10 145.89.109.1 : %SEC-6-IPACCESSLOGP: list 120 denied tcp 184.105.139.98(0) -> 145.89.109.49(0), 1 packet Sep 22 15:22:10 145.89.109.1 : %SEC-6-IPACCESSLOGS: list 78 denied 145.89.110.15 1 packet Sep 22 16:20:46 145.89.109.11 28w6d: %LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet1/20, changed state to down Sep 22 16:20:46 145.89.109.11 28w6d: %LINK-3-UPDOWN: Interface GigabitEthernet1/20, changed state to down
My code is as followed but i am not getting the result i want:
infile = open("router1.log","r") #Open log bestand in "read modus"
dictionary = {} #Maak lege dictionary aan
for line in infile: #For-loop die elke regel afgaat in log-bestand
try:
naam = line.split(":")[3] #variable naam die regel split naar een lijst met index 3
naam2 = line.split(":")[4] #variable naam die regel split naar een lijst met index 4
if naam.strip()in dictionary.keys(): #"Als" naam zich bevindt in dictionary voer onderstaande uit:
dictionary[naam.strip()]+=1
else: #Anders voer onderstaan uit:
dictionary[naam.strip()]=0
except:
continue