add flush

This commit is contained in:
vvzvlad 2024-08-13 04:49:09 +03:00
parent d6cdee6fdb
commit 415eb2695b

View File

@ -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()