Enabled ability to run in dry
This commit is contained in:
@ -22,15 +22,18 @@ logger.addHandler(console_handler)
|
||||
class SystemHealthMonitor:
|
||||
def __init__(self,
|
||||
ticket_api_url: str = 'http://10.10.10.45/create_ticket_api.php',
|
||||
state_file: str = '/tmp/last_health_check.json'):
|
||||
state_file: str = '/tmp/last_health_check.json',
|
||||
dry_run: bool = False):
|
||||
"""
|
||||
Initialize the system health monitor.
|
||||
|
||||
:param ticket_api_url: URL for the ticket creation API.
|
||||
:param state_file: File path to track the last health check results.
|
||||
:param dry_run: If True, simulate API calls without sending requests.
|
||||
"""
|
||||
self.ticket_api_url = ticket_api_url
|
||||
self.state_file = state_file
|
||||
self.dry_run = dry_run
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
@ -126,7 +129,6 @@ class SystemHealthMonitor:
|
||||
print("No issues detected.")
|
||||
return
|
||||
|
||||
# Initialize default ticket fields
|
||||
hostname = socket.gethostname() # Get the current hostname
|
||||
action_type = "[auto]" # Default action type for automatic checks
|
||||
scope = "[cluster-wide]" # Scope of the issues
|
||||
@ -158,7 +160,6 @@ class SystemHealthMonitor:
|
||||
|
||||
# Create the ticket title with relevant details
|
||||
ticket_title = f"[{hostname}]{action_type}[{issue_type}] {issue} {scope}{environment}{ticket_type}"
|
||||
# Create a detailed description for the ticket
|
||||
description = self._generate_detailed_description(issue, health_report)
|
||||
|
||||
ticket_payload = {
|
||||
@ -170,19 +171,20 @@ class SystemHealthMonitor:
|
||||
"type": issue_type
|
||||
}
|
||||
|
||||
# Debug: Log the ticket payload being sent
|
||||
print("Attempting to create ticket with payload:")
|
||||
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))
|
||||
|
||||
# Attempt to create the ticket via the API
|
||||
else:
|
||||
# Perform actual API request
|
||||
try:
|
||||
response = requests.post(
|
||||
self.ticket_api_url,
|
||||
json=ticket_payload,
|
||||
headers={'Content-Type': 'application/json'}
|
||||
)
|
||||
|
||||
# Debug: Log the response from the server
|
||||
print(f"Response status code: {response.status_code}")
|
||||
print(f"Response body: {response.text}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user