Skip to content

Commit 1a221bb

Browse files
committed
Minor improvements
1 parent ddc536e commit 1a221bb

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lxc_autoscale/notification.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def send_notification(self, title: str, message: str, priority: int = 5):
3737
headers = {'X-Gotify-Key': self.token}
3838

3939
try:
40-
response = requests.post(f"{self.url}/message", data=payload, headers=headers)
40+
response = requests.post(f"{self.url}/message", json=payload, headers=headers, timeout=10)
4141
response.raise_for_status()
4242
logging.info(f"Gotify notification sent: {title} - {message}")
43-
except requests.exceptions.RequestException as e:
43+
except Exception as e:
4444
logging.error(f"Gotify notification failed: {e}")
4545

4646
# Email notification implementation
@@ -71,7 +71,7 @@ def send_notification(self, title: str, message: str, priority: int = 5):
7171
msg['To'] = ', '.join(self.to_addrs)
7272

7373
try:
74-
with smtplib.SMTP(self.smtp_server, self.port) as server:
74+
with smtplib.SMTP(self.smtp_server, self.port, timeout=10) as server:
7575
server.starttls() # Encrypt the connection
7676
server.login(self.username, self.password) # Authenticate with the SMTP server
7777
server.sendmail(self.from_addr, self.to_addrs, msg.as_string()) # Send the email
@@ -97,13 +97,11 @@ def send_notification(self, title: str, message: str, priority: int = 5):
9797
priority (int): Unused, but kept for interface consistency.
9898
"""
9999
try:
100-
response = requests.get(self.webhook_url)
101-
if response.status_code == 200:
102-
logging.info("Uptime Kuma notification sent successfully")
103-
else:
104-
logging.error(f"Failed to send Uptime Kuma notification: {response.status_code}")
100+
response = requests.post(self.webhook_url, json={'title': title, 'message': message, 'priority': priority}, timeout=10)
101+
response.raise_for_status()
102+
logging.info("Uptime Kuma notification sent successfully")
105103
except Exception as e:
106-
logging.error(f"Error sending Uptime Kuma notification: {e}")
104+
logging.error(f"Failed to send Uptime Kuma notification: {e}")
107105

108106
# Send notification to all initialized notifiers
109107
def send_notification(title, message, priority=5):

lxc_autoscale/scaling_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def scale_memory(ctid: str, mem_usage: float, mem_upper: float, mem_lower: float
9898
int((mem_usage - mem_upper) * config['memory_min_increment'] / MEMORY_SCALE_FACTOR),
9999
)
100100
if available_memory >= increment:
101-
logging.info(f"Increasing memory for container {ctid} by {increment}MB (current: {current_memory}MB, new: {new_memory}MB)")
102101
new_memory = current_memory + increment
102+
logging.info(f"Increasing memory for container {ctid} by {increment}MB (current: {current_memory}MB, new: {new_memory}MB)")
103103
run_command(f"pct set {ctid} -memory {new_memory}")
104104
available_memory -= increment
105105
memory_changed = True
@@ -115,8 +115,8 @@ def scale_memory(ctid: str, mem_usage: float, mem_upper: float, mem_lower: float
115115
min_memory,
116116
)
117117
if decrease_amount > 0:
118-
logging.info(f"Decreasing memory for container {ctid} by {decrease_amount}MB (current: {current_memory}MB, new: {new_memory}MB)")
119118
new_memory = current_memory - decrease_amount
119+
logging.info(f"Decreasing memory for container {ctid} by {decrease_amount}MB (current: {current_memory}MB, new: {new_memory}MB)")
120120
run_command(f"pct set {ctid} -memory {new_memory}")
121121
available_memory += decrease_amount
122122
memory_changed = True

0 commit comments

Comments
 (0)