From 883aee7390b5cc758707966a5e7efcaf39bcaa23 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Dec 2024 21:14:12 -0500 Subject: [PATCH] Updated title tags accordingly --- hwmonDaemon.py | 68 +++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index ad61a73..4d53a97 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -117,49 +117,46 @@ class SystemHealthMonitor: description += "\n" return description - def _create_tickets_for_issues(self, health_report: Dict[str, Any]): """ - Create tickets for detected issues with dynamic parameters based on severity. - - :param health_report: The comprehensive health report from the checks. + Create tickets for detected issues with standardized parameters. """ issues = self._detect_issues(health_report) if not issues: logger.info("No issues detected.") return - hostname = socket.gethostname() # Get the current hostname - action_type = "[auto]" # Default action type for automatic checks - scope = "[cluster-wide]" # Scope of the issues - environment = "[production]" # Environment where the issues were found - ticket_type = "[maintenance]" # Type of the ticket being created + hostname = socket.gethostname() + action_type = "[auto]" + environment = "[production]" + ticket_type = "[maintenance]" for issue in issues: - # Determine priority, category, and type based on the issue detected - priority = "4" # Default to low priority - category = "Other" - issue_type = "Task" + # Set default values + priority = "P4" + category = "Hardware" + issue_type = "Problem" + scope = "[single-node]" if "Disk" in issue: - priority = "3" # Medium priority for disk issues - category = "Hardware" - issue_type = "Incident" + hardware_type = "[hardware]" + if "CRITICAL" in issue or "SMART failure" in issue: + priority = "P2" + elif "WARNING" in issue: + priority = "P3" elif "Memory" in issue: - priority = "4" # Low priority for memory issues - category = "Hardware" - issue_type = "Incident" + hardware_type = "[hardware]" + priority = "P3" elif "CPU" in issue: - priority = "4" # Low priority for CPU issues - category = "Hardware" - issue_type = "Incident" - elif "issues" in issue: # Any network issues - priority = "2" # High priority for network issues - category = "Network" - issue_type = "Problem" + hardware_type = "[hardware]" + priority = "P3" + elif "Network" in issue: + hardware_type = "[network]" + priority = "P2" + scope = "[cluster-wide]" - # Create the ticket title with relevant details - ticket_title = f"[{hostname}]{action_type}[{issue_type}] {issue} {scope}{environment}{ticket_type}" + # Create standardized ticket title + ticket_title = f"[{hostname}]{action_type}{hardware_type} {issue} {scope}{environment}{ticket_type}" description = self._generate_detailed_description(issue, health_report) ticket_payload = { @@ -172,30 +169,27 @@ class SystemHealthMonitor: } if self.dry_run: - # Dry-run mode: log the payload instead of sending it logger.info("Dry-run mode enabled. Simulating ticket creation:") logger.info(json.dumps(ticket_payload, indent=4)) print("Dry-run: Ticket payload:") print(json.dumps(ticket_payload, indent=4)) else: - # Perform actual API request try: response = requests.post( self.ticket_api_url, json=ticket_payload, headers={'Content-Type': 'application/json'} ) - print(f"Response status code: {response.status_code}") - print(f"Response body: {response.text}") + logger.info(f"Response status code: {response.status_code}") + logger.info(f"Response body: {response.text}") if response.status_code in [200, 201]: - print(f"Ticket created successfully: {ticket_title}") + logger.info(f"Ticket created successfully: {ticket_title}") else: - print(f"Failed to create ticket. Status code: {response.status_code}") - print(f"Response: {response.text}") + logger.error(f"Failed to create ticket. Status code: {response.status_code}") + logger.error(f"Response: {response.text}") except Exception as e: - print(f"Error creating ticket: {e}") - + logger.error(f"Error creating ticket: {e}") def _detect_issues(self, health_report: Dict[str, Any]) -> List[str]: """ Detect issues in the health report including non-critical issues.