From 7c748b1dff27b4076c6b2fae07ec7a8b9c3c2770 Mon Sep 17 00:00:00 2001 From: jaydee Date: Mon, 24 Feb 2025 01:06:18 +0100 Subject: [PATCH] lala --- mqtt_srv.py | 107 +++++++++++++++------ mqtt_srv.pyw | 262 ++++++++++++++++++++++++--------------------------- 2 files changed, 203 insertions(+), 166 deletions(-) diff --git a/mqtt_srv.py b/mqtt_srv.py index fba00a4..54c4ec8 100755 --- a/mqtt_srv.py +++ b/mqtt_srv.py @@ -17,7 +17,7 @@ import ctypes import getopt import random import requests - +import shutil if os.path.exists("/etc/mqtt_srv/mqtt_srv.cfg"): with open("/etc/mqtt_srv/mqtt_srv.cfg") as json_file: @@ -28,7 +28,7 @@ else: #import psutil stats = {} -VERSION = "1.0.36" +VERSION = "1.0.37" curos = platform.system() host = platform.node().lower().replace(".home.lan","") @@ -74,14 +74,19 @@ def uptime(): string += str(seconds) return string; - +ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S") +if curos == "Windows": + log_path = "c:\\Program Files\\jaydee\\jaydee.log" +else: + log_path = "/tmp/mqtt_srv.log" + +if os.path.exists(log_path): + shutil.move(log_path, log_path + "." + ts2) def writeLog(msg, svr="INFO"): ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - - if curos == "Windows": - log_path = "c:\\Program Files\\jaydee\\jaydee.log" - else: - log_path = "/tmp/mqtt_srv.log" + ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + f = open(log_path, "a") f.write(ts + " | " + svr + " | " + str(msg) + "\n") f.close() @@ -654,8 +659,8 @@ def on_message(client, userdata, msg): # os.startfile(sys.argv[0]) #sys.exit() myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc' - print(myCmd) writeLog(myCmd) + subprocess.Popen(myCmd.split()) if myObj["cmd"] == "getstats": print("lalaa1") @@ -667,19 +672,43 @@ def on_message(client, userdata, msg): 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) print("lalaa2") - + if myObj["cmd"] == "openrgb": + myCmd = 'powershell.exe -windowstyle hidden -command Stop-ScheduledTask -TaskName "jaydee\OpenRGB"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + time.sleep(2) + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\OpenRGB"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + if myObj["cmd"] == "hyperion": + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperion"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + if myObj["cmd"] == "hyperiond": + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperiond"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + if myObj["cmd"] == "assist": + if myObj['target'] == "start": + myCmd =f"powershell c:\\Users\\jd\Documents\\volume.ps1 10" + else: + myCmd =f"powershell c:\\Users\\jd\\Documents\\volume.ps1 100" + output = subprocess.Popen(myCmd, shell=True) if myObj["cmd"] == "display": - if curos == "Windows1": + if curos == "Windows": # os.startfile(sys.argv[0]) #sys.exit() #print("reconfigure") - myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml' + #myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml' + + myCmd =f"powershell -w h -command \" Import-Module DisplayConfig ; Import-Clixml $home\monitors\{myObj['target']}.xml | Use-DisplayConfig -UpdateAdapterIds \"" writeLog(myCmd) - #writeLog(os.path.realpath(__file__)) - print("lalaa2") - #subprocess.Popen(r'"{}"'.format(myCmd), shell=True) - print("lalaa3") - subprocess.Popen(myCmd.split(), shell=True,cwd=r'c:\Progra~1\jaydee') + #myCmd = f"MultiMonitorTool.exe /LoadConfig \"c:\\Program Files\\jaydee\\Monitors\\{myObj["target"]}.cfg\"" + #writeLog(myCmd) + #print(myCmd) + output = subprocess.Popen(myCmd, shell=True) + #output = subprocess.Popen(myCmd.split()) + writeLog(output) else: ''' myCmd = "" @@ -706,7 +735,7 @@ def on_message(client, userdata, msg): ''' myCmd = "" writeLog(myObj["target"]) - if curos == "Windows": + if curos == "Windows1": myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"]) @@ -813,8 +842,9 @@ def on_message(client, userdata, msg): if myObj["cmd"] == "suspend": writeLog("suspending") if curos == "Windows": - if host == "amd" or host == "amd1": - os.system("shutdown /s /t 1") + if host == "amd" or host == "amd1" or host == "morefine": + #os.system("shutdown /s /t 1") + os.system("shutdown /h") else: os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") #cmnd = "psshutdown -d -t 1" @@ -936,16 +966,13 @@ if curos == "Windows": client.loop_start() NEXT_CHECK = 0 while True: - print("Version: {}".format(VERSION)) time.sleep(5) try: mtime = os.path.getmtime(sys.argv[0]) except OSError: mtime = 0 - print(mtime) if NEXT_CHECK < int(time.time()): NEXT_CHECK = int(time.time()) + 10 - writeLog("Blalala : Next : " + str(NEXT_CHECK)) if curos == "Windows": if checkIfProcessRunning("aida64.exe"): aide_refs = { @@ -961,9 +988,7 @@ if curos == "Windows": } #ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"] - - - + path = winreg.HKEY_CURRENT_USER try: key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues") @@ -1010,6 +1035,28 @@ if curos == "Windows": client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True) #print(json.dumps(stats)) #writeLog(json.dumps(stats)) + writeLog(FILE_TIMESTAMP) + writeLog(mtime) + writeLog(sys.argv[0]) + if FILE_TIMESTAMP != mtime: + writeLog("Script updated ! restarting...") + #os.execv(sys.executable, ['python'] + sys.argv) + #os.system("/share/ZFS530_DATA/.qpkg/QPython39/bin/python3 mqtt_srv.py") + + if host.lower() == "morefine": + mycmd = 'powershell -w h -command Start-ScheduledTask -TaskName "jaydee\\restart_mqtt_srv"' + writeLog(mycmd) + status,output = subprocess.Popen(mycmd.split(),shell=True) + if host.lower() == "router" or host.lower() == "omv": + #sys.stdout.flush() + #os.execv(sys.argv, "") + print("argv was",sys.argv) + print("sys.executable was", sys.executable) + print("restart now") + + os.execv(sys.executable, ['python3'] + sys.argv) + #os.startfile(sys.argv[0]) + sys.exit() else: print("Linux") client.loop_start() @@ -1020,15 +1067,16 @@ else: time.sleep(5) try: mtime = os.path.getmtime(sys.argv[0]) + writeLog(sys.argv[0]) except OSError: mtime = 0 #print(mtime) if NEXT_CHECK < int(time.time()): NEXT_CHECK = int(time.time()) + 20 - writeLog("Blalala : Next : " + str(NEXT_CHECK)) + #writeLog("Blalala : Next : " + str(NEXT_CHECK)) if host.lower() == "asus" or host.lower() == "morefine" or host.lower() == "ryzen" or host.lower() == "amd" or host.lower() == "rack": - writeLog("Blalala : AAA") + #writeLog("Blalala : AAA") print(psutil.sensors_temperatures()) #print(psutil.sensors_fans()) sences = psutil.sensors_temperatures() @@ -1163,7 +1211,8 @@ else: payload[m] = 0 client.publish( "home-assistant/" + host + "/hwstats", payload=json.dumps(payload), qos=0, retain=True) - + writeLog(FILE_TIMESTAMP) + writeLog(mtime) if FILE_TIMESTAMP != mtime: writeLog("Script updated ! restarting...") #os.execv(sys.executable, ['python'] + sys.argv) diff --git a/mqtt_srv.pyw b/mqtt_srv.pyw index 5fd1907..20a1dab 100755 --- a/mqtt_srv.pyw +++ b/mqtt_srv.pyw @@ -17,11 +17,21 @@ import ctypes import getopt import random import requests +import shutil + +if os.path.exists("/etc/mqtt_srv/mqtt_srv.cfg"): + with open("/etc/mqtt_srv/mqtt_srv.cfg") as json_file: + config = json.load(json_file) + print(config) +else: + config = {} + #import psutil stats = {} -VERSION = "1.0.28" +VERSION = "1.0.36" + curos = platform.system() -host = platform.node().lower() +host = platform.node().lower().replace(".home.lan","") print(host) if curos == "Windows": import winreg @@ -64,13 +74,19 @@ def uptime(): string += str(seconds) return string; - +ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S") +if curos == "Windows": + log_path = "c:\\Program Files\\jaydee\\jaydee.log" +else: + log_path = "/tmp/mqtt_srv.log" + +if os.path.exists(log_path): + shutil.move(log_path, log_path + "." + ts2) def writeLog(msg, svr="INFO"): ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - if curos == "Windows": - log_path = "c:\Program Files\jaydee\jaydee.log" - else: - log_path = "/tmp/mqtt_srv.log" + ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + f = open(log_path, "a") f.write(ts + " | " + svr + " | " + str(msg) + "\n") f.close() @@ -221,7 +237,7 @@ for o, a in opts: _THR_VAL = sys.argv[3] else: _WIZZARD = True -MQTT_HOST = "192.168.77.106" +MQTT_HOST = "mqtt.home.lan" MQTT_PORT = 1883 if _PUBLISH: @@ -311,9 +327,13 @@ def get_ip(): finally: s.close() return IP - - -IP = get_ip() +ex = 0 +while ex == 0: + try: + IP = get_ip() + ex = 1 + except: + time.sleep(5) print("OS : " + curos) @@ -617,94 +637,6 @@ def on_message(client, userdata, msg): writeLog("Payload111114") writeLog(output) print(json.dumps(serv_d)) - ''' - if myObj["target"].lower() == "192.168.77.246": - dest_ip = "192.168.77.246" - elif myObj["target"].lower() == "192.168.77.106": - dest_ip = "192.168.77.106" - - - - - RULES = ["EMAIL993", "EMAIL995", "EMAIL143", "EMAIL25", "EMAIL993", "EMAIL465", "HTTPS", "HTTP"] - for i in RULES: - cmnd = "uci set firewall.{}.dest_ip={}".format(i,dest_ip) - writeLog(cmnd) - subprocess.Popen(cmnd.split()) - - #cmnd = "uci set dhcp.@dnsmasq[0].address=/mqtt_broker/" + dest_ip - #writeLog(cmnd) - #subprocess.Popen(cmnd.split()) - time.sleep(1) - cmnd = "uci commit" - - subprocess.Popen(cmnd.split()) - - writeLog("Starting " + myObj["target"].lower()) - if myObj["target"].lower() == "192.168.77.246": - dest_ip = "192.168.77.246" - - - cmnd = "ssh root@192.168.77.246 'docker start mailu_resolver_1 mailu_redis_1 mailu_front_1 mailu_antispam_1 mailu_imap_1 mailu_admin_1 mailu_smtp_1 mailu_webmail_1 watchtower_watchtower_1 nginx-proxy-manager_db_1 nginx-proxy-manager_app_1 HomeAssistant webhub_client_1 dockermon_docker_mon_1 mosquitto_mosquitto_1 node-red_node-red_1 nextcloud_db_1 nextcloud_app_1'" - status, output = subprocess.getstatusoutput(cmnd) - elif myObj["target"].lower() == "192.168.77.106": - dest_ip = "192.168.77.106" - cmnd = "ssh root@192.168.77.246 'docker stop mailu_resolver_1 mailu_redis_1 mailu_front_1 mailu_antispam_1 mailu_imap_1 mailu_admin_1 mailu_smtp_1 mailu_webmail_1 watchtower_watchtower_1 nginx-proxy-manager_db_1 nginx-proxy-manager_app_1 HomeAssistant webhub_client_1 dockermon_docker_mon_1 mosquitto_mosquitto_1 node-red_node-red_1 nextcloud_db_1 nextcloud_app_1'" - status, output = subprocess.getstatusoutput(cmnd) - time.sleep(1) - cmnd = "/etc/init.d/firewall restart" - subprocess.Popen(cmnd.split()) - #cmnd = "/etc/init.d/dnsmasq restart" - #subprocess.Popen(cmnd.split()) - writeLog("reconfigure iot") - MQTT_BROKER = dest_ip - MQTT_USER = "jaydee" - MQTT_PASS = "jaydee1" - - cmnd = "nmap -sP 192.168.77.*|grep \"Nmap scan report\"|egrep -o \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\"" - #print(cmnd) - status, output = subprocess.getstatusoutput(cmnd) - - # print(output) - - ips = output.splitlines() - tasm_data = {} - for sys_ip in ips: - # print("Thsis is ip : " + sys_ip) - cmnd = "nmap " + sys_ip + " -p80|grep \"80/tcp open http\"" - status, output = subprocess.getstatusoutput(cmnd) - # print("status of 80 : " + str(status)) - if status == 0: - try: - # url = "http://" + sys_ip + "/cm?user=admin&password=l4c1j4yd33Du5l0&cmnd=STATUS+5" - - url = "http://" + sys_ip + "/cm?cmnd=Backlog%20MqttHost%20" + MQTT_BROKER + "%3BMqttUser%20" + MQTT_USER + "%3BMqttPassword%20" + MQTT_PASS - print(url) - requests.get(url) - - except: - #print(sys_ip + " : Not a tasmota!") - pass - else: - #print(sys_ip + " : Not a listening") - pass - - - - time.sleep(1) - cmnd = "sed -i 's/^MQTT_HOST = .*/MQTT_HOST = \"" + dest_ip + "\"/' /root/mqtt_srv.py" - writeLog(cmnd) - status, output = subprocess.getstatusoutput(cmnd) - #for i in ;do uci set firewall.${i}.dest_ip=192.168.77.246;done;uci set firewall.HTTPS.dest_port='443';uci set firewall.HTTP.dest_port='80' ;uci commit;/etc/init.d/firewall restart - else: - pass - #cmnd = "/root/router_cmd.sh -t wireless -v 0" - - - print("Executed " + cmnd) - writeLog("Executed " + cmnd) - ''' - if myObj["cmd"] == "banip": if myObj["status"] == "ban": @@ -727,8 +659,8 @@ def on_message(client, userdata, msg): # os.startfile(sys.argv[0]) #sys.exit() myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc' - print(myCmd) writeLog(myCmd) + subprocess.Popen(myCmd.split()) if myObj["cmd"] == "getstats": print("lalaa1") @@ -740,19 +672,37 @@ def on_message(client, userdata, msg): 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) print("lalaa2") - + if myObj["cmd"] == "openrgb": + myCmd = 'powershell.exe -windowstyle hidden -command Stop-ScheduledTask -TaskName "jaydee\OpenRGB"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + time.sleep(2) + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\OpenRGB"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + if myObj["cmd"] == "hyperion": + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperion"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) + if myObj["cmd"] == "hyperiond": + myCmd = 'powershell.exe -windowstyle hidden -command Start-ScheduledTask -TaskName "jaydee\hyperiond"' + writeLog(myCmd) + subprocess.Popen(myCmd.split()) if myObj["cmd"] == "display": - if curos == "Windows1": + if curos == "Windows": # os.startfile(sys.argv[0]) #sys.exit() #print("reconfigure") - myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml' + #myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml' + + myCmd =f"powershell -w h -command \" Import-Module DisplayConfig ; Import-Clixml $home\monitors\{myObj['target']}.xml | Use-DisplayConfig -UpdateAdapterIds \"" writeLog(myCmd) - #writeLog(os.path.realpath(__file__)) - print("lalaa2") - #subprocess.Popen(r'"{}"'.format(myCmd), shell=True) - print("lalaa3") - subprocess.Popen(myCmd.split(), shell=True,cwd=r'c:\Progra~1\jaydee') + #myCmd = f"MultiMonitorTool.exe /LoadConfig \"c:\\Program Files\\jaydee\\Monitors\\{myObj["target"]}.cfg\"" + #writeLog(myCmd) + #print(myCmd) + output = subprocess.Popen(myCmd, shell=True) + #output = subprocess.Popen(myCmd.split()) + writeLog(output) else: ''' myCmd = "" @@ -779,7 +729,7 @@ def on_message(client, userdata, msg): ''' myCmd = "" writeLog(myObj["target"]) - if curos == "Windows": + if curos == "Windows1": myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"]) @@ -787,14 +737,42 @@ def on_message(client, userdata, msg): ''' mon1 = "HDMI-1-1" mon2 = "HDMI-1-2" - mon3 = "DVI-I-2-1" - mon4 = "eDP-1-1" + mon3 = "DisplayPort-0" + mon4 = "DisplayPort-8" ''' - right = ["HDMI-A-0", "1920x1080"] - tleft = ["HDMI-A-0", "1920x1080"] - tright = ["DVI-I-1-1", "1920x1080"] - left = ["DisplayPort-0", "2560x1440"] - mid = ["DisplayPort-1", "3440x1440"] + # right = ["HDMI-A-0", "1920x1080"] + # tleft = ["DisplayPort-6", "1920x1080"] + # tright = ["DisplayPort-8", "1920x1080"] + # left = ["DisplayPort-7", "2560x1440"] + # mid = ["DisplayPort-0", "3440x1440"] + + right = config['morefine']['right'] + tleft = config['morefine']['tleft'] + tright = config['morefine']['tright'] + left = config['morefine']['left'] + mid = config['morefine']['mid'] + myCmd = "bash /home/jd/test.sh" + status, output = subprocess.getstatusoutput(myCmd) + f = open( "/tmp/monitors.txt" ) + contents = f.read().splitlines() + f.close() + writeLog(contents) + for i in contents: + writeLog(i) + d = i.split(";") + if len(d) < 2: + continue + writeLog(d[1]) + if d[1] == "DELL P3421W": + mid[0] = d[0] + elif d[1] == "VG27WQ": + left[0] = d[0] + elif d[1] == "PHL 243V5": + tleft[0] = d[0] + elif d[1] == "PHL 273V7": + tright[0] = d[0] + writeLog("dpc") + writeLog(contents) #xrandr --output DisplayPort-1 --primary --auto --mode 3440x1440 --output HDMI-A-0 --auto --left-of DVI-I-1-1 --mode 1920x1080 --output DisplayPort-0 --auto --left-of DisplayPort-1 --mode 2560x1440 --output DVI-I-1-1 --above DisplayPort-1 --mode 1920x1080 if myObj["target"] == "mid": @@ -823,9 +801,11 @@ def on_message(client, userdata, msg): print(myCmd) writeLog("Executing : {myCmd}") #subprocess.Popen(myCmd.split()) - status, output = subprocess.getstatusoutput(myCmd) - writeLog(output) - writeLog(status) + for i in [1,2,3]: + status, output = subprocess.getstatusoutput(myCmd) + writeLog(output) + writeLog(status) + time.sleep(1) if myObj["cmd"] == "display2": # os.startfile(sys.argv[0]) #sys.exit() @@ -854,10 +834,11 @@ def on_message(client, userdata, msg): subprocess.Popen(['/usr/bin/xrandr']) if myObj["cmd"] == "suspend": - print("suspending") + writeLog("suspending") if curos == "Windows": - if host == "amd" or host == "amd1": - os.system("shutdown /s /t 1") + if host == "amd" or host == "amd1" or host == "morefine": + #os.system("shutdown /s /t 1") + os.system("shutdown /h") else: os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") #cmnd = "psshutdown -d -t 1" @@ -867,19 +848,24 @@ def on_message(client, userdata, msg): #writeLog(output) else: if host == "nas" or host == "octopi": - subprocess.Popen(["/sbin/poweroff"]) - elif host == "openmediavault" or host == "omv" or host == "amd" or host == "ryzen": - subprocess.Popen(["poweroff"]) + cmnd = "/sbin/poweroff" + elif host in ["openmediavault", "omv","amd","rack"]: + cmnd = "poweroff" elif host == "amd" or host == "ryzen": - subprocess.Popen(["systemctl suspend"]) + cmnd = "systemctl suspend" + else: #subprocess.Popen(["/bin/systemctl", "suspend", "-i"]) #subprocess.Popen(["sudo", "pm-suspend"]) + cmnd = "pm-suspend" - status, output = subprocess.getstatusoutput(cmnd) - print(output) - print(status) + writeLog(cmnd) + #subprocess.Popen(cmnd) + status, output = subprocess.getstatusoutput(cmnd) + print(output) + print(status) + if myObj["cmd"] == "stats": grep = subprocess.Popen(['grep', 'cpu', '/proc/stat'], stdout=subprocess.PIPE, @@ -983,7 +969,7 @@ if curos == "Windows": print(mtime) if NEXT_CHECK < int(time.time()): NEXT_CHECK = int(time.time()) + 10 - writeLog("Blalala : Next : " + str(NEXT_CHECK)) + #writeLog("Blalala : Next : " + str(NEXT_CHECK)) if curos == "Windows": if checkIfProcessRunning("aida64.exe"): aide_refs = { @@ -1065,7 +1051,7 @@ else: NEXT_CHECK = int(time.time()) + 20 writeLog("Blalala : Next : " + str(NEXT_CHECK)) - if host.lower() == "asus" or host.lower() == "morefine" or host.lower() == "ryzen": + if host.lower() == "asus" or host.lower() == "morefine" or host.lower() == "ryzen" or host.lower() == "amd" or host.lower() == "rack": writeLog("Blalala : AAA") print(psutil.sensors_temperatures()) #print(psutil.sensors_fans()) @@ -1141,7 +1127,7 @@ else: print("CPU Util : {}".format(cpu_usage)) print(mem_data) print(mem_data.percent) - raid_data = psutil.disk_usage('/srv/dev-disk-by-uuid-02fbe97a-cd9a-4511-8bd5-21f8516353ee') + raid_data = psutil.disk_usage('/srv/dev-disk-by-uuid-2f843500-95b6-43b0-bea1-9b67032989b8') #print(psutil.virtual_memory()) #print(dict(psutil.virtual_memory()._asdict())) #cmnd = "sensors -j|grep -v \"Can't read\"" @@ -1165,12 +1151,13 @@ 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='{"version":"' + VERSION + '","reboot":"' + str(reboot_pending) + '", "uptime":"' + str(sys_uptime) + '", "raid_usage": ' + str(disk_usage) + ',"rsync":"' + str(stat_rsync) +'", "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":0, "VMEM_UTIL":' + str(swap_data.percent) + ', "CPU_UTIL":' + str(cpu_usage) + '}', qos=0, retain=False) + client.publish("home-assistant/" + host + "/hwstats", payload='{"status":"on", "version":"' + VERSION + '","reboot":"' + str(reboot_pending) + '", "uptime":"' + str(sys_uptime) + '", "raid_usage": ' + str(disk_usage) + ',"rsync":"' + str(stat_rsync) +'", "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":0, "VMEM_UTIL":' + str(swap_data.percent) + ', "CPU_UTIL":' + str(cpu_usage) + '}', qos=0, retain=False) + writeLog("lalal") elif host.lower() == "router": check_router() elif host.lower() == "nas": print("Getting VM info") - + payload = {"status":"on"} cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh list --all" writeLog(cmnd) status, output = subprocess.getstatusoutput(cmnd) @@ -1195,11 +1182,12 @@ else: status, output = subprocess.getstatusoutput(cmnd) writeLog(output) if output.strip() == "running": - client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True) + payload[m] = 1 else: - client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True) + payload[m] = 0 + client.publish( "home-assistant/" + host + "/hwstats", payload=json.dumps(payload), qos=0, retain=True) - + if FILE_TIMESTAMP != mtime: writeLog("Script updated ! restarting...") #os.execv(sys.executable, ['python'] + sys.argv)