add flush
This commit is contained in:
parent
d6cdee6fdb
commit
415eb2695b
@ -49,13 +49,13 @@ def main():
|
|||||||
result = run_command(f'/usr/bin/snmpget -v2c -O v -O q -c public {ups_ip} {oid_states}')
|
result = run_command(f'/usr/bin/snmpget -v2c -O v -O q -c public {ups_ip} {oid_states}')
|
||||||
state = parse_states(result.strip('"'))
|
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 time_on_battery != False and time_on_battery < time_threshold:
|
||||||
if state == "on-battery":
|
if state == "on-battery":
|
||||||
shutdown_status = run_command('shutdown --show 2>&1')
|
shutdown_status = run_command('shutdown --show 2>&1')
|
||||||
if "No scheduled shutdown" in shutdown_status:
|
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")
|
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"')
|
run_command('sudo shutdown -h 1 "Shutting down due to UPS failure"')
|
||||||
|
|
||||||
@ -65,6 +65,6 @@ def main():
|
|||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Starting UPS monitoring...")
|
print("Starting UPS monitoring...", flush=True)
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user