From 86744e5d81d189e5a6817e7863aafbdde2e02650 Mon Sep 17 00:00:00 2001 From: "s.mostryukov" Date: Sun, 22 Jun 2025 14:11:55 +0300 Subject: [PATCH] add debug connection in template --- app/backup.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/backup.py b/app/backup.py index cea50e1..492f7aa 100644 --- a/app/backup.py +++ b/app/backup.py @@ -83,7 +83,11 @@ def send_command(connection: ConnectHandler, command: str) -> str: except exceptions.NetmikoTimeoutException: result = "NetmikoTimeoutException" except exceptions.ReadTimeout: - result = "ReadTimeout" + try: + result: str = connection.send_command(command, read_timeout=cfg.net_dev.read_timeout) + log.info('the second time command send success') + except exceptions.ReadTimeout: + result = "ReadTimeout" return result @@ -105,7 +109,6 @@ def save_mikrotik_bcp(host: str, name: str) -> None: elif result == "ReadTimeout": log.warning("Timeout read config from %r", name) return - result = "\n".join(result.split("\n")[1:]) with open(os.path.join(cfg.bcp.dir, name), "w") as f: f.write(result) @@ -125,7 +128,10 @@ def save_snr_bcp(host: str, name: str) -> None: connection.disconnect() log.info("disconnected from %r", name) if result == "NetmikoTimeoutException": - log.warning("Timeout read config from %s", name) + log.warning("Timeout error %r", name) + return + elif result == "ReadTimeout": + log.warning("Timeout read config from %r", name) return with open(os.path.join(cfg.bcp.dir, name), "w") as f: f.write(result) @@ -145,7 +151,10 @@ def save_cisco_sb_bcp(host: str, name: str) -> None: connection.disconnect() log.info("disconnected from %s", name) if result == "NetmikoTimeoutException": - log.warning("Timeout read config from %s", name) + log.warning("Timeout error %r", name) + return + elif result == "ReadTimeout": + log.warning("Timeout read config from %r", name) return with open(os.path.join(cfg.bcp.dir, name), "w") as f: f.write(result) @@ -164,6 +173,9 @@ def save_cisco_bcp(host: str, name: str) -> None: connection.disconnect() log.info("disconnected from %r", name) if result == "NetmikoTimeoutException": + log.warning("Timeout error %r", name) + return + elif result == "ReadTimeout": log.warning("Timeout read config from %r", name) return with open(os.path.join(cfg.bcp.dir, name), "w") as f: