ADD zls_check.py

master
Sebastian Serfling 2023-10-25 11:07:51 +02:00
parent c379a46065
commit 76c2e83117
2 changed files with 54 additions and 56 deletions

View File

@ -4,3 +4,7 @@ Keine Netvolume vorhanden!
Keine Netvolume vorhanden! Keine Netvolume vorhanden!
Keine Netvolume vorhanden! Keine Netvolume vorhanden!
Keine Netvolume vorhanden! Keine Netvolume vorhanden!
25.10.2023 11:04 - rdpadmin has no access to \\jah-data01\Daten\Netzwerkfreigaben\Datenaustausch X
25.10.2023 11:04 - rdpadmin has no access to \\jah-data01\Home\%USERNAME% U
25.10.2023 11:06 - rdpadmin has no access to \\jah-data01\Daten\Netzwerkfreigaben\Datenaustausch X
25.10.2023 11:06 - rdpadmin has no access to \\jah-data01\Home\%USERNAME% U

106
main.py
View File

@ -39,75 +39,69 @@ user = os.getlogin() ## GET CURRENT USER
## Check Database ## Check Database
database = request("host/get/database",{"ip":system_info.get_local_ip()}).text.replace('"','') ##GET DATABASE FROM SQL-SERVER database = request("host/get/database",{"ip":system_info.get_local_ip()}).text.replace('"','') ##GET DATABASE FROM SQL-SERVER
# check_hostname = request("host/get",{"hostname":hostname,"dbname":database}) ##GET VOLUMES FROM SQL-SERVER check_hostname = request("host/get",{"hostname":hostname,"dbname":database}) ##GET VOLUMES FROM SQL-SERVER
system_type = system_info.get_client_info()
## Check Host if system_type == "Client":
# if check_hostname.text == "false":
# request("host/set",{"hostname":hostname,"ipadresse":system_info.get_local_ip(),"ram":system_info.get_ram_info(),"hddused":space_used(),"hddfree":space_free(),"hddtotal":space_total(),"dbname":database})
# else:
# request("host/update",
# {"hostname": hostname, "ipadresse": system_info.get_local_ip(), "ram": system_info.get_ram_info(),
# "hddused": space_used(), "hddfree": space_free(), "hddtotal": space_total(), "dbname": database})
if system_info.get_client_info() == "Client":
user = system_info.get_smb_credential() user = system_info.get_smb_credential()
### Check User ### Check User
check_user_exist = request("user/get",{"user":user,"dbname":database}) check_user_exist = request("user/get",{"user":user,"dbname":database})
print(check_user_exist.text)
if check_user_exist.text == "false": if check_user_exist.text == "false":
request("user/set", {"user": user, "dbname": database,"hardwareID": check_hostname.text}) request("user/set", {"user": user, "dbname": database,"hardwareID": check_hostname.text})
# else: else:
# request("user/set/lastlogon", {"userID": check_user_exist.text, "dbname": database, "lastlogon": system_info.get_lastlogon(user)}) if system_type == "Client":
next
else:
request("user/set/lastlogon", {"userID": check_user_exist.text, "dbname": database, "lastlogon": system_info.get_lastlogon(user)})
## Check Host
if check_hostname.text == "false":
request("host/set",{"hostname":hostname,"user": os.getlogin(),"ipadresse":system_info.get_local_ip(),"winver":system_info.get_winver(),"cpuname":system_info.get_cpu_brand(),"cores":system_info.get_cpu_core(),"ram":system_info.get_ram_info(),"hddused":space_used(),"hddfree":space_free(),"hddtotal":space_total(),"netvolumeuser":user,"dbname":database})
else:
request("host/update",
{"hostname":hostname,"user": os.getlogin(),"ipadresse":system_info.get_local_ip(),"winver":system_info.get_winver(),"cpuname":system_info.get_cpu_brand(),"cores":system_info.get_cpu_core(),"ram":system_info.get_ram_info(),"hddused":space_used(),"hddfree":space_free(),"hddtotal":space_total(),"netvolumeuser":user,"dbname":database})
# ### Check CPU
# check_cpu = request("host/get/cpu",{"cputype":system_info.get_cpu_brand(),"ghz":system_info.get_cpu_ghz()})
# if check_cpu.text == "false":
# request("host/set/cpu",{"cputype":system_info.get_cpu_brand(),"cpucore":system_info.get_cpu_core()})
#
# ### Check Mainboard
# request("host/mainboard",{"mainboardmodel":system_info.get_mainboard_model(),"mainboardvendor":system_info.get_mainboard_vendor()})
### Check NetVolume Exist ### Check NetVolume Exist
netvolume = request("host/get/netvolume",{"user":user,"dbname":database}) netvolume = request("host/get/netvolume",{"user":user,"dbname":database})
# if netvolume.text == "false": if netvolume.text == "false":
# print(net_volume.get_netvolume()) print(net_volume.get_netvolume())
# if net_volume.get_netvolume() is None: if net_volume.get_netvolume() is None:
# with open("log.txt", "a") as datei: ## Schreibt ergebnissse in Log File with open("log.txt", "a") as datei: ## Schreibt ergebnissse in Log File
# datei.writelines(f"Keine Netvolume vorhanden!" + "\n") ## WRITE TO ERRORLOG datei.writelines(f"Keine Netvolume vorhanden!" + "\n") ## WRITE TO ERRORLOG
# # pushover_send("Keine Netvolume vorhanden!", hostname) ## SEND ERROR LOG TO PUSHOVER # pushover_send("Keine Netvolume vorhanden!", hostname) ## SEND ERROR LOG TO PUSHOVER
# else: else:
# for i in netvolume.json(): ##LIST FORM netvolume for i in netvolume.json(): ##LIST FORM netvolume
# print(i[2]) print(i[2])
# if i != "-": if i != "-":
# if not os.path.isdir(f"{i[1]}"): if not os.path.isdir(f"{i[1]}"):
# try: try:
# result = subprocess.run(["net", "use", f"{i[1]}:", f"{i[0]}"], capture_output=True, check=True) ## MOUNT VOLUME subprocess.run(["net", "use", f"{i[1]}:", f"{i[0]}"], capture_output=True, check=True) ## MOUNT VOLUME
# script = fr'''$shell = New-Object -ComObject Shell.Application script = fr'''$shell = New-Object -ComObject Shell.Application
# $shell.NameSpace("{i[1]}:").Self.Name = "{i[2]}"''' ### Schreibt den Namen der Netzlaufwerke um $shell.NameSpace("{i[1]}:").Self.Name = "{i[2]}"''' ### Schreibt den Namen der Netzlaufwerke um
# subprocess.run(["powershell", "-Command", script], capture_output = True,text = True) subprocess.run(["powershell", "-Command", script], capture_output = True,text = True)
# print(script) except subprocess.CalledProcessError as e:
# print("net", "use", f"{i[1]}:", f"{i[0]}") time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M")
# except subprocess.CalledProcessError as e: if "85" in str(e.stderr):
# time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M") print(f"{time} - Volume exists {i[0]} {i[1]}")
# if "85" in str(e.stderr): elif "1223" in str(e.stderr):
# print(f"{time} - Volume exists {i[0]} {i[1]}") errorcode = f"{time} - {user} has no access to {i[0]} {i[1]}"
# elif "1223" in str(e.stderr): elif "53" in str(e.stderr):
# errorcode = f"{time} - {user} has no access to {i[0]} {i[1]}" errorcode = f"{time} - Volume was not Found {i[0]} {i[1]}"
# elif "53" in str(e.stderr): elif "64" in str(e.stderr):
# errorcode = f"{time} - Volume was not Found {i[0]} {i[1]}" errorcode = f"{time} - Volume Path not found {i[0]} {i[1]}"
# elif "64" in str(e.stderr): elif "1219" in str(e.stderr):
# errorcode = f"{time} - Volume Path not found {i[0]} {i[1]}" errorcode = f"{time} - Multiconnection to Folder not allow {i[0]} {i[1]}"
# elif "1219" in str(e.stderr): else:
# errorcode = f"{time} - Multiconnection to Folder not allow {i[0]} {i[1]}" errorcode = f"{time} - Unknow ERROR Code {str(e.stderr)}"
# else:
# errorcode = f"{time} - Unknow ERROR Code {str(e.stderr)}"
# with open("log.txt", "a") as datei:
# datei.writelines(f"{errorcode}" + "\n") ## WRITE TO ERRORLOG
# with open("log.txt", "a") as datei:
# datei.writelines(f"{errorcode}" + "\n") ## WRITE TO ERRORLOG
# # pushover_send(errorcode, hostname) ## SEND ERROR LOG TO PUSHOVER # # pushover_send(errorcode, hostname) ## SEND ERROR LOG TO PUSHOVER
# #
# while True: # while True: