mirror of
https://github.com/unixtensor/proxmox-ntfy.git
synced 2025-06-28 13:28:05 +00:00
Ntfy headers
This commit is contained in:
16
src/cpu.py
16
src/cpu.py
@ -10,11 +10,11 @@ from ntfy import Ntfy
|
||||
last_cpu_check_warning: float = time.time()
|
||||
|
||||
class Tempature:
|
||||
cpu_temp_warning_message: str = "🌡️ CPU is at a high tempature."
|
||||
cpu_temp_queue_check: int = 120 # Seconds
|
||||
warning_message: str = "🌡️ CPU is at a high tempature."
|
||||
timeout_check: int = 180 # Seconds
|
||||
|
||||
def __init__(self, ntfy_instance: Ntfy, cpu_warning_temp: int):
|
||||
self.cpu_warning_temp = cpu_warning_temp
|
||||
def __init__(self, ntfy_instance: Ntfy, warning_temp: int):
|
||||
self.warning_temp = warning_temp
|
||||
self.ntfy = ntfy_instance
|
||||
|
||||
def get(self) -> Optional[float]:
|
||||
@ -26,14 +26,14 @@ class Tempature:
|
||||
return float(match.group(1))
|
||||
return None
|
||||
|
||||
def __queue_time(self, last_check: float) -> bool:
|
||||
return (time.time() - last_check) > Tempature.cpu_temp_queue_check * 1000
|
||||
def __timeout_expired(self, last_check: float) -> bool:
|
||||
return (time.time() - last_check) > Tempature.timeout_check * 1000
|
||||
|
||||
def ntfy_check(self):
|
||||
cpu_temp = self.get()
|
||||
if cpu_temp:
|
||||
cpu_temp = math.floor(cpu_temp)
|
||||
if cpu_temp >= self.cpu_warning_temp and self.__queue_time(last_cpu_check_warning):
|
||||
self.ntfy.send(f"{Tempature.cpu_temp_warning_message} {cpu_temp} C")
|
||||
if cpu_temp >= self.warning_temp and self.__timeout_expired(last_cpu_check_warning):
|
||||
self.ntfy.send(f"{Tempature.warning_message} {cpu_temp} C")
|
||||
else:
|
||||
print_t("\033[31mCannot get a feasible tempature value for the CPU. (lm-sensors)\033[0m")
|
||||
|
Reference in New Issue
Block a user