mirror of
https://gitlab.sectorq.eu/jaydee/mqtt_srv.git
synced 2025-12-14 18:44:53 +01:00
Compare commits
125 Commits
dev
...
87d82d8f73
| Author | SHA1 | Date | |
|---|---|---|---|
| 87d82d8f73 | |||
| 7d0da9241e | |||
| 2c892fd6fa | |||
| 1e0a172cb9 | |||
| 69ddbe559b | |||
| 245e88f612 | |||
| 07e61dc952 | |||
| bb3de5c241 | |||
| e428b18e42 | |||
| f747536496 | |||
| ebfb825cfe | |||
| 796eae1859 | |||
| 2c7be24654 | |||
| 5b05f1ac61 | |||
| 9ed37997a0 | |||
| 3f132c1f89 | |||
| facb016fc3 | |||
| 6951eebf09 | |||
| b361e043c5 | |||
| 35c24f9527 | |||
| 58752ed0bb | |||
| 043a97e23f | |||
| 38862b3f39 | |||
| 563d7ad04b | |||
| 152239a804 | |||
| c3ee4f371a | |||
| fdd652a575 | |||
| b8c591968e | |||
| 350597ed35 | |||
| 82ffb5064a | |||
| 9fb535ac51 | |||
| b665775a5f | |||
| ee9cb6f5c8 | |||
| 06489f0665 | |||
| c27861e933 | |||
| 46d2949af7 | |||
| 0b30c493fd | |||
| 4ad61769a9 | |||
| cab79db6e9 | |||
| 441851ff2f | |||
| 19ba9b38b7 | |||
| 9a5846edff | |||
| 7c6494b93b | |||
| 639641a10a | |||
| 16731f1083 | |||
| aceffccbc1 | |||
| a5615c109d | |||
| 2aca817303 | |||
| 58fb5a832e | |||
| 320adbfafa | |||
| 8807fa75b1 | |||
| 6df8ca7be9 | |||
| 7d65175a1c | |||
| 61cad82864 | |||
| eb785594f5 | |||
| e17febe9ee | |||
| 071385ce84 | |||
| 4ecf3a4956 | |||
| 51a5b1a94b | |||
| 532a1ba8d9 | |||
| 0ab9d1baed | |||
| 67a1c39d7e | |||
| 19d83844ae | |||
| 25e05af7f7 | |||
| 344706f10d | |||
| 920dadd36f | |||
| c63de3c3fb | |||
| 7c748b1dff | |||
|
|
cb2ee57784 | ||
|
|
d476df0a10 | ||
|
|
a7e2702282 | ||
|
|
17c83dc0c5 | ||
|
|
a704b0d132 | ||
|
|
a4b4bb9d9f | ||
|
|
d747cc61ed | ||
|
|
e84f008185 | ||
|
|
db67db8d43 | ||
|
|
c0fc8d82d9 | ||
|
|
a281768e41 | ||
|
|
df5004982d | ||
|
|
6c5360653d | ||
|
|
0f78a61e46 | ||
|
|
0c4f3c5146 | ||
|
|
46a0f8b4b0 | ||
|
|
0074c3e356 | ||
|
|
f30b937313 | ||
|
|
7f7bd30bab | ||
|
|
0271860fea | ||
|
|
2ce50277cb | ||
|
|
2c933229a7 | ||
|
|
9be7a48ba6 | ||
|
|
f2358e8c76 | ||
|
|
5b819d3043 | ||
|
|
f836cd59b3 | ||
|
|
10a9aa31f8 | ||
|
|
d1e67120d8 | ||
|
|
2633f271ca | ||
|
|
bb95e1fcd4 | ||
|
|
8915068760 | ||
|
|
94c06c80c5 | ||
|
|
23c107366f | ||
|
|
134a2dbad9 | ||
|
|
8ad43c8873 | ||
|
|
6304f1a5f9 | ||
|
|
209161414a | ||
|
|
8ab0d7efe6 | ||
|
|
8d9bfa08e1 | ||
|
|
f9b3ba3a75 | ||
|
|
254100d2b2 | ||
|
|
826b44658c | ||
|
|
64e47c68d3 | ||
|
|
558bc597b9 | ||
|
|
f32a5b030e | ||
|
|
8e5e547827 | ||
|
|
e428893a50 | ||
|
|
ed83895391 | ||
|
|
b4018dafb5 | ||
|
|
2f8530ea4f | ||
|
|
8b261f1baf | ||
|
|
1ab9d43b22 | ||
|
|
b57b8cc200 | ||
|
|
cf03567047 | ||
|
|
4edb522e5e | ||
|
|
1c726c376c | ||
|
|
2b68910618 |
13
.gitlab-ci.yml
Normal file
13
.gitlab-ci.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
stages: # List of stages for jobs, and their order of execution
|
||||||
|
- build
|
||||||
|
|
||||||
|
|
||||||
|
build-job: # This job runs in the build stage, which runs first.
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- column=":"
|
||||||
|
- echo "${flow_id}"
|
||||||
|
- curl -X POST https://kestra.sectorq.eu/api/v1/executions/webhook/jaydee/ansible-all/${flow_id} -d '{"tag":["mqtt-srv"],"target":["morefine.home.lan"]}' -H "Content-Type${column} application/json"
|
||||||
|
- rm -rf /home/gitlab-runner/builds/1fLwHSKm2/0/jaydee/mqtt_srv.tmp/.gitlab-runner.ext.conf
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_MESSAGE =~ /build/'
|
||||||
14
mqtt_srv.cfg
Normal file
14
mqtt_srv.cfg
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"global":
|
||||||
|
{
|
||||||
|
"mykey": "prod/v1/install/"
|
||||||
|
},
|
||||||
|
"morefine":
|
||||||
|
{
|
||||||
|
"right": ["HDMI-A-0", "1920x1080"],
|
||||||
|
"tleft": ["DisplayPort-9", "1920x1080"],
|
||||||
|
"tright": ["DisplayPort-11", "1920x1080"],
|
||||||
|
"left": ["DisplayPort-10", "2560x1440"],
|
||||||
|
"mid": ["DisplayPort-0", "3440x1440"]
|
||||||
|
}
|
||||||
|
}
|
||||||
589
mqtt_srv.py
589
mqtt_srv.py
@@ -17,12 +17,34 @@ 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.25"
|
VERSION = "1.0.37"
|
||||||
|
|
||||||
curos = platform.system()
|
curos = platform.system()
|
||||||
host = platform.node().lower()
|
host = platform.node().lower().replace(".home.lan","")
|
||||||
print(host)
|
if curos == "Windows":
|
||||||
|
log_path = "c:\\Program Files\\jaydee\\jaydee.log"
|
||||||
|
else:
|
||||||
|
log_path = "/tmp/mqtt_srv.log"
|
||||||
|
|
||||||
|
def writeLog(msg, svr="INFO"):
|
||||||
|
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
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()
|
||||||
|
writeLog(host)
|
||||||
if curos == "Windows":
|
if curos == "Windows":
|
||||||
import winreg
|
import winreg
|
||||||
def uptime():
|
def uptime():
|
||||||
@@ -64,16 +86,12 @@ 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 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"
|
|
||||||
f = open(log_path, "a")
|
|
||||||
f.write(ts + " | " + svr + " | " + str(msg) + "\n")
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def check_router():
|
def check_router():
|
||||||
stats["uptime"] = uptime()
|
stats["uptime"] = uptime()
|
||||||
@@ -200,7 +218,7 @@ try:
|
|||||||
opts, args = getopt.getopt(sys.argv[1:], "Sspmt:", ["command=", "help", "output="])
|
opts, args = getopt.getopt(sys.argv[1:], "Sspmt:", ["command=", "help", "output="])
|
||||||
except getopt.GetoptError as err:
|
except getopt.GetoptError as err:
|
||||||
# print help information and exit:
|
# print help information and exit:
|
||||||
print(str(err)) # will print something like "option -a not recognized"
|
writeLog(str(err)) # will print something like "option -a not recognized"
|
||||||
#usage()
|
#usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
output = None
|
output = None
|
||||||
@@ -221,7 +239,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:
|
||||||
@@ -250,9 +268,9 @@ if _PUBLISH:
|
|||||||
# result: [0, 1]
|
# result: [0, 1]
|
||||||
status = result[0]
|
status = result[0]
|
||||||
if status == 0:
|
if status == 0:
|
||||||
print(f"Send `{_MESSAGE}` to topic `{_TOPIC}`")
|
writeLog(f"Send `{_MESSAGE}` to topic `{_TOPIC}`")
|
||||||
else:
|
else:
|
||||||
print(f"Failed to send message to topic {_TOPIC}")
|
writeLog(f"Failed to send message to topic {_TOPIC}")
|
||||||
|
|
||||||
client = connect_mqtt()
|
client = connect_mqtt()
|
||||||
publish(client)
|
publish(client)
|
||||||
@@ -311,12 +329,15 @@ def get_ip():
|
|||||||
finally:
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
return IP
|
return IP
|
||||||
|
ex = 0
|
||||||
|
while ex == 0:
|
||||||
|
try:
|
||||||
|
IP = get_ip()
|
||||||
|
ex = 1
|
||||||
|
except:
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
IP = get_ip()
|
|
||||||
|
|
||||||
|
|
||||||
print("OS : " + curos)
|
|
||||||
writeLog("OS : " + curos)
|
writeLog("OS : " + curos)
|
||||||
if curos != "Windows":
|
if curos != "Windows":
|
||||||
import autorandr
|
import autorandr
|
||||||
@@ -330,28 +351,27 @@ elif host == "SERVER":
|
|||||||
mac = str(get_mac_address("enp2s0"))
|
mac = str(get_mac_address("enp2s0"))
|
||||||
elif host == "ASUS" and curos != "Windows":
|
elif host == "ASUS" and curos != "Windows":
|
||||||
mac = str(get_mac_address("enp3s0f1"))
|
mac = str(get_mac_address("enp3s0f1"))
|
||||||
|
elif host == "morefine" and curos != "Windows":
|
||||||
|
mac = str(get_mac_address("eno1"))
|
||||||
else:
|
else:
|
||||||
mac = str(get_mac_address("Ethernet"))
|
mac = str(get_mac_address("Ethernet"))
|
||||||
|
|
||||||
|
|
||||||
print("MAC : " + mac)
|
|
||||||
writeLog("MAC : " + mac)
|
writeLog("MAC : " + mac)
|
||||||
print("SYSTEM : " + host)
|
|
||||||
writeLog("SYSTEM : " + host)
|
writeLog("SYSTEM : " + host)
|
||||||
print("IP : " + IP)
|
|
||||||
writeLog("IP : " + IP)
|
writeLog("IP : " + IP)
|
||||||
|
|
||||||
flag_connected = 0
|
flag_connected = 0
|
||||||
# The callback for when the client receives a CONNACK response from the server.
|
# The callback for when the client receives a CONNACK response from the server.
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
print("Connected with result code " + str(rc))
|
|
||||||
writeLog("Connected with result code " + str(rc))
|
writeLog("Connected with result code " + str(rc))
|
||||||
global flag_connected
|
global flag_connected
|
||||||
flag_connected = 1
|
flag_connected = 1
|
||||||
# Subscribing in on_connect() means that if we lose the connection and
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
# reconnect then subscriptions will be renewed.
|
# reconnect then subscriptions will be renewed.
|
||||||
topic = "sectorq/systems/" + host.lower()
|
topic = "sectorq/systems/" + host.lower()
|
||||||
print(topic)
|
topic2 = "sectorq/systems/all"
|
||||||
|
MQTT_TOPIC = [(topic,0),(topic2,0)]
|
||||||
writeLog(topic)
|
writeLog(topic)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
client.publish("sectorq/status", payload="{'action':'connect', 'system':'" + host.lower() + "', 'ip': '" + IP + "', 'mac':'" + mac + "', 'ver':'" + VERS + "'}", qos=0, retain=False)
|
client.publish("sectorq/status", payload="{'action':'connect', 'system':'" + host.lower() + "', 'ip': '" + IP + "', 'mac':'" + mac + "', 'ver':'" + VERS + "'}", qos=0, retain=False)
|
||||||
@@ -359,11 +379,21 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
if host.lower() == "router":
|
if host.lower() == "router":
|
||||||
check_router()
|
check_router()
|
||||||
|
|
||||||
if host.lower() == "nas":
|
if host.lower() == "morefine":
|
||||||
print("Getting VM info")
|
myCmd =f'sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer set Master 100%'
|
||||||
|
# try:
|
||||||
|
# #percent = 20
|
||||||
|
# #output = subprocess.run(["pactl", "set-sink-volume", "@DEFAULT_SINK@", f"{percent}%"], check=True)
|
||||||
|
# writeLog(output)
|
||||||
|
# except subprocess.CalledProcessError as e:
|
||||||
|
# writeLog(e)
|
||||||
|
# writeLog("Failed to mute/unmute")
|
||||||
|
writeLog(myCmd)
|
||||||
|
output = subprocess.Popen(myCmd, shell=True)
|
||||||
|
|
||||||
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
|
if host.lower() == "nas":
|
||||||
print(cmnd)
|
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
|
||||||
|
writeLog(cmnd)
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
l = 1
|
l = 1
|
||||||
lines = output.splitlines()
|
lines = output.splitlines()
|
||||||
@@ -373,28 +403,26 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
if l < 4:
|
if l < 4:
|
||||||
continue
|
continue
|
||||||
line = re.split(r" {2,}", i)
|
line = re.split(r" {2,}", i)
|
||||||
print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
|
writeLog(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
|
||||||
VMS[str(line[1].strip())] = str(line[2].strip())
|
VMS[str(line[1].strip())] = str(line[2].strip())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for m in VMS:
|
for m in VMS:
|
||||||
|
|
||||||
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
|
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
|
||||||
#out = subprocess.Popen(cmnd.split())
|
#out = subprocess.Popen(cmnd.split())
|
||||||
print(cmnd)
|
writeLog(cmnd)
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
print(output)
|
writeLog(output)
|
||||||
if output.strip() == "running":
|
if output.strip() == "running":
|
||||||
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True)
|
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True)
|
||||||
else:
|
else:
|
||||||
client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True)
|
client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True)
|
||||||
|
|
||||||
|
client.subscribe(MQTT_TOPIC)
|
||||||
client.subscribe(topic)
|
|
||||||
|
|
||||||
def on_disconnect(client, userdata, rc):
|
def on_disconnect(client, userdata, rc):
|
||||||
print("disconnecting reason " +str(rc))
|
|
||||||
writeLog("disconnecting reason " +str(rc))
|
writeLog("disconnecting reason " +str(rc))
|
||||||
client.connected_flag=False
|
client.connected_flag=False
|
||||||
client.disconnect_flag=True
|
client.disconnect_flag=True
|
||||||
@@ -404,8 +432,8 @@ def on_disconnect(client, userdata, rc):
|
|||||||
|
|
||||||
# The callback for when a PUBLISH message is received from the server.
|
# The callback for when a PUBLISH message is received from the server.
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
print(msg.topic)
|
writeLog(msg.topic)
|
||||||
print(msg.payload)
|
writeLog(msg.payload)
|
||||||
myObj = msg.payload.decode('utf-8')
|
myObj = msg.payload.decode('utf-8')
|
||||||
# command = re.sub(r"^b\'|\'$", "", str(msg.payload))
|
# command = re.sub(r"^b\'|\'$", "", str(msg.payload))
|
||||||
# command = json.loads(msg.payload.decode("utf-8"))
|
# command = json.loads(msg.payload.decode("utf-8"))
|
||||||
@@ -413,49 +441,36 @@ def on_message(client, userdata, msg):
|
|||||||
myObj = json.loads(msg.payload)
|
myObj = json.loads(msg.payload)
|
||||||
try:
|
try:
|
||||||
writeLog(myObj["action"])
|
writeLog(myObj["action"])
|
||||||
print(myObj["action"])
|
|
||||||
except:
|
except:
|
||||||
print("Action not set")
|
|
||||||
writeLog("Action not set", "WARNING")
|
writeLog("Action not set", "WARNING")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(myObj["cmd"])
|
|
||||||
writeLog(myObj["cmd"])
|
writeLog(myObj["cmd"])
|
||||||
except:
|
except:
|
||||||
print("Cmd not set")
|
|
||||||
writeLog("Cmd not set", "WARNING")
|
writeLog("Cmd not set", "WARNING")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(myObj["target"])
|
|
||||||
writeLog(myObj["target"])
|
writeLog(myObj["target"])
|
||||||
except:
|
except:
|
||||||
print("Target Not Set")
|
|
||||||
writeLog("Target Not Set", "WARNING")
|
writeLog("Target Not Set", "WARNING")
|
||||||
try:
|
try:
|
||||||
print(myObj["status"])
|
|
||||||
writeLog(myObj["status"])
|
writeLog(myObj["status"])
|
||||||
except:
|
except:
|
||||||
print("Status Not Set")
|
|
||||||
writeLog("Status Not Set")
|
writeLog("Status Not Set")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(myObj["command"])
|
|
||||||
writeLog(myObj["command"])
|
writeLog(myObj["command"])
|
||||||
except:
|
except:
|
||||||
print("Command Not Set")
|
|
||||||
writeLog("Command Not Set")
|
writeLog("Command Not Set")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(myObj["cmd_line"])
|
|
||||||
writeLog(myObj["cmd_line"])
|
writeLog(myObj["cmd_line"])
|
||||||
except:
|
except:
|
||||||
print("Cmd_line Not Set")
|
|
||||||
writeLog("Cmd_line Not Set")
|
writeLog("Cmd_line Not Set")
|
||||||
|
|
||||||
|
|
||||||
if myObj["cmd"] == "command":
|
if myObj["cmd"] == "command":
|
||||||
|
|
||||||
print("Executing " + myObj["cmd_line"])
|
|
||||||
writeLog("Executing " + myObj["cmd_line"])
|
writeLog("Executing " + myObj["cmd_line"])
|
||||||
#os.system('start /b "' + myObj["cmd_line"] + '"')
|
#os.system('start /b "' + myObj["cmd_line"] + '"')
|
||||||
try:
|
try:
|
||||||
@@ -464,48 +479,48 @@ def on_message(client, userdata, msg):
|
|||||||
# ctypes.windll.user32.MessageBoxW(0, myObj["cmd_line"], "Executed", 64)
|
# ctypes.windll.user32.MessageBoxW(0, myObj["cmd_line"], "Executed", 64)
|
||||||
except:
|
except:
|
||||||
ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 16)
|
ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 16)
|
||||||
print("Executed " + myObj["cmd_line"])
|
|
||||||
writeLog("Executed " + myObj["cmd_line"])
|
writeLog("Executed " + myObj["cmd_line"])
|
||||||
|
|
||||||
if myObj["cmd"] == "nas_cmd":
|
if myObj["cmd"] == "nas_cmd":
|
||||||
print("Executing NAS")
|
writeLog("Executing NAS")
|
||||||
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
|
#cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
|
||||||
print(cmnd)
|
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
|
||||||
|
writeLog(cmnd)
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
print(output)
|
writeLog(output)
|
||||||
cmd_type = myObj["command"]
|
cmd_type = myObj["command"]
|
||||||
if myObj["command"] == "start":
|
if myObj["command"] == "start":
|
||||||
if output.strip() == "paused":
|
if output.strip() == "paused":
|
||||||
print("System suspended")
|
writeLog("System suspended")
|
||||||
cmd_type = "resume"
|
cmd_type = "resume"
|
||||||
else:
|
else:
|
||||||
print("System Off")
|
writeLog("System Off")
|
||||||
cmd_type = "start"
|
cmd_type = "start"
|
||||||
if myObj["command"] == "suspend":
|
if myObj["command"] == "suspend":
|
||||||
cmd_type = "shutdown"
|
cmd_type = "shutdown"
|
||||||
|
|
||||||
|
|
||||||
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh " + cmd_type + " " + str(myObj["target"])
|
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh " + cmd_type + " " + str(myObj["target"])
|
||||||
subprocess.Popen(cmnd.split())
|
subprocess.Popen(cmnd.split())
|
||||||
print(cmnd)
|
writeLog(cmnd)
|
||||||
if myObj["command"] == "start":
|
if myObj["command"] == "start":
|
||||||
try:
|
try:
|
||||||
print("sending")
|
writeLog("sending")
|
||||||
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=1, qos=0, retain=False)
|
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=1, qos=0, retain=False)
|
||||||
except:
|
except:
|
||||||
print("failed to execute!")
|
writeLog("failed to execute!")
|
||||||
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
|
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
print("sending")
|
writeLog("sending")
|
||||||
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=0, qos=0, retain=False)
|
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=0, qos=0, retain=False)
|
||||||
except:
|
except:
|
||||||
print("failed to execute!")
|
writeLog("failed to execute!")
|
||||||
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
|
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
|
||||||
|
|
||||||
|
|
||||||
if myObj["cmd"] == "distrib":
|
if myObj["cmd"] == "distrib":
|
||||||
print("distributin313g")
|
writeLog("distributin313g")
|
||||||
# os.startfile(sys.argv[0])
|
# os.startfile(sys.argv[0])
|
||||||
#sys.exit()
|
#sys.exit()
|
||||||
subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt'])
|
subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt'])
|
||||||
@@ -614,94 +629,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":
|
||||||
@@ -724,8 +651,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")
|
||||||
@@ -737,19 +664,74 @@ 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":
|
||||||
|
writeLog("Starting Assist")
|
||||||
|
if curos == "Windows":
|
||||||
|
writeLog("Windows Vol Control")
|
||||||
|
if myObj['target'] == "start":
|
||||||
|
myCmd =f'powershell "& ""c:\\Program Files\\jaydee\\vol_control.ps1""" 0.2'
|
||||||
|
else:
|
||||||
|
myCmd =f'powershell "& ""c:\\Program Files\\jaydee\\vol_control.ps1""" 1'
|
||||||
|
else:
|
||||||
|
writeLog("Linux Vol Control")
|
||||||
|
if myObj['target'] == "start":
|
||||||
|
writeLog("Getting sound status")
|
||||||
|
#myCmd = "sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer sget Master | awk -F'[][]' '/Left:/ { print $2 }'"
|
||||||
|
myCmd = "sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer sget Master"
|
||||||
|
writeLog(myCmd)
|
||||||
|
output = subprocess.Popen(myCmd, shell=True)
|
||||||
|
cmd = """sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer sget Master | awk -F'[][]' '/Left:/ { print $2 }'"""
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
cmd,
|
||||||
|
shell=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
os.environ["MQTT_SRV_CUR_VOLUME"] = result.stdout.strip()
|
||||||
|
writeLog(f"Status of volume {os.environ["MQTT_SRV_CUR_VOLUME"]}")
|
||||||
|
myCmd = f'sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer set Master 20%'
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
myCmd =f'sudo XDG_RUNTIME_DIR=/run/user/1000 -u jd amixer set Master {os.environ["MQTT_SRV_CUR_VOLUME"] }'
|
||||||
|
# try:
|
||||||
|
# #percent = 20
|
||||||
|
# #output = subprocess.run(["pactl", "set-sink-volume", "@DEFAULT_SINK@", f"{percent}%"], check=True)
|
||||||
|
# writeLog(output)
|
||||||
|
# except subprocess.CalledProcessError as e:
|
||||||
|
# writeLog(e)
|
||||||
|
# writeLog("Failed to mute/unmute")
|
||||||
|
writeLog(myCmd)
|
||||||
|
output = subprocess.Popen(myCmd, shell=True)
|
||||||
|
writeLog(output)
|
||||||
|
|
||||||
if myObj["cmd"] == "display":
|
if myObj["cmd"] == "display":
|
||||||
if curos == "Windows1":
|
if curos == "Windows":
|
||||||
# os.startfile(sys.argv[0])
|
myCmd =f"powershell -w h -command \" Import-Module DisplayConfig ; Import-Clixml $home\\monitors\\{myObj['target']}.xml | Use-DisplayConfig -UpdateAdapterIds \""
|
||||||
#sys.exit()
|
|
||||||
#print("reconfigure")
|
|
||||||
myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml'
|
|
||||||
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 = ""
|
||||||
@@ -776,7 +758,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"])
|
||||||
|
|
||||||
@@ -784,44 +766,77 @@ 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"
|
||||||
'''
|
'''
|
||||||
mon1 = "HDMI-1"
|
# right = ["HDMI-A-0", "1920x1080"]
|
||||||
mon2 = "HDMI-2"
|
# tleft = ["DisplayPort-6", "1920x1080"]
|
||||||
mon3 = "DVI-I-2-1"
|
# tright = ["DisplayPort-8", "1920x1080"]
|
||||||
mon4 = "eDP-1"
|
# 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 /myapps/mqtt_srv/get_monitors.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":
|
if myObj["target"] == "mid":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon1 + " --off --output " + mon4 + " --off"
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --output {left[0]} --off --output {tleft[0]} --off --output {tright[0]} --off"
|
||||||
elif myObj["target"] == "left":
|
elif myObj["target"] == "left":
|
||||||
myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off"
|
myCmd = f"xrandr --output {left[0]} --primary --auto --mode {left[1]} --output {mid[0]} --off --output {tleft[0]} --off --output {tright[0]} --off"
|
||||||
|
|
||||||
elif myObj["target"] == "all":
|
elif myObj["target"] == "all":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --pos 0x0 --output {tleft[0]} --auto --pos -1920x-1080 --mode {tleft[1]} --output {left[0]} --auto --left-of {mid[0]} --mode {left[1]} --output {tright[0]} --above {mid[0]} --mode {tright[1]}"
|
||||||
|
elif myObj["target"] == "midtright":
|
||||||
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --pos 0x0 --output {tleft[0]} --off --output {left[0]} --off --output {tright[0]} --above {mid[0]} --mode {tright[1]}"
|
||||||
|
#myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --output {right[0]} --auto --right-of {mid[0]} --mode {right[1]} --output {left[0]} --auto --left-of {mid[0]} --mode {left[1]}"
|
||||||
elif myObj["target"] == "midleft":
|
elif myObj["target"] == "midleft":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off"
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --output {tleft[0]} --off --output {left[0]} --auto --left-of {mid[0]} --mode {left[1]} --output {tright[0]} --off"
|
||||||
elif myObj["target"] == "midtop":
|
elif myObj["target"] == "midtop":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --off --output " + mon4 + " --off"
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --output {tright[0]} --auto --above {mid[0]} --mode {tright[1]} --output {left[0]} --off --output {tleft[0]} --off"
|
||||||
elif myObj["target"] == "midleftbuild":
|
elif myObj["target"] == "midlefttleft":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
|
myCmd = f"xrandr --output {mid[0]} --primary --auto --mode {mid[1]} --pos 0x0 --output {tright[0]} --off --output {left[0]} --auto --left-of {mid[0]} --mode {left[1]} --output {tleft[0]} --auto --pos -1920x-1080 --mode {tleft[1]}"
|
||||||
elif myObj["target"] == "midbuild":
|
elif myObj["target"] == "lefttlefttright":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
|
myCmd = f"xrandr --output {mid[0]} --off --output {tleft[0]} --auto --pos 640x-1080 --mode {tright[1]} --output {left[0]} --primary --auto --mode {left[1]} --pos 0x0 --output {tright[0]} --right-of {tleft[0]} --mode {tright[1]}"
|
||||||
elif myObj["target"] == "midlefttop":
|
elif myObj["target"] == "lefttleft":
|
||||||
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --auto --left-of " + mon2 + " --mode 1920x1080 --output " + mon4 + " --off"
|
myCmd = f"xrandr --output {mid[0]} --off --output {tleft[0]} --auto --pos 640x-1080 --mode {tright[1]} --output {left[0]} --primary --auto --mode {left[1]} --pos 0x0 --output {tright[0]} --off"
|
||||||
elif myObj["target"] == "build":
|
|
||||||
myCmd = "xrandr --output " + mon2 + " --off --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --mode 1920x1080"
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
writeLog(myCmd)
|
writeLog(myCmd)
|
||||||
if myCmd != "":
|
if myCmd != "":
|
||||||
print(myCmd)
|
print(myCmd)
|
||||||
writeLog("Executing")
|
writeLog("Executing : {myCmd}")
|
||||||
#subprocess.Popen(myCmd.split())
|
#subprocess.Popen(myCmd.split())
|
||||||
status, output = subprocess.getstatusoutput(myCmd)
|
for i in [1,2,3]:
|
||||||
writeLog(output)
|
status, output = subprocess.getstatusoutput(myCmd)
|
||||||
writeLog(status)
|
writeLog(output)
|
||||||
|
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()
|
||||||
@@ -850,10 +865,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"
|
||||||
@@ -863,16 +879,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":
|
elif host in ["openmediavault", "omv","amd","rack"]:
|
||||||
subprocess.Popen(["poweroff"])
|
cmnd = "poweroff"
|
||||||
|
elif host == "amd" or host == "ryzen":
|
||||||
|
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"
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
writeLog(cmnd)
|
||||||
print(output)
|
#subprocess.Popen(cmnd)
|
||||||
print(status)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
print(output)
|
||||||
|
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,
|
||||||
@@ -919,6 +943,7 @@ def on_message(client, userdata, msg):
|
|||||||
client.publish("sectorq/status/" + host, payload=jn, qos=0, retain=False)
|
client.publish("sectorq/status/" + host, payload=jn, qos=0, retain=False)
|
||||||
except:
|
except:
|
||||||
print("not a json!")
|
print("not a json!")
|
||||||
|
print(msg.payload)
|
||||||
|
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
payload = '{"status": "off"}'
|
payload = '{"status": "off"}'
|
||||||
@@ -927,7 +952,15 @@ client.will_set("home-assistant/" + host.lower() + "/hwstats", payload=payload,
|
|||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
writeLog(MQTT_HOST)
|
writeLog(MQTT_HOST)
|
||||||
client.connect(MQTT_HOST, MQTT_PORT, 25)
|
connected = False
|
||||||
|
while not connected:
|
||||||
|
try:
|
||||||
|
client.connect(MQTT_HOST, MQTT_PORT, 25)
|
||||||
|
connected = True
|
||||||
|
except:
|
||||||
|
writeLog("Failed to connect repeating...")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
# client.publish("sectorq/status", payload="{'action':'connect', 'system':'" + host + "', 'ip': '" + IP + "', 'mac':'" + mac + "', 'ver':'?'}", qos=0, retain=False)
|
# client.publish("sectorq/status", payload="{'action':'connect', 'system':'" + host + "', 'ip': '" + IP + "', 'mac':'" + mac + "', 'ver':'?'}", qos=0, retain=False)
|
||||||
|
|
||||||
@@ -954,21 +987,18 @@ def checkIfProcessRunning(processName):
|
|||||||
|
|
||||||
|
|
||||||
if curos == "Windows":
|
if curos == "Windows":
|
||||||
print("WINDOWS")
|
|
||||||
#client.loop_forever()
|
#client.loop_forever()
|
||||||
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 = {
|
||||||
@@ -985,8 +1015,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")
|
||||||
@@ -1033,8 +1061,29 @@ 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")
|
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
NEXT_CHECK = 0
|
NEXT_CHECK = 0
|
||||||
@@ -1043,20 +1092,50 @@ 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() == "rpi5":
|
||||||
if host.lower() == "asus":
|
#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()
|
||||||
cpu_data = sences["coretemp"][0]
|
print("SENCES")
|
||||||
mb_data = sences["acpitz"][0]
|
print(sences)
|
||||||
fan_data = psutil.sensors_fans()["asus"][0]
|
print("#"*40)
|
||||||
|
try:
|
||||||
|
cpu_data = sences["cpu_thermal"][0]
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
cpu_data = sences["k10temp"][0]
|
||||||
|
except:
|
||||||
|
cpu_data = "None"
|
||||||
|
writeLog(cpu_data)
|
||||||
|
print("CPUDATA")
|
||||||
|
print(cpu_data)
|
||||||
|
print("#"*40)
|
||||||
|
print("MBDATA")
|
||||||
|
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()["pwmfan"][0].current
|
||||||
|
except:
|
||||||
|
fan_data = "None"
|
||||||
mem_data = psutil.virtual_memory()
|
mem_data = psutil.virtual_memory()
|
||||||
swap_data = psutil.swap_memory()
|
swap_data = psutil.swap_memory()
|
||||||
#cpu_usage = psutil.cpu_percent(interval=1)
|
#cpu_usage = psutil.cpu_percent(interval=1)
|
||||||
@@ -1077,7 +1156,68 @@ 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='{"status":"on", "version":"' + VERSION + '","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.current) + ', "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)
|
||||||
|
if host.lower() == "asus" or host.lower() == "m-server" 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())
|
||||||
|
sences = psutil.sensors_temperatures()
|
||||||
|
print("SENCES")
|
||||||
|
print(sences)
|
||||||
|
print("#"*40)
|
||||||
|
try:
|
||||||
|
cpu_data = sences["coretemp"][0]
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
cpu_data = sences["k10temp"][0]
|
||||||
|
except:
|
||||||
|
cpu_data = "None"
|
||||||
|
writeLog(cpu_data)
|
||||||
|
print("CPUDATA")
|
||||||
|
print(cpu_data)
|
||||||
|
print("#"*40)
|
||||||
|
print("MBDATA")
|
||||||
|
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"
|
||||||
|
mem_data = psutil.virtual_memory()
|
||||||
|
swap_data = psutil.swap_memory()
|
||||||
|
#cpu_usage = psutil.cpu_percent(interval=1)
|
||||||
|
load1, load5, load15 = psutil.getloadavg()
|
||||||
|
cpu_usage = round((load1/os.cpu_count()) * 100, 1)
|
||||||
|
|
||||||
|
print(mem_data)
|
||||||
|
print(mem_data.percent)
|
||||||
|
print(psutil.disk_usage('/'))
|
||||||
|
#print(psutil.virtual_memory())
|
||||||
|
#print(dict(psutil.virtual_memory()._asdict()))
|
||||||
|
#cmnd = "sensors -j|grep -v \"Can't read\""
|
||||||
|
#status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
#print(output)
|
||||||
|
#print(type(output))
|
||||||
|
#jn1 = json.loads(output)
|
||||||
|
|
||||||
|
#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)
|
||||||
|
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)
|
client.publish("sectorq/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
|
||||||
elif host.lower() == "openmediavault" or host.lower() == "omv":
|
elif host.lower() == "openmediavault" or host.lower() == "omv":
|
||||||
#print(psutil.sensors_temperatures())
|
#print(psutil.sensors_temperatures())
|
||||||
@@ -1095,7 +1235,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\""
|
||||||
@@ -1119,13 +1259,14 @@ 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/ZFS530_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)
|
||||||
l = 1
|
l = 1
|
||||||
@@ -1136,24 +1277,26 @@ else:
|
|||||||
if l < 4:
|
if l < 4:
|
||||||
continue
|
continue
|
||||||
line = re.split(r" {2,}", i)
|
line = re.split(r" {2,}", i)
|
||||||
print(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
|
writeLog(str(line[0].strip()) + " " + str(line[1].strip()) + " " + str(line[2].strip()))
|
||||||
VMS[str(line[1].strip())] = str(line[2].strip())
|
VMS[str(line[1].strip())] = str(line[2].strip())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for m in VMS:
|
for m in VMS:
|
||||||
|
|
||||||
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
|
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + m
|
||||||
#out = subprocess.Popen(cmnd.split())
|
#out = subprocess.Popen(cmnd.split())
|
||||||
writeLog(cmnd)
|
writeLog(cmnd)
|
||||||
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)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|||||||
1208
mqtt_srv.pyw
Executable file
1208
mqtt_srv.pyw
Executable file
File diff suppressed because it is too large
Load Diff
15
mqtt_srv.service
Normal file
15
mqtt_srv.service
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=ROT13 demo service
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network.target network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
Environment=XAUTHORITY=/home/jd/.Xauthority
|
||||||
|
Environment=DISPLAY=:0
|
||||||
|
#ExecStartPre=/bin/sleep 30
|
||||||
|
ExecStart=/myapps/mqtt_srv/venv/bin/python3 /myapps/mqtt_srv/mqtt_srv.py
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
|
||||||
28
mqtt_srv.sh
Normal file
28
mqtt_srv.sh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
THIS_HOST=`uname -n`
|
||||||
|
case $1 in
|
||||||
|
"start")
|
||||||
|
echo "`date` : Starting service" >> /tmp/mqtt_srv.log
|
||||||
|
if [ "$THIS_HOST" == "nas" ]
|
||||||
|
then
|
||||||
|
echo "$?" >> /tmp/mqtt_srv.log
|
||||||
|
/share/Data/python/bin/python3 /usr/bin/mqtt_srv.py > /dev/null 2>&1 &
|
||||||
|
echo "$?" >> /tmp/mqtt_srv.log
|
||||||
|
else
|
||||||
|
python3 /jffs/scripts/mqtt_srv/mqtt_srv.py > /dev/null 2>&1 &
|
||||||
|
fi
|
||||||
|
cp /share/Data/nas_bash_history /root/.bash_history
|
||||||
|
;;
|
||||||
|
"stop")
|
||||||
|
echo lala1 >> /tmp/mqtt_srv.log
|
||||||
|
kill -9 `ps |grep -e "mqtt_srv.py"|grep -v grep|awk '{ print $1}'`
|
||||||
|
cp /root/.bash_history /share/Data/nas_bash_history
|
||||||
|
;;
|
||||||
|
"restart")
|
||||||
|
$0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
"status")
|
||||||
|
ps |grep -e "mqtt_srv.py"|grep -v grep
|
||||||
|
;;
|
||||||
|
esac
|
||||||
44
mqtt_srv.spec
Normal file
44
mqtt_srv.spec
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['mqtt_srv.pyw'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=[],
|
||||||
|
datas=[],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher,
|
||||||
|
noarchive=False,
|
||||||
|
)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='mqtt_srv',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
ping3
|
ping3
|
||||||
requests
|
requests
|
||||||
getmac
|
getmac
|
||||||
paho-mqtt
|
paho-mqtt<2.0.0
|
||||||
autorandr
|
autorandr
|
||||||
|
psutil
|
||||||
Reference in New Issue
Block a user