From 415eb2695bca9a6c5b35936bda347a295d7b9f96 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Tue, 13 Aug 2024 04:49:09 +0300 Subject: [PATCH] add flush --- shutdown_ups.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shutdown_ups.py b/shutdown_ups.py index 739d0a6..850c9f3 100644 --- a/shutdown_ups.py +++ b/shutdown_ups.py @@ -49,13 +49,13 @@ def main(): result = run_command(f'/usr/bin/snmpget -v2c -O v -O q -c public {ups_ip} {oid_states}') state = parse_states(result.strip('"')) - print(f"Time on battery: {time_on_battery} minutes, State: {state}") + print(f"Time on battery: {time_on_battery} minutes, State: {state}", flush=True) if time_on_battery != False and time_on_battery < time_threshold: if state == "on-battery": shutdown_status = run_command('shutdown --show 2>&1') if "No scheduled shutdown" in shutdown_status: - print("UPS is failing, shutting down in 60 seconds...") + 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...", f"{socket.gethostname()}@vvzvlad.xyz") run_command('sudo shutdown -h 1 "Shutting down due to UPS failure"') @@ -65,6 +65,6 @@ def main(): time.sleep(interval) if __name__ == "__main__": - print("Starting UPS monitoring...") + print("Starting UPS monitoring...", flush=True) main() \ No newline at end of file