from netmiko import ConnectHandler import logging LOG = logging.getLogger("healthcheck") def configure_logging(): LOG.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) file_handler = logging.FileHandler("healthcheck.log") file_handler.setLevel(logging.DEBUG) file_handler.setFormatter(formatter) stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) stream_handler.setFormatter(formatter) LOG.addHandler(file_handler) LOG.addHandler(stream_handler) <...output omitted ...> def main() -> None: configure_logging() for dev in DEVICES: output = check_device(dev) print(output) print("Health check complete") <...output omitted ...> <...output omitted ...> def main() -> None: configure_logging() for dev in DEVICES: check_device(dev) LOG.info("Health check complete") <...output omitted ...> <...output omitted ...> def check_device(device: dict): LOG.debug(f"Connecting to {device['host']}") conn = ConnectHandler(**device) output = conn.send_command("show ip interfaces brief") LOG.debug(f"Device output: {output}") conn.disconnect() <...output omitted ...> <...output omitted ...> def check_device(device: dict): LOG.debug(f"Connecting to {device['host']}") try: conn = ConnectHandler(**device) output = conn.send_command("show ip interfaces brief") LOG.debug(f"Device output: {output}") conn.disconnect() except NetmikoTimeoutException as e: LOG.error(f"Timeout Error: {str(e)}") from netmiko import ConnectHandler import logging from netmiko.exceptions import NetmikoTimeoutException, NetmikoAuthenticationException <...output omitted ...> <...output omitted ...> def check_device(device: dict): LOG.debug(f"Connecting to {device['host']}") try: conn = ConnectHandler(**device) output = conn.send_command("show ip interfaces brief") LOG.debug(f"Device output: {output}") conn.disconnect() except NetmikoTimeoutException as e: LOG.error(f"Timeout Error: {str(e)}") except NetmikoAuthenticationException as e: LOG.error(f"Authentication Error: {str(e)}") except Exception as e: LOG.error(f"Unexpected error: {str(e)}") <...output omitted ...>