From 589b89416506806ed5a324926be2e72ec1c87ca8 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Tue, 13 Aug 2024 19:32:32 +0300 Subject: [PATCH] tiny fix --- shutdown_ups.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/shutdown_ups.py b/shutdown_ups.py index 42d3d7e..bf29d7b 100644 --- a/shutdown_ups.py +++ b/shutdown_ups.py @@ -6,7 +6,9 @@ import socket import os UPS_IP = "10.31.41.46" -TIME_THRESHOLD = 6 +TIME_THRESHOLD = 7 +SHUTDOWN_DELAY = 2 + INTERVAL_LINE = 60 INTERVAL_BATTERY = 5 OID_ON_BATTERY_TIME = "1.3.6.1.4.1.318.1.1.1.2.2.3.0" @@ -88,16 +90,16 @@ def main(): if result is None: continue battery_percent = int(result) - print(f"Batterry {battery_percent}%, {state}, estimated time on battery: {time_on_battery} minutes", flush=True) + print(f"Batterry {battery_percent}%, {state}, estimated time on battery: {time_on_battery} minute (treshhold {TIME_THRESHOLD})", flush=True) shutdown_status = run_command('shutdown --show') if (state == "on-battery") and (time_on_battery < TIME_THRESHOLD) and ("No scheduled shutdown" in shutdown_status): - print("UPS is failing, shutting down in 60 seconds...", flush=True) - send_email(f"{socket.gethostname()}@vvzvlad.xyz", "UPS is failing, shutting down in 60 seconds...", - f"Proxmox node '{socket.gethostname()}': UPS is failing, shutting down in 60 seconds...", + print(f"UPS is failing, shutting down in {SHUTDOWN_DELAY} min...", flush=True) + send_email(f"{socket.gethostname()}@vvzvlad.xyz", "UPS is failing, shutting down in {SHUTDOWN_DELAY} min.", + f"Proxmox node '{socket.gethostname()}': UPS is failing, shutting down in {SHUTDOWN_DELAY} min, 'shutdown -c' to cancel", f"{socket.gethostname()}@vvzvlad.xyz") - run_command('shutdown -h 3 "Shutting down due to UPS failure"') + run_command(f'shutdown -h {SHUTDOWN_DELAY} "Shutting down due to UPS failure"') if (state == "on-line") and ("Shutdown scheduled" in shutdown_status): print("UPS is back online, cancelling shutdown...", flush=True)