I'm building a script to parse out data from switch configuration files and have come to a bit of hiccup (using Python 3.5)
Here's the pseudo code I'm trying to work through:
if re.match(patter0):
continue to match pattern1
if re.match(pattern1):
test if < 10 minutes
return pass or fail
Here's the code that I have so far, I've tried many variations including for-in
loops, while
loops, and nested if
statements, but I'm getting no where.
def net1639andnet1624(input_file):
maxTimeOut = 10
pattern0 = re.compile("^line vty (([0-9] [0-9])|([0-9] [0-9][0-9]))$")
pattern1 = re.compile(
"^ exec-timeout\s([0-9]|[0-9][0-9]|[[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9])\s([0-9]|[0-9][0-9]|[[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9])$")
for i, line in enumerate(open(input_file)):
for match in re.finditer(pattern0, line):
print(line)
for match in re.finditer(pattern1, line):
minutes = match.group(1)
seconds = match.group(2)
print(line)
if int (minutes) > maxTimeOut:
print('fail')
else:
print('pass')
Last run, this return None when it should be returning 1 for each line vty
shown below:
!
line con 0
exec-timeout 0 30
stopbits 1
line vty 0 3
access-class 182 in
exec-timeout 1440 30
transport input telnet
line vty 4 15
access-class 182 in
no exec
exec-timeout 0 1
transport input none
!
end
So basically, I'm trying to get to the point where it tells me
line vty 0 3
exe-timeout 1440 30
fail
line vty 4 15
exec-timeout 0 1
pass