-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_loop.py
More file actions
executable file
·50 lines (43 loc) · 1.21 KB
/
check_loop.py
File metadata and controls
executable file
·50 lines (43 loc) · 1.21 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
#!/usr/bin/python
import sys
import datetime
def getLoopCount():
fp = open("/var/log/syslog","rb")
data = fp.read()
fp.close()
first = None
result = {}
for l in data.strip().split("\n"):
ls = l.split(" ")
if ls[4] != "kernel:":
continue
if not ls[6].startswith("br"):
continue
interface = ls[10]
if not " ".join(ls[11:]) == "with own address as source address":
continue
d = datetime.datetime.strptime(str(datetime.datetime.now().year)+" "+" ".join(ls[0:3]), "%Y %b %d %H:%M:%S")
delta = datetime.datetime.now() - d
if delta.seconds > 60: #1 min
continue
if first == None:
first = l
#print "%i: %s"%(delta.seconds,interface)
if interface not in result:
result[interface] = 0
result[interface]+=1
#print l
#print "First:"
#print first
#print "Count: %i"%(count)
return result
result = getLoopCount()
#result["test"] =5
if len(result.keys()) == 0:
print "\n***** No loops detected *****"
sys.exit(0)
else:
print "\nLoops in:"
for r in result:
print " %s:%i"%(r,result[r])
sys.exit(1)