mirror of
https://github.com/unixtensor/proxmox-ntfy.git
synced 2025-06-28 03:28:05 +00:00
Use requests
module instead of curl and use python3 main.py server.com
instead of --server=server.com
This commit is contained in:
@ -2,7 +2,6 @@ import argparse
|
|||||||
|
|
||||||
def interface():
|
def interface():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--server", required=True, help="")
|
|
||||||
parser.add_argument("--cpu-temp-critical", type=int, default=80, help="cpu tempature crtitical. default = 80")
|
parser.add_argument("--cpu-temp-critical", type=int, default=80, help="cpu tempature crtitical. default = 80")
|
||||||
parser.add_argument("--cpu-temp-warning", type=int, default=70, help="cpu tempature warning. default = 70")
|
parser.add_argument("--cpu-temp-warning", type=int, default=70, help="cpu tempature warning. default = 70")
|
||||||
parser.add_argument("--update-rate", type=int, default=1, help="how often updates happen in seconds. default = 1")
|
parser.add_argument("--update-rate", type=int, default=1, help="how often updates happen in seconds. default = 1")
|
||||||
|
25
src/main.py
25
src/main.py
@ -1,4 +1,5 @@
|
|||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
import package
|
import package
|
||||||
import cli
|
import cli
|
||||||
@ -6,6 +7,11 @@ import cpu
|
|||||||
|
|
||||||
from ntfy import Ntfy
|
from ntfy import Ntfy
|
||||||
|
|
||||||
|
_ntfy_configure_prompt = """\033[4mPlease configure an ntfy url before starting.\033[0m
|
||||||
|
Examples:
|
||||||
|
\033[32mpython3 main.py 10.0.13.37:42069
|
||||||
|
python3 main.py ntfy.domain.com\033[0m"""
|
||||||
|
|
||||||
def start(
|
def start(
|
||||||
cpu_critical_temp: int,
|
cpu_critical_temp: int,
|
||||||
cpu_warning_temp: int,
|
cpu_warning_temp: int,
|
||||||
@ -23,11 +29,14 @@ def start(
|
|||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if package.installed_list(["lm-sensors", "ntfy", "curl"]):
|
if package.installed("lm-sensors"):
|
||||||
cli_args = cli.interface()
|
if len(sys.argv) > 1:
|
||||||
start(
|
cli_args = cli.interface()
|
||||||
cli_args.cpu_temp_critical,
|
start(
|
||||||
cli_args.cpu_temp_warning,
|
cli_args.cpu_temp_critical,
|
||||||
cli_args.server,
|
cli_args.cpu_temp_warning,
|
||||||
cli_args.update_rate,
|
sys.argv[1],
|
||||||
)
|
cli_args.update_rate,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(_ntfy_configure_prompt)
|
@ -1,4 +1,4 @@
|
|||||||
import subprocess
|
import requests
|
||||||
|
|
||||||
class Ntfy:
|
class Ntfy:
|
||||||
def __init__(self, server: str):
|
def __init__(self, server: str):
|
||||||
@ -6,6 +6,6 @@ class Ntfy:
|
|||||||
|
|
||||||
def send(self, message: str):
|
def send(self, message: str):
|
||||||
try:
|
try:
|
||||||
subprocess.run(["curl", "-d", f"\"{message}\"", self.server], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
requests.post(self.server, data=message)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Ntfy failed. {err}")
|
print(f"Ntfy failed. {err}")
|
||||||
|
@ -10,10 +10,4 @@ def installed(package_name: str) -> Optional[bool]:
|
|||||||
return installed
|
return installed
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(err)
|
print(err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def installed_list(package_name_list: list[str]) -> bool:
|
|
||||||
for pkg_name in package_name_list:
|
|
||||||
if not installed(pkg_name):
|
|
||||||
return False
|
|
||||||
return True
|
|
Reference in New Issue
Block a user