This commit is contained in:
2025-02-24 01:06:18 +01:00
parent cb2ee57784
commit 7c748b1dff
2 changed files with 203 additions and 166 deletions

View File

@@ -17,7 +17,7 @@ import ctypes
import getopt import getopt
import random import random
import requests import requests
import shutil
if os.path.exists("/etc/mqtt_srv/mqtt_srv.cfg"): if os.path.exists("/etc/mqtt_srv/mqtt_srv.cfg"):
with open("/etc/mqtt_srv/mqtt_srv.cfg") as json_file: with open("/etc/mqtt_srv/mqtt_srv.cfg") as json_file:
@@ -28,7 +28,7 @@ else:
#import psutil #import psutil
stats = {} stats = {}
VERSION = "1.0.36" VERSION = "1.0.37"
curos = platform.system() curos = platform.system()
host = platform.node().lower().replace(".home.lan","") host = platform.node().lower().replace(".home.lan","")
@@ -74,14 +74,19 @@ def uptime():
string += str(seconds) string += str(seconds)
return string; 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"): def writeLog(msg, svr="INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 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"
f = open(log_path, "a") f = open(log_path, "a")
f.write(ts + " | " + svr + " | " + str(msg) + "\n") f.write(ts + " | " + svr + " | " + str(msg) + "\n")
f.close() f.close()
@@ -654,8 +659,8 @@ def on_message(client, userdata, msg):
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc' myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc'
print(myCmd)
writeLog(myCmd) writeLog(myCmd)
subprocess.Popen(myCmd.split()) subprocess.Popen(myCmd.split())
if myObj["cmd"] == "getstats": if myObj["cmd"] == "getstats":
print("lalaa1") 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) 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") 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 myObj["cmd"] == "display":
if curos == "Windows1": if curos == "Windows":
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
#print("reconfigure") #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(myCmd)
#writeLog(os.path.realpath(__file__)) #myCmd = f"MultiMonitorTool.exe /LoadConfig \"c:\\Program Files\\jaydee\\Monitors\\{myObj["target"]}.cfg\""
print("lalaa2") #writeLog(myCmd)
#subprocess.Popen(r'"{}"'.format(myCmd), shell=True) #print(myCmd)
print("lalaa3") output = subprocess.Popen(myCmd, shell=True)
subprocess.Popen(myCmd.split(), shell=True,cwd=r'c:\Progra~1\jaydee') #output = subprocess.Popen(myCmd.split())
writeLog(output)
else: else:
''' '''
myCmd = "" myCmd = ""
@@ -706,7 +735,7 @@ def on_message(client, userdata, msg):
''' '''
myCmd = "" myCmd = ""
writeLog(myObj["target"]) writeLog(myObj["target"])
if curos == "Windows": if curos == "Windows1":
myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"]) myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"])
@@ -813,8 +842,9 @@ def on_message(client, userdata, msg):
if myObj["cmd"] == "suspend": if myObj["cmd"] == "suspend":
writeLog("suspending") writeLog("suspending")
if curos == "Windows": if curos == "Windows":
if host == "amd" or host == "amd1": if host == "amd" or host == "amd1" or host == "morefine":
os.system("shutdown /s /t 1") #os.system("shutdown /s /t 1")
os.system("shutdown /h")
else: else:
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
#cmnd = "psshutdown -d -t 1" #cmnd = "psshutdown -d -t 1"
@@ -936,16 +966,13 @@ if curos == "Windows":
client.loop_start() client.loop_start()
NEXT_CHECK = 0 NEXT_CHECK = 0
while True: while True:
print("Version: {}".format(VERSION))
time.sleep(5) time.sleep(5)
try: try:
mtime = os.path.getmtime(sys.argv[0]) mtime = os.path.getmtime(sys.argv[0])
except OSError: except OSError:
mtime = 0 mtime = 0
print(mtime)
if NEXT_CHECK < int(time.time()): if NEXT_CHECK < int(time.time()):
NEXT_CHECK = int(time.time()) + 10 NEXT_CHECK = int(time.time()) + 10
writeLog("Blalala : Next : " + str(NEXT_CHECK))
if curos == "Windows": if curos == "Windows":
if checkIfProcessRunning("aida64.exe"): if checkIfProcessRunning("aida64.exe"):
aide_refs = { aide_refs = {
@@ -962,8 +989,6 @@ if curos == "Windows":
#ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"] #ks = ["TCPU", "TPCHDIO", "SMEMUTI", "SVIRTMEMUTI", "SCPUUTI", "FCPU", "TGPU1DIO", "SGPU1BIUTI"]
path = winreg.HKEY_CURRENT_USER path = winreg.HKEY_CURRENT_USER
try: try:
key = winreg.OpenKeyEx(path, r"SOFTWARE\\FinalWire\\AIDA64\\SensorValues") 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) client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
#print(json.dumps(stats)) #print(json.dumps(stats))
#writeLog(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: else:
print("Linux") print("Linux")
client.loop_start() client.loop_start()
@@ -1020,15 +1067,16 @@ else:
time.sleep(5) time.sleep(5)
try: try:
mtime = os.path.getmtime(sys.argv[0]) mtime = os.path.getmtime(sys.argv[0])
writeLog(sys.argv[0])
except OSError: except OSError:
mtime = 0 mtime = 0
#print(mtime) #print(mtime)
if NEXT_CHECK < int(time.time()): if NEXT_CHECK < int(time.time()):
NEXT_CHECK = int(time.time()) + 20 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": 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_temperatures())
#print(psutil.sensors_fans()) #print(psutil.sensors_fans())
sences = psutil.sensors_temperatures() sences = psutil.sensors_temperatures()
@@ -1163,7 +1211,8 @@ else:
payload[m] = 0 payload[m] = 0
client.publish( "home-assistant/" + host + "/hwstats", payload=json.dumps(payload), qos=0, retain=True) client.publish( "home-assistant/" + host + "/hwstats", payload=json.dumps(payload), qos=0, retain=True)
writeLog(FILE_TIMESTAMP)
writeLog(mtime)
if FILE_TIMESTAMP != mtime: if FILE_TIMESTAMP != mtime:
writeLog("Script updated ! restarting...") writeLog("Script updated ! restarting...")
#os.execv(sys.executable, ['python'] + sys.argv) #os.execv(sys.executable, ['python'] + sys.argv)

View File

@@ -17,11 +17,21 @@ import ctypes
import getopt import getopt
import random import random
import requests 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 #import psutil
stats = {} stats = {}
VERSION = "1.0.28" VERSION = "1.0.36"
curos = platform.system() curos = platform.system()
host = platform.node().lower() host = platform.node().lower().replace(".home.lan","")
print(host) print(host)
if curos == "Windows": if curos == "Windows":
import winreg import winreg
@@ -64,13 +74,19 @@ def uptime():
string += str(seconds) string += str(seconds)
return string; 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"): def writeLog(msg, svr="INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if curos == "Windows": ts2 = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
log_path = "c:\Program Files\jaydee\jaydee.log"
else:
log_path = "/tmp/mqtt_srv.log"
f = open(log_path, "a") f = open(log_path, "a")
f.write(ts + " | " + svr + " | " + str(msg) + "\n") f.write(ts + " | " + svr + " | " + str(msg) + "\n")
f.close() f.close()
@@ -221,7 +237,7 @@ for o, a in opts:
_THR_VAL = sys.argv[3] _THR_VAL = sys.argv[3]
else: else:
_WIZZARD = True _WIZZARD = True
MQTT_HOST = "192.168.77.106" MQTT_HOST = "mqtt.home.lan"
MQTT_PORT = 1883 MQTT_PORT = 1883
if _PUBLISH: if _PUBLISH:
@@ -311,9 +327,13 @@ def get_ip():
finally: finally:
s.close() s.close()
return IP return IP
ex = 0
while ex == 0:
IP = get_ip() try:
IP = get_ip()
ex = 1
except:
time.sleep(5)
print("OS : " + curos) print("OS : " + curos)
@@ -617,94 +637,6 @@ def on_message(client, userdata, msg):
writeLog("Payload111114") writeLog("Payload111114")
writeLog(output) writeLog(output)
print(json.dumps(serv_d)) 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["cmd"] == "banip":
if myObj["status"] == "ban": if myObj["status"] == "ban":
@@ -727,8 +659,8 @@ def on_message(client, userdata, msg):
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc' myCmd = 'c:\\Program Files\\RealVNC\\VNC Viewer\\vncviewer.exe C:\\Users\\jaydee\\' + myObj["target"].upper() + '.vnc'
print(myCmd)
writeLog(myCmd) writeLog(myCmd)
subprocess.Popen(myCmd.split()) subprocess.Popen(myCmd.split())
if myObj["cmd"] == "getstats": if myObj["cmd"] == "getstats":
print("lalaa1") 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) 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") 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 myObj["cmd"] == "display":
if curos == "Windows1": if curos == "Windows":
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
#print("reconfigure") #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(myCmd)
#writeLog(os.path.realpath(__file__)) #myCmd = f"MultiMonitorTool.exe /LoadConfig \"c:\\Program Files\\jaydee\\Monitors\\{myObj["target"]}.cfg\""
print("lalaa2") #writeLog(myCmd)
#subprocess.Popen(r'"{}"'.format(myCmd), shell=True) #print(myCmd)
print("lalaa3") output = subprocess.Popen(myCmd, shell=True)
subprocess.Popen(myCmd.split(), shell=True,cwd=r'c:\Progra~1\jaydee') #output = subprocess.Popen(myCmd.split())
writeLog(output)
else: else:
''' '''
myCmd = "" myCmd = ""
@@ -779,7 +729,7 @@ def on_message(client, userdata, msg):
''' '''
myCmd = "" myCmd = ""
writeLog(myObj["target"]) writeLog(myObj["target"])
if curos == "Windows": if curos == "Windows1":
myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"]) myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"])
@@ -787,14 +737,42 @@ def on_message(client, userdata, msg):
''' '''
mon1 = "HDMI-1-1" mon1 = "HDMI-1-1"
mon2 = "HDMI-1-2" mon2 = "HDMI-1-2"
mon3 = "DVI-I-2-1" mon3 = "DisplayPort-0"
mon4 = "eDP-1-1" mon4 = "DisplayPort-8"
''' '''
right = ["HDMI-A-0", "1920x1080"] # right = ["HDMI-A-0", "1920x1080"]
tleft = ["HDMI-A-0", "1920x1080"] # tleft = ["DisplayPort-6", "1920x1080"]
tright = ["DVI-I-1-1", "1920x1080"] # tright = ["DisplayPort-8", "1920x1080"]
left = ["DisplayPort-0", "2560x1440"] # left = ["DisplayPort-7", "2560x1440"]
mid = ["DisplayPort-1", "3440x1440"] # 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 #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": if myObj["target"] == "mid":
@@ -823,9 +801,11 @@ def on_message(client, userdata, msg):
print(myCmd) print(myCmd)
writeLog("Executing : {myCmd}") writeLog("Executing : {myCmd}")
#subprocess.Popen(myCmd.split()) #subprocess.Popen(myCmd.split())
for i in [1,2,3]:
status, output = subprocess.getstatusoutput(myCmd) status, output = subprocess.getstatusoutput(myCmd)
writeLog(output) writeLog(output)
writeLog(status) writeLog(status)
time.sleep(1)
if myObj["cmd"] == "display2": if myObj["cmd"] == "display2":
# os.startfile(sys.argv[0]) # os.startfile(sys.argv[0])
#sys.exit() #sys.exit()
@@ -854,10 +834,11 @@ def on_message(client, userdata, msg):
subprocess.Popen(['/usr/bin/xrandr']) subprocess.Popen(['/usr/bin/xrandr'])
if myObj["cmd"] == "suspend": if myObj["cmd"] == "suspend":
print("suspending") writeLog("suspending")
if curos == "Windows": if curos == "Windows":
if host == "amd" or host == "amd1": if host == "amd" or host == "amd1" or host == "morefine":
os.system("shutdown /s /t 1") #os.system("shutdown /s /t 1")
os.system("shutdown /h")
else: else:
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0") os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
#cmnd = "psshutdown -d -t 1" #cmnd = "psshutdown -d -t 1"
@@ -867,19 +848,24 @@ def on_message(client, userdata, msg):
#writeLog(output) #writeLog(output)
else: else:
if host == "nas" or host == "octopi": if host == "nas" or host == "octopi":
subprocess.Popen(["/sbin/poweroff"]) cmnd = "/sbin/poweroff"
elif host == "openmediavault" or host == "omv" or host == "amd" or host == "ryzen": elif host in ["openmediavault", "omv","amd","rack"]:
subprocess.Popen(["poweroff"]) cmnd = "poweroff"
elif host == "amd" or host == "ryzen": elif host == "amd" or host == "ryzen":
subprocess.Popen(["systemctl suspend"]) cmnd = "systemctl suspend"
else: else:
#subprocess.Popen(["/bin/systemctl", "suspend", "-i"]) #subprocess.Popen(["/bin/systemctl", "suspend", "-i"])
#subprocess.Popen(["sudo", "pm-suspend"]) #subprocess.Popen(["sudo", "pm-suspend"])
cmnd = "pm-suspend" cmnd = "pm-suspend"
writeLog(cmnd)
#subprocess.Popen(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
print(output) print(output)
print(status) print(status)
if myObj["cmd"] == "stats": if myObj["cmd"] == "stats":
grep = subprocess.Popen(['grep', 'cpu', '/proc/stat'], grep = subprocess.Popen(['grep', 'cpu', '/proc/stat'],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -983,7 +969,7 @@ if curos == "Windows":
print(mtime) print(mtime)
if NEXT_CHECK < int(time.time()): if NEXT_CHECK < int(time.time()):
NEXT_CHECK = int(time.time()) + 10 NEXT_CHECK = int(time.time()) + 10
writeLog("Blalala : Next : " + str(NEXT_CHECK)) #writeLog("Blalala : Next : " + str(NEXT_CHECK))
if curos == "Windows": if curos == "Windows":
if checkIfProcessRunning("aida64.exe"): if checkIfProcessRunning("aida64.exe"):
aide_refs = { aide_refs = {
@@ -1065,7 +1051,7 @@ else:
NEXT_CHECK = int(time.time()) + 20 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": 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_temperatures())
#print(psutil.sensors_fans()) #print(psutil.sensors_fans())
@@ -1141,7 +1127,7 @@ else:
print("CPU Util : {}".format(cpu_usage)) print("CPU Util : {}".format(cpu_usage))
print(mem_data) print(mem_data)
print(mem_data.percent) 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(psutil.virtual_memory())
#print(dict(psutil.virtual_memory()._asdict())) #print(dict(psutil.virtual_memory()._asdict()))
#cmnd = "sensors -j|grep -v \"Can't read\"" #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["coretemp-isa-0000"]["Package id 0"]["temp1_input"]))
#print(str(jn1["asus-isa-0000"]["cpu_fan"]["fan1_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("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": elif host.lower() == "router":
check_router() check_router()
elif host.lower() == "nas": elif host.lower() == "nas":
print("Getting VM info") print("Getting VM info")
payload = {"status":"on"}
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh list --all" cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
writeLog(cmnd) writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
@@ -1195,9 +1182,10 @@ else:
status, output = subprocess.getstatusoutput(cmnd) status, output = subprocess.getstatusoutput(cmnd)
writeLog(output) writeLog(output)
if output.strip() == "running": if output.strip() == "running":
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True) payload[m] = 1
else: 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: if FILE_TIMESTAMP != mtime: