Compare commits

...

125 Commits

Author SHA1 Message Date
87d82d8f73 build 2025-12-07 22:49:08 +01:00
7d0da9241e build 2025-12-07 22:47:09 +01:00
2c892fd6fa build 2025-12-07 22:44:32 +01:00
1e0a172cb9 build 2025-12-07 22:41:19 +01:00
69ddbe559b build 2025-12-07 22:33:43 +01:00
245e88f612 build 2025-12-07 22:31:10 +01:00
07e61dc952 build 2025-12-07 22:27:58 +01:00
bb3de5c241 build 2025-12-07 22:25:03 +01:00
e428b18e42 build 2025-12-07 22:20:43 +01:00
f747536496 build 2025-12-07 22:19:04 +01:00
ebfb825cfe build 2025-12-07 22:16:35 +01:00
796eae1859 build 2025-12-07 22:15:00 +01:00
2c7be24654 Merge branch 'main' of gitlab.sectorq.eu:jaydee/mqtt_srv 2025-12-07 22:12:26 +01:00
5b05f1ac61 build 2025-12-07 22:12:22 +01:00
9ed37997a0 Update .gitlab-ci.yml file 2025-12-07 22:07:14 +01:00
3f132c1f89 Update .gitlab-ci.yml file 2025-12-07 22:06:47 +01:00
facb016fc3 build 2025-12-07 22:04:58 +01:00
6951eebf09 build 2025-12-07 21:46:47 +01:00
b361e043c5 build 2025-12-07 21:46:10 +01:00
35c24f9527 build 2025-11-11 12:39:02 +01:00
58752ed0bb build 2025-11-04 07:25:54 +01:00
043a97e23f build 2025-11-04 07:25:05 +01:00
38862b3f39 build 2025-11-04 07:24:21 +01:00
563d7ad04b build 2025-10-25 22:23:29 +02:00
152239a804 build 2025-10-25 22:08:03 +02:00
c3ee4f371a build 2025-10-25 22:04:48 +02:00
fdd652a575 build 2025-10-25 21:58:39 +02:00
b8c591968e build 2025-10-25 21:57:23 +02:00
350597ed35 build 2025-10-25 21:56:18 +02:00
82ffb5064a build 2025-10-25 21:55:07 +02:00
9fb535ac51 build 2025-10-25 21:53:11 +02:00
b665775a5f build 2025-10-25 21:48:12 +02:00
ee9cb6f5c8 build 2025-10-25 21:45:00 +02:00
06489f0665 build 2025-10-25 21:43:15 +02:00
c27861e933 lala 2025-10-25 21:43:04 +02:00
46d2949af7 Merge branch 'main' of gitlab.sectorq.eu:jaydee/mqtt_srv 2025-10-25 21:42:54 +02:00
0b30c493fd lala 2025-10-25 21:42:31 +02:00
4ad61769a9 Update .gitlab-ci.yml file 2025-10-25 21:42:21 +02:00
cab79db6e9 lala 2025-10-25 21:39:52 +02:00
441851ff2f lala 2025-10-25 21:37:06 +02:00
19ba9b38b7 lala 2025-10-25 21:34:23 +02:00
9a5846edff lala 2025-10-25 21:29:34 +02:00
7c6494b93b lala 2025-10-25 19:21:34 +02:00
639641a10a lala 2025-10-25 19:16:43 +02:00
16731f1083 lala 2025-10-13 06:52:24 +02:00
aceffccbc1 lala 2025-10-13 06:46:42 +02:00
a5615c109d build 2025-10-06 09:23:30 +02:00
2aca817303 build 2025-09-13 11:30:46 +02:00
58fb5a832e build 2025-08-27 04:27:38 +02:00
320adbfafa build 2025-08-03 03:08:33 +02:00
8807fa75b1 added v3 2025-05-19 10:10:30 +02:00
6df8ca7be9 added v3 2025-05-13 09:25:06 +02:00
7d65175a1c added v3 2025-05-13 09:23:08 +02:00
61cad82864 added v3 2025-05-13 09:20:02 +02:00
eb785594f5 added v3 2025-05-11 14:55:29 +02:00
e17febe9ee added v3 2025-05-06 18:39:41 +02:00
071385ce84 added v3 2025-05-06 18:35:44 +02:00
4ecf3a4956 added v3 2025-05-06 18:29:36 +02:00
51a5b1a94b added v3 2025-05-06 18:17:28 +02:00
532a1ba8d9 klal 2025-05-05 18:23:15 +02:00
0ab9d1baed klal 2025-05-05 18:21:22 +02:00
67a1c39d7e klal 2025-05-05 18:20:46 +02:00
19d83844ae klal 2025-05-05 17:10:26 +02:00
25e05af7f7 klal 2025-05-05 17:09:50 +02:00
344706f10d klal 2025-05-05 17:09:01 +02:00
920dadd36f Edit requirements.txt 2025-04-24 09:50:51 +02:00
c63de3c3fb Edit requirements.txt 2025-04-24 08:55:38 +02:00
7c748b1dff lala 2025-02-24 01:06:18 +01:00
jaydee
cb2ee57784 initial 2024-12-19 15:47:07 +01:00
jaydee
d476df0a10 bitwarden 2024-11-29 02:04:09 +01:00
jaydee
a7e2702282 bitwarden 2024-11-29 01:43:06 +01:00
jaydee
17c83dc0c5 bitwarden 2024-11-29 01:40:48 +01:00
jaydee
a704b0d132 bitwarden 2024-11-29 01:30:56 +01:00
jaydee
a4b4bb9d9f bitwarden 2024-11-20 21:03:02 +01:00
jaydee
d747cc61ed bitwarden 2024-11-20 20:42:10 +01:00
jaydee
e84f008185 bitwarden 2024-11-20 20:40:21 +01:00
jaydee
db67db8d43 bitwarden 2024-11-20 20:37:37 +01:00
jaydee
c0fc8d82d9 bitwarden 2024-11-20 20:31:33 +01:00
jaydee
a281768e41 bitwarden 2024-11-20 20:06:47 +01:00
jaydee
df5004982d bitwarden 2024-11-19 19:31:15 +01:00
jaydee
6c5360653d bitwarden 2024-11-19 18:04:04 +01:00
jaydee
0f78a61e46 bitwarden 2024-11-19 18:00:53 +01:00
jaydee
0c4f3c5146 bitwarden 2024-11-19 07:58:10 +01:00
jaydee
46a0f8b4b0 bitwarden 2024-11-19 06:52:12 +01:00
jaydee
0074c3e356 bitwarden 2024-10-31 09:20:25 +01:00
jaydee
f30b937313 bitwarden 2024-10-30 12:48:33 +01:00
jaydee
7f7bd30bab bitwarden 2024-10-30 12:46:15 +01:00
jaydee
0271860fea bitwarden 2024-10-30 12:44:41 +01:00
jaydee
2ce50277cb bitwarden 2024-10-30 12:40:01 +01:00
jaydee
2c933229a7 bitwarden 2024-10-30 12:38:28 +01:00
jaydee
9be7a48ba6 bitwarden 2024-10-30 12:35:11 +01:00
jaydee
f2358e8c76 bitwarden 2024-10-30 12:32:08 +01:00
jaydee
5b819d3043 bitwarden 2024-10-30 12:26:49 +01:00
jaydee
f836cd59b3 bitwarden 2024-10-30 12:01:30 +01:00
jaydee
10a9aa31f8 bitwarden 2024-10-30 11:57:25 +01:00
jaydee
d1e67120d8 bitwarden 2024-10-30 11:52:12 +01:00
jaydee
2633f271ca bitwarden 2024-10-30 08:50:46 +01:00
jaydee
bb95e1fcd4 bitwarden 2024-10-10 23:16:32 +02:00
jaydee
8915068760 bitwarden 2024-10-10 23:03:12 +02:00
jaydee
94c06c80c5 bitwarden 2024-10-10 22:58:21 +02:00
jaydee
23c107366f bitwarden 2024-10-10 22:55:04 +02:00
jaydee
134a2dbad9 bitwarden 2024-10-10 22:46:58 +02:00
jaydee
8ad43c8873 bitwarden 2024-09-30 20:24:09 +02:00
jaydee
6304f1a5f9 bitwarden 2024-08-18 18:47:05 +02:00
jaydee
209161414a bitwarden 2024-08-05 12:45:38 +02:00
jaydee
8ab0d7efe6 bitwarden 2024-07-29 10:26:24 +02:00
jaydee
8d9bfa08e1 upt playbook 2024-07-11 02:25:01 +02:00
jaydee
f9b3ba3a75 upt playbook 2024-07-11 01:30:14 +02:00
jaydee
254100d2b2 upt playbook 2024-07-09 01:48:01 +02:00
jaydee
826b44658c upt playbook 2024-07-09 01:44:49 +02:00
jaydee
64e47c68d3 upt playbook 2024-07-09 01:38:19 +02:00
jaydee
558bc597b9 upt playbook 2024-07-09 01:34:53 +02:00
jaydee
f32a5b030e upt playbook 2024-07-08 23:28:01 +02:00
jaydee
8e5e547827 upt playbook 2024-07-08 23:24:49 +02:00
jaydee
e428893a50 upt playbook 2024-07-08 23:09:49 +02:00
jaydee
ed83895391 upt playbook 2024-07-08 23:05:25 +02:00
Your Name
b4018dafb5 added 2024-07-08 22:51:06 +02:00
jaydee
2f8530ea4f bitwarden 2024-07-07 23:25:13 +02:00
jaydee
8b261f1baf bitwarden 2024-07-07 22:22:15 +02:00
jaydee
1ab9d43b22 bitwarden 2024-07-07 20:22:06 +02:00
jaydee
b57b8cc200 lala 2024-04-02 09:21:25 +02:00
jaydee
cf03567047 lala 2024-04-02 09:16:07 +02:00
jaydee
4edb522e5e modify xrandr 2024-02-15 06:55:53 +01:00
jaydee
1c726c376c upt playbook 2023-09-24 19:45:30 +02:00
jaydee
2b68910618 upt playbook 2023-09-24 19:39:34 +02:00
8 changed files with 1697 additions and 231 deletions

13
.gitlab-ci.yml Normal file
View 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
View 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"]
}
}

View File

@@ -17,12 +17,34 @@ 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.25"
VERSION = "1.0.37"
curos = platform.system()
host = platform.node().lower()
print(host)
host = platform.node().lower().replace(".home.lan","")
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":
import winreg
def uptime():
@@ -64,16 +86,12 @@ def uptime():
string += str(seconds)
return string;
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()
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 check_router():
stats["uptime"] = uptime()
@@ -200,7 +218,7 @@ try:
opts, args = getopt.getopt(sys.argv[1:], "Sspmt:", ["command=", "help", "output="])
except getopt.GetoptError as err:
# 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()
sys.exit(2)
output = None
@@ -221,7 +239,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:
@@ -250,9 +268,9 @@ if _PUBLISH:
# result: [0, 1]
status = result[0]
if status == 0:
print(f"Send `{_MESSAGE}` to topic `{_TOPIC}`")
writeLog(f"Send `{_MESSAGE}` to topic `{_TOPIC}`")
else:
print(f"Failed to send message to topic {_TOPIC}")
writeLog(f"Failed to send message to topic {_TOPIC}")
client = connect_mqtt()
publish(client)
@@ -311,12 +329,15 @@ def get_ip():
finally:
s.close()
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)
if curos != "Windows":
import autorandr
@@ -330,40 +351,49 @@ elif host == "SERVER":
mac = str(get_mac_address("enp2s0"))
elif host == "ASUS" and curos != "Windows":
mac = str(get_mac_address("enp3s0f1"))
elif host == "morefine" and curos != "Windows":
mac = str(get_mac_address("eno1"))
else:
mac = str(get_mac_address("Ethernet"))
print("MAC : " + mac)
writeLog("MAC : " + mac)
print("SYSTEM : " + host)
writeLog("SYSTEM : " + host)
print("IP : " + IP)
writeLog("IP : " + IP)
flag_connected = 0
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
writeLog("Connected with result code " + str(rc))
global flag_connected
flag_connected = 1
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
topic = "sectorq/systems/" + host.lower()
print(topic)
topic2 = "sectorq/systems/all"
MQTT_TOPIC = [(topic,0),(topic2,0)]
writeLog(topic)
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/systems/" + host.lower() + "/stat", payload="on", qos=0, retain=True)
if host.lower() == "router":
check_router()
if host.lower() == "nas":
print("Getting VM info")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
print(cmnd)
if host.lower() == "morefine":
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)
if host.lower() == "nas":
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
l = 1
lines = output.splitlines()
@@ -373,28 +403,26 @@ def on_connect(client, userdata, flags, rc):
if l < 4:
continue
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())
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())
print(cmnd)
writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
print(output)
writeLog(output)
if output.strip() == "running":
client.publish("sectorq/systems/nas/" + m, payload=1, qos=0, retain=True)
else:
client.publish("sectorq/systems/nas/" + m, payload=0, qos=0, retain=True)
client.subscribe(topic)
client.subscribe(MQTT_TOPIC)
def on_disconnect(client, userdata, rc):
print("disconnecting reason " +str(rc))
writeLog("disconnecting reason " +str(rc))
client.connected_flag=False
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.
def on_message(client, userdata, msg):
print(msg.topic)
print(msg.payload)
writeLog(msg.topic)
writeLog(msg.payload)
myObj = msg.payload.decode('utf-8')
# command = re.sub(r"^b\'|\'$", "", str(msg.payload))
# command = json.loads(msg.payload.decode("utf-8"))
@@ -413,49 +441,36 @@ def on_message(client, userdata, msg):
myObj = json.loads(msg.payload)
try:
writeLog(myObj["action"])
print(myObj["action"])
except:
print("Action not set")
writeLog("Action not set", "WARNING")
try:
print(myObj["cmd"])
writeLog(myObj["cmd"])
except:
print("Cmd not set")
writeLog("Cmd not set", "WARNING")
try:
print(myObj["target"])
writeLog(myObj["target"])
except:
print("Target Not Set")
writeLog("Target Not Set", "WARNING")
try:
print(myObj["status"])
writeLog(myObj["status"])
except:
print("Status Not Set")
writeLog("Status Not Set")
try:
print(myObj["command"])
writeLog(myObj["command"])
except:
print("Command Not Set")
writeLog("Command Not Set")
try:
print(myObj["cmd_line"])
writeLog(myObj["cmd_line"])
except:
print("Cmd_line Not Set")
writeLog("Cmd_line Not Set")
if myObj["cmd"] == "command":
print("Executing " + myObj["cmd_line"])
writeLog("Executing " + myObj["cmd_line"])
#os.system('start /b "' + myObj["cmd_line"] + '"')
try:
@@ -464,48 +479,48 @@ def on_message(client, userdata, msg):
# ctypes.windll.user32.MessageBoxW(0, myObj["cmd_line"], "Executed", 64)
except:
ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 16)
print("Executed " + myObj["cmd_line"])
writeLog("Executed " + myObj["cmd_line"])
if myObj["cmd"] == "nas_cmd":
print("Executing NAS")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
print(cmnd)
writeLog("Executing NAS")
#cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
cmnd = "/share/ZFS532_DATA/.qpkg/QKVM/usr/bin/virsh domstate " + str(myObj["target"])
writeLog(cmnd)
status, output = subprocess.getstatusoutput(cmnd)
print(output)
writeLog(output)
cmd_type = myObj["command"]
if myObj["command"] == "start":
if output.strip() == "paused":
print("System suspended")
writeLog("System suspended")
cmd_type = "resume"
else:
print("System Off")
writeLog("System Off")
cmd_type = "start"
if myObj["command"] == "suspend":
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())
print(cmnd)
writeLog(cmnd)
if myObj["command"] == "start":
try:
print("sending")
writeLog("sending")
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=1, qos=0, retain=False)
except:
print("failed to execute!")
writeLog("failed to execute!")
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
else:
try:
print("sending")
writeLog("sending")
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload=0, qos=0, retain=False)
except:
print("failed to execute!")
writeLog("failed to execute!")
client.publish("sectorq/systems/nas/" + str(myObj["target"]), payload="failed", qos=0, retain=False)
if myObj["cmd"] == "distrib":
print("distributin313g")
writeLog("distributin313g")
# os.startfile(sys.argv[0])
#sys.exit()
subprocess.Popen(['/bin/systemctl', 'restart', 'mqtt'])
@@ -614,94 +629,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":
@@ -724,8 +651,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")
@@ -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)
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 curos == "Windows1":
# os.startfile(sys.argv[0])
#sys.exit()
#print("reconfigure")
myCmd = 'MonitorSwitcher.exe -load:' + myObj["target"] + '.xml'
if curos == "Windows":
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 = ""
@@ -776,7 +758,7 @@ def on_message(client, userdata, msg):
'''
myCmd = ""
writeLog(myObj["target"])
if curos == "Windows":
if curos == "Windows1":
myCmd = "DisplayFusionCommand.exe -monitorloadprofile {}".format(myObj["target"])
@@ -784,44 +766,77 @@ 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"
'''
mon1 = "HDMI-1"
mon2 = "HDMI-2"
mon3 = "DVI-I-2-1"
mon4 = "eDP-1"
# 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 /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":
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":
myCmd = "xrandr --output " + mon1 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " +mon2 + " --off --output " + mon4 + " --off"
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 {left[0]} --primary --auto --mode {left[1]} --output {mid[0]} --off --output {tleft[0]} --off --output {tright[0]} --off"
elif myObj["target"] == "all":
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":
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":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --auto --right-of " + mon2 + " --mode 1920x1080 --output " + mon1 + " --off --output " + mon4 + " --off"
elif myObj["target"] == "midleftbuild":
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"
elif myObj["target"] == "midbuild":
myCmd = "xrandr --output " + mon2 + " --primary --auto --mode 1920x1080 --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --right-of " + mon2 + " --mode 1920x1080"
elif myObj["target"] == "midlefttop":
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"
elif myObj["target"] == "build":
myCmd = "xrandr --output " + mon2 + " --off --output " + mon3 + " --off --output " + mon1 + " --off --output " + mon4 + " --auto --mode 1920x1080"
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"] == "midlefttleft":
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"] == "lefttlefttright":
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"] == "lefttleft":
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"
else:
pass
writeLog(myCmd)
if myCmd != "":
print(myCmd)
writeLog("Executing")
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()
@@ -850,10 +865,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"
@@ -863,16 +879,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":
subprocess.Popen(["poweroff"])
cmnd = "/sbin/poweroff"
elif host in ["openmediavault", "omv","amd","rack"]:
cmnd = "poweroff"
elif host == "amd" or host == "ryzen":
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,
@@ -919,6 +943,7 @@ def on_message(client, userdata, msg):
client.publish("sectorq/status/" + host, payload=jn, qos=0, retain=False)
except:
print("not a json!")
print(msg.payload)
client = mqtt.Client()
payload = '{"status": "off"}'
@@ -927,7 +952,15 @@ client.will_set("home-assistant/" + host.lower() + "/hwstats", payload=payload,
client.on_connect = on_connect
client.on_message = on_message
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)
@@ -954,21 +987,18 @@ def checkIfProcessRunning(processName):
if curos == "Windows":
print("WINDOWS")
#client.loop_forever()
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 = {
@@ -984,9 +1014,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")
@@ -1033,8 +1061,29 @@ 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()
NEXT_CHECK = 0
@@ -1043,20 +1092,50 @@ 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))
if host.lower() == "asus":
#writeLog("Blalala : Next : " + str(NEXT_CHECK))
if host.lower() == "rpi5":
#writeLog("Blalala : AAA")
print(psutil.sensors_temperatures())
#print(psutil.sensors_fans())
sences = psutil.sensors_temperatures()
cpu_data = sences["coretemp"][0]
mb_data = sences["acpitz"][0]
fan_data = psutil.sensors_fans()["asus"][0]
print("SENCES")
print(sences)
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()
swap_data = psutil.swap_memory()
#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["asus-isa-0000"]["cpu_fan"]["fan1_input"]))
#client.publish("sectorq/monitor/" + host.lower(), payload="{\"mb_temp\":0,\"mem_usage\":0,\"cpu_temp\":0,\"cpu_usage\":0,\"gpu_temp\":0,\"gpu_usage\":0}", qos=0, retain=False)
client.publish("home-assistant/" + host + "/hwstats", payload='{"status":"on", "version":"' + VERSION + '","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)
elif host.lower() == "openmediavault" or host.lower() == "omv":
#print(psutil.sensors_temperatures())
@@ -1095,7 +1235,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\""
@@ -1119,13 +1259,14 @@ 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")
cmnd = "/share/ZFS530_DATA/.qpkg/QKVM/usr/bin/virsh list --all"
#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)
l = 1
@@ -1136,24 +1277,26 @@ else:
if l < 4:
continue
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())
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())
writeLog(cmnd)
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)
# writeLog(FILE_TIMESTAMP)
# writeLog(mtime)
if FILE_TIMESTAMP != mtime:
writeLog("Script updated ! restarting...")
#os.execv(sys.executable, ['python'] + sys.argv)

1208
mqtt_srv.pyw Executable file

File diff suppressed because it is too large Load Diff

15
mqtt_srv.service Normal file
View 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
View 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
View 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,
)

View File

@@ -1,5 +1,6 @@
ping3
requests
getmac
paho-mqtt
autorandr
paho-mqtt<2.0.0
autorandr
psutil