-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflapper.py
More file actions
executable file
·98 lines (83 loc) · 2.68 KB
/
flapper.py
File metadata and controls
executable file
·98 lines (83 loc) · 2.68 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
######
# flapper.py
#
# A tool for parsing through 128T logs (routingManager) to look for evidence of path flaps,
# and to create some human-readable/interpretable output.
#
# (c)2022 Patrick Timmons
######
import os
import re
import argparse
import sys
FLAP_REGEX = r'.*Peer path state change'
def main(argv):
parser = argparse.ArgumentParser(description='128T peer path flap analyzer')
parser.add_argument('--input', '-i', metavar='<filename>', type=str,
help='routingManager to analyze')
args = parser.parse_args()
flap_count = 0
flap_down = 0
flap_up = 0
skipped = 0
peer_flaps = {}
intf_flaps = {}
with open(args.input) as fin:
for line in fin:
is_flap = re.search(FLAP_REGEX, line)
if is_flap:
tokens = line.split()
if len(tokens) < 30:
skipped += 1
continue
peer_name = tokens[15]
peer_intf = tokens[18]
node_name = tokens[21]
self_intf = tokens[24]
self_vlan = tokens[27]
peer_state = tokens[29]
if self_intf in peer_flaps.keys():
if peer_name in peer_flaps[self_intf].keys():
if peer_intf in peer_flaps[self_intf][peer_name].keys():
if peer_flaps[self_intf][peer_name][peer_intf]['state'] == peer_state:
skipped += 1
continue
peer_flaps[self_intf][peer_name][peer_intf]['state'] = peer_state
peer_flaps[self_intf][peer_name][peer_intf]['count'] += 1
else:
peer_flaps[self_intf][peer_name][peer_intf] = {}
peer_flaps[self_intf][peer_name][peer_intf]['state'] = peer_state
peer_flaps[self_intf][peer_name][peer_intf]['count'] = 1
else:
peer_flaps[self_intf][peer_name] = {}
peer_flaps[self_intf][peer_name][peer_intf] = {}
peer_flaps[self_intf][peer_name][peer_intf]['state'] = peer_state
peer_flaps[self_intf][peer_name][peer_intf]['count'] = 1
else:
if peer_state == 'down':
# only add them here if they're down (presume they're up to begin with)
peer_flaps[self_intf] = {}
peer_flaps[self_intf][peer_name] = {}
peer_flaps[self_intf][peer_name][peer_intf] = {}
peer_flaps[self_intf][peer_name][peer_intf]['state'] = peer_state
peer_flaps[self_intf][peer_name][peer_intf]['count'] = 1
else:
skipped += 1
continue
if self_intf in intf_flaps.keys():
intf_flaps[self_intf] += 1
else:
intf_flaps[self_intf] = 1
if tokens[29] == 'up':
flap_up += 1
elif tokens[29] == 'down':
flap_down += 1
flap_count += 1
print(f'Found {flap_count} flaps in the file.')
print(f' up: {flap_up}, down: {flap_down}')
print(f' skipped {skipped}')
print(peer_flaps)
print(intf_flaps)
if __name__ == '__main__':
main(sys.argv[1:])