From 572bb5e38608b346facb29392fd6bfe9ec86b699 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Dec 2024 20:39:10 -0500 Subject: [PATCH] adjusted parser to enable dry mode --- hwmonDaemon.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 4953547..25276ba 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -import os, sys, json, requests, psutil, socket, subprocess, logging +import os, sys, json, requests, psutil, socket, subprocess, logging, argparse, urllib.request from typing import Dict, Any, List # Create a logger @@ -126,7 +126,7 @@ class SystemHealthMonitor: """ issues = self._detect_issues(health_report) if not issues: - print("No issues detected.") + logger.info("No issues detected.") return hostname = socket.gethostname() # Get the current hostname @@ -384,19 +384,25 @@ def main(): # Run the health checks monitor.run() - # Check network health asynchronously - network_health = asyncio.run(monitor._check_network_status()) - print(f"Network health: {network_health}") - - except KeyboardInterrupt: - # Handle KeyboardInterrupt gracefully - print("Interrupted by user. Exiting...") - sys.exit(0) + # Check network health synchronously + network_health = monitor._check_network_status() + logger.info(f"Network health: {network_health}") except Exception as e: - # Handle other exceptions - print(f"An unexpected error occurred: {e}") + logger.error(f"An unexpected error occurred: {e}") sys.exit(1) if __name__ == "__main__": + # Argument parser for CLI options + parser = argparse.ArgumentParser(description="System Health Monitor") + parser.add_argument( + "--dry-run", + action="store_true", + help="Enable dry-run mode (simulate ticket creation without actual API calls)." + ) + args = parser.parse_args() + + # Set dry-run mode if specified + dry_run_mode = args.dry_run + main() \ No newline at end of file