From c0ce86873ee866f0afd441b1fe2bc05a63b485c4 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Tue, 13 Aug 2024 04:39:38 +0300 Subject: [PATCH] unfix --- shutdown_ups.py | 18 +++++++----------- ups_shutdown.service | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/shutdown_ups.py b/shutdown_ups.py index e9aa4b3..63a63bd 100644 --- a/shutdown_ups.py +++ b/shutdown_ups.py @@ -3,7 +3,10 @@ import time import requests import socket import os -import sys + +ups_ip = "10.31.41.46" +time_threshold = 4 +interval = 20 def parse_time(time_str): try: @@ -35,7 +38,7 @@ def run_command(command): result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) return result.stdout.strip() -def main(ups_ip, time_threshold, interval): +def main(): print("Starting UPS monitoring...") while True: oid_on_battery_time = "1.3.6.1.4.1.318.1.1.1.2.2.3.0" @@ -62,12 +65,5 @@ def main(ups_ip, time_threshold, interval): time.sleep(interval) if __name__ == "__main__": - if len(sys.argv) != 4: - print("Usage: script.py ") - sys.exit(1) - - ups_ip = sys.argv[1] - time_threshold = int(sys.argv[2]) - interval = int(sys.argv[3]) - - main(ups_ip, time_threshold, interval) + main() + \ No newline at end of file diff --git a/ups_shutdown.service b/ups_shutdown.service index 26ebffe..a4b8bfd 100644 --- a/ups_shutdown.service +++ b/ups_shutdown.service @@ -3,7 +3,7 @@ Description=Service to manage UPS shutdown script After=network.target [Service] -ExecStart=/usr/bin/python3 /usr/local/bin/shutdown_ups.py 10.31.41.46 4 20 +ExecStart=/usr/bin/python3 /usr/local/bin/shutdown_ups.py Restart=always RestartSec=5s