From 06c31d83dbd5dec41ac30ab83327041313ecc10a Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Wed, 30 Sep 2020 11:54:08 -0600 Subject: [PATCH 1/3] trying to catch the lockup with cisco controller and graceful exit --- cisco_wifi_ctl.py | 67 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/cisco_wifi_ctl.py b/cisco_wifi_ctl.py index 80cbf252..e30c1a4c 100755 --- a/cisco_wifi_ctl.py +++ b/cisco_wifi_ctl.py @@ -465,11 +465,22 @@ def main(): if k == 1: logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after)) if j == 4: - logg.info("9800 timed out looking for WLC>,WLC#,User:,Password: i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after)) - logg.info("9800 send carriage return to see if get prompt back ") - egg.sendline(CR) - sleep(0.4) + logg.info("9800 timed out looking for WLC>,WLC#,User:,Password: loop_count {} i {} j {} before {} after {}".format(loop_count,i,j,egg.before,egg.after)) + logg.info("9800 Closing the connection and try to re-establish loop_count {} i {} j {}".format(loop_count,i,j)) + egg.close(force = True) + sleep(1) + #egg.close(force = True) + #sleep(0.2) + # re establish telnet + cmd = "telnet %s %d"%(host, port) + logg.info("Spawn: "+cmd+NL) + egg = pexpect.spawn(cmd) + egg.logfile = FileAdapter(logg) + time.sleep(0.1) + logged_in_9800 = False + loop_count = 0 + found_escape = False if i == 1: logg.info("9800 found WLC> will elevate loging i:{} before {} after {}".format(i,egg.before,egg.after)) @@ -578,34 +589,54 @@ def main(): logg.info("9800 Timed out waiting for # prompt i:{} j:{} k:{} before {} after {}".format(i,j,k,egg.before,egg.after)) if j == 4: logg.info("9800 timed out looking WLC>, WLC#, User:, Password: i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after)) - egg.sendline(CR) - sleep(0.1) + logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} j: {} before {} after {}".format(loop_count, i, j, egg.before,egg.after)) + logg.info("9800 Closing the connection and try to re-establish, ") + egg.close(force = True) + sleep(1) + #egg.close(force = True) + #sleep(0.2) + + # re establish telnet + cmd = "telnet %s %d"%(host, port) + logg.info("Spawn: "+cmd+NL) + egg = pexpect.spawn(cmd) + egg.logfile = FileAdapter(logg) + time.sleep(0.1) + logged_in_9800 = False + loop_count = 0 + found_escape = False if i == 6: logg.info("9800 recieved Bad secrets, to many password attempts i: {} before {} after {}".format(i, egg.before,egg.after)) egg.sendline(CR) sleep(0.2) if i == 7: - logg.info("9800 Timed out waiting for initial prompt send logout i: {} before {} after {}".format(i, egg.before,egg.after)) - egg.sendline(CR) - sleep(0.2) - r = 0 - while( r <= 120): - egg.expect(pexpect.TIMEOUT,timeout=0) - logg.info("Not seeing prompts r {} before {} after {}".format(r,egg.before,egg.after)) - egg.sendline("Hello?") - sleep(1) - loop_count += 1 + logg.info("9800 Timed out waiting for initial prompt send logout loop_count: {} i: {} before {} after {}".format(loop_count, i, egg.before,egg.after)) + logg.info("9800 Closing the connection and try to re-establish, ") + egg.close(force = True) + sleep(0.1) + #egg.close(force = True) + #sleep(0.2) + + # re establish telnet + cmd = "telnet %s %d"%(host, port) + logg.info("Spawn: "+cmd+NL) + egg = pexpect.spawn(cmd) + egg.logfile = FileAdapter(logg) + time.sleep(0.1) + logged_in_9800 = False + loop_count = 0 + found_escape = False if loop_count >= 3: if found_escape == True: logg.info("9800 there may be another prompt present that not aware of") logg.info("9800 will send escape to close telnet") r = 0 - while( r <= 120): + while( r <= 10): egg.expect(pexpect.TIMEOUT,timeout=0) logg.info("Not seeing prompts r {} before {} after {}".format(r,egg.before,egg.after)) egg.sendline("Hello?") - sleep(1) + sleep(3) egg.sendline("\x1b\r") logg.info("9800 the excape was found... close egg session") egg.close(force = True) From 736447f4d3654a3b9d162cad06b6c6c21b924a0a Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Wed, 30 Sep 2020 13:12:21 -0600 Subject: [PATCH 2/3] log fixes --- cisco_wifi_ctl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cisco_wifi_ctl.py b/cisco_wifi_ctl.py index e30c1a4c..8987a111 100755 --- a/cisco_wifi_ctl.py +++ b/cisco_wifi_ctl.py @@ -417,7 +417,7 @@ def main(): j = egg.expect_exact(["WLC>","WLC#","User:","Password:",pexpect.TIMEOUT],timeout=3) sleep(0.1) if j == 0: - logg.info("9800 found WLC# will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after)) + logg.info("9800 found WLC> will elevate loging i:{} j:{} before {} after {}".format(i,j,egg.before,egg.after)) egg.sendline("en") sleep(0.1) k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2) @@ -437,7 +437,7 @@ def main(): logg.info("9800 found # so logged in can start sending commands i:{} j:{}".format(i,j)) logged_in_9800 = True if j == 2: - logg.info("9800 found User\: will put in args.user {} i:{} j:{}".format(args.user,i,j)) + logg.info("9800 found User: will put in args.user {} i:{} j:{}".format(args.user,i,j)) egg.sendline(args.user) sleep(0.1) k = egg.expect_exact(["Password:",pexpect.TIMEOUT], timeout=2) From 9b0e8cfa39f67457b7cf6d264684040cd215a7a7 Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Wed, 30 Sep 2020 13:39:31 -0600 Subject: [PATCH 3/3] additional logging --- cisco_wifi_ctl.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cisco_wifi_ctl.py b/cisco_wifi_ctl.py index 8987a111..7743972b 100755 --- a/cisco_wifi_ctl.py +++ b/cisco_wifi_ctl.py @@ -398,6 +398,8 @@ def main(): #9800 series if args.series == "9800": while logged_in_9800 == False and loop_count <= 2: + logg.info("9800 establishing Telnet egg {} ".format(egg)) + sleep(5) egg.sendline(CR) sleep(3) try: