Updated title tags accordingly

This commit is contained in:
2024-12-05 21:14:12 -05:00
parent 0a51bee132
commit 883aee7390

View File

@ -117,49 +117,46 @@ class SystemHealthMonitor:
description += "\n" description += "\n"
return description return description
def _create_tickets_for_issues(self, health_report: Dict[str, Any]): def _create_tickets_for_issues(self, health_report: Dict[str, Any]):
""" """
Create tickets for detected issues with dynamic parameters based on severity. Create tickets for detected issues with standardized parameters.
:param health_report: The comprehensive health report from the checks.
""" """
issues = self._detect_issues(health_report) issues = self._detect_issues(health_report)
if not issues: if not issues:
logger.info("No issues detected.") logger.info("No issues detected.")
return return
hostname = socket.gethostname() # Get the current hostname hostname = socket.gethostname()
action_type = "[auto]" # Default action type for automatic checks action_type = "[auto]"
scope = "[cluster-wide]" # Scope of the issues environment = "[production]"
environment = "[production]" # Environment where the issues were found ticket_type = "[maintenance]"
ticket_type = "[maintenance]" # Type of the ticket being created
for issue in issues: for issue in issues:
# Determine priority, category, and type based on the issue detected # Set default values
priority = "4" # Default to low priority priority = "P4"
category = "Other" category = "Hardware"
issue_type = "Task" issue_type = "Problem"
scope = "[single-node]"
if "Disk" in issue: if "Disk" in issue:
priority = "3" # Medium priority for disk issues hardware_type = "[hardware]"
category = "Hardware" if "CRITICAL" in issue or "SMART failure" in issue:
issue_type = "Incident" priority = "P2"
elif "WARNING" in issue:
priority = "P3"
elif "Memory" in issue: elif "Memory" in issue:
priority = "4" # Low priority for memory issues hardware_type = "[hardware]"
category = "Hardware" priority = "P3"
issue_type = "Incident"
elif "CPU" in issue: elif "CPU" in issue:
priority = "4" # Low priority for CPU issues hardware_type = "[hardware]"
category = "Hardware" priority = "P3"
issue_type = "Incident" elif "Network" in issue:
elif "issues" in issue: # Any network issues hardware_type = "[network]"
priority = "2" # High priority for network issues priority = "P2"
category = "Network" scope = "[cluster-wide]"
issue_type = "Problem"
# Create the ticket title with relevant details # Create standardized ticket title
ticket_title = f"[{hostname}]{action_type}[{issue_type}] {issue} {scope}{environment}{ticket_type}" ticket_title = f"[{hostname}]{action_type}{hardware_type} {issue} {scope}{environment}{ticket_type}"
description = self._generate_detailed_description(issue, health_report) description = self._generate_detailed_description(issue, health_report)
ticket_payload = { ticket_payload = {
@ -172,30 +169,27 @@ class SystemHealthMonitor:
} }
if self.dry_run: 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("Dry-run mode enabled. Simulating ticket creation:")
logger.info(json.dumps(ticket_payload, indent=4)) logger.info(json.dumps(ticket_payload, indent=4))
print("Dry-run: Ticket payload:") print("Dry-run: Ticket payload:")
print(json.dumps(ticket_payload, indent=4)) print(json.dumps(ticket_payload, indent=4))
else: else:
# Perform actual API request
try: try:
response = requests.post( response = requests.post(
self.ticket_api_url, self.ticket_api_url,
json=ticket_payload, json=ticket_payload,
headers={'Content-Type': 'application/json'} headers={'Content-Type': 'application/json'}
) )
print(f"Response status code: {response.status_code}") logger.info(f"Response status code: {response.status_code}")
print(f"Response body: {response.text}") logger.info(f"Response body: {response.text}")
if response.status_code in [200, 201]: if response.status_code in [200, 201]:
print(f"Ticket created successfully: {ticket_title}") logger.info(f"Ticket created successfully: {ticket_title}")
else: else:
print(f"Failed to create ticket. Status code: {response.status_code}") logger.error(f"Failed to create ticket. Status code: {response.status_code}")
print(f"Response: {response.text}") logger.error(f"Response: {response.text}")
except Exception as e: 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]: def _detect_issues(self, health_report: Dict[str, Any]) -> List[str]:
""" """
Detect issues in the health report including non-critical issues. Detect issues in the health report including non-critical issues.