bitwarden

This commit is contained in:
jaydee
2024-06-27 00:19:16 +02:00
parent 4d19b05594
commit 6e3ad23eec
6 changed files with 53 additions and 39 deletions

View File

@ -1,12 +1,7 @@
#!/usr/bin/env python3
from asyncio.log import logger
import paho.mqtt
import paho.mqtt.client as mqttClient
if paho.mqtt.__version__[0] > '1':
client = mqttClient.Client(mqttClient.CallbackAPIVersion.VERSION1)
else:
client = mqttClient.Client()
import paho.mqtt.client as mqtt
from getmac import get_mac_address
import platform
import socket
@ -24,7 +19,7 @@ import random
import requests
#import psutil
stats = {}
VERSION = "1.0.26"
VERSION = "1.0.27"
curos = platform.system()
host = platform.node().lower()
print(host)
@ -243,10 +238,7 @@ if _PUBLISH:
else:
print("Failed to connect, return code %d\n", rc)
if paho.mqtt.__version__[0] > '1':
client = mqttClient.Client(mqttClient.CallbackAPIVersion.VERSION1)
else:
client = mqttClient.Client()
client = mqtt.Client(client_id)
client.username_pw_set(username, password)
client.on_connect = on_connect
client.connect(MQTT_HOST, MQTT_PORT)
@ -876,8 +868,11 @@ def on_message(client, userdata, msg):
else:
if host == "nas" or host == "octopi":
subprocess.Popen(["/sbin/poweroff"])
elif host == "openmediavault" or host == "omv":
elif host == "openmediavault" or host == "omv" or host == "amd" or host == "ryzen":
subprocess.Popen(["poweroff"])
elif host == "amd" or host == "ryzen":
subprocess.Popen(["systemctl suspend"])
else:
#subprocess.Popen(["/bin/systemctl", "suspend", "-i"])
#subprocess.Popen(["sudo", "pm-suspend"])
@ -932,10 +927,7 @@ def on_message(client, userdata, msg):
except:
print("not a json!")
if paho.mqtt.__version__[0] > '1':
client = mqttClient.Client(mqttClient.CallbackAPIVersion.VERSION1)
else:
client = mqttClient.Client()
client = mqtt.Client()
payload = '{"status": "off"}'
client.username_pw_set("jaydee", password="jaydee1")
client.will_set("home-assistant/" + host.lower() + "/hwstats", payload=payload, qos=0, retain=True)
@ -1065,7 +1057,8 @@ else:
NEXT_CHECK = int(time.time()) + 20
writeLog("Blalala : Next : " + str(NEXT_CHECK))
if host.lower() == "asus" or host.lower() == "morefine":
if host.lower() == "asus" or host.lower() == "morefine" or host.lower() == "ryzen":
writeLog("Blalala : AAA")
print(psutil.sensors_temperatures())
#print(psutil.sensors_fans())
sences = psutil.sensors_temperatures()
@ -1079,19 +1072,25 @@ else:
cpu_data = sences["k10temp"][0]
except:
cpu_data = "None"
writeLog(cpu_data)
print("CPUDATA")
print(cpu_data)
print("#"*40)
mb_data = sences["acpitz"][0]
print("MBDATA")
print(mb_data)
print(mb_data.current)
try:
mb_data = sences["acpitz"][0]
print(mb_data)
print(mb_data.current)
mb_data = mb_data.current
except:
mb_data = 0
print("#"*40)
try:
print(psutil.sensors_fans())
fan_data = psutil.sensors_fans()["asus"][0].current
except:
fan_data = "None"
@ -1115,7 +1114,8 @@ else:
#print(str(jn1["coretemp-isa-0000"]["Package id 0"]["temp1_input"]))
#print(str(jn1["asus-isa-0000"]["cpu_fan"]["fan1_input"]))
#client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False)
client.publish("home-assistant/" + host + "/hwstats", payload='{"status":"on", "version":"' + VERSION + '","TCPU":"NA", "MB_TEMP":' + str(mb_data.current) + ', "MEM_UTIL":' + str(mem_data.percent) + ', "CPU_TEMP":' + str(cpu_data.current) + ', "GPU_TEMP":0, "GPU_UTIL":0, "FAN_CPU":"' + str(fan_data) + '", "VMEM_UTIL":' + str(swap_data.percent) + ', "CPU_UTIL":' + str(cpu_usage) + '}', qos=0, retain=False)
writeLog('{"status":"on", "version":"' + VERSION + '","TCPU":"NA", "MB_TEMP":' + str(mb_data) + ', "MEM_UTIL":' + str(mem_data.percent) + ', "CPU_TEMP":' + str(cpu_data.current) + ', "GPU_TEMP":0, "GPU_UTIL":0, "FAN_CPU":"' + str(fan_data) + '", "VMEM_UTIL":' + str(swap_data.percent) + ', "CPU_UTIL":' + str(cpu_usage) + '}')
client.publish("home-assistant/" + host + "/hwstats", payload='{"status":"on", "version":"' + VERSION + '","TCPU":"NA", "MB_TEMP":' + str(mb_data) + ', "MEM_UTIL":' + str(mem_data.percent) + ', "CPU_TEMP":' + str(cpu_data.current) + ', "GPU_TEMP":0, "GPU_UTIL":0, "FAN_CPU":"' + str(fan_data) + '", "VMEM_UTIL":' + str(swap_data.percent) + ', "CPU_UTIL":' + str(cpu_usage) + '}', qos=0, retain=False)
client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
elif host.lower() == "openmediavault" or host.lower() == "omv":
#print(psutil.sensors_temperatures())