ADD zls_check.py
parent
4a0edfa446
commit
311e60461c
76
main.py
76
main.py
|
|
@ -49,6 +49,10 @@ else:
|
|||
{"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()
|
||||
|
||||
|
||||
### Check User
|
||||
check_user_exist = request("user/get",{"user":user,"dbname":database})
|
||||
if check_user_exist.text == "false":
|
||||
|
|
@ -67,42 +71,42 @@ request("host/mainboard",{"mainboardmodel":system_info.get_mainboard_model(),"ma
|
|||
### Check NetVolume Exist
|
||||
netvolume = request("host/get/netvolume",{"user":user,"dbname":database})
|
||||
|
||||
if netvolume.text == "false":
|
||||
print(net_volume.get_netvolume())
|
||||
if net_volume.get_netvolume() is None:
|
||||
with open("log.txt", "a") as datei: ## Schreibt ergebnissse in Log File
|
||||
datei.writelines(f"Keine Netvolume vorhanden!" + "\n") ## WRITE TO ERRORLOG
|
||||
# pushover_send("Keine Netvolume vorhanden!", hostname) ## SEND ERROR LOG TO PUSHOVER
|
||||
else:
|
||||
for i in netvolume.json(): ##LIST FORM netvolume
|
||||
print(i[2])
|
||||
if i != "-":
|
||||
if not os.path.isdir(f"{i[1]}"):
|
||||
try:
|
||||
result = 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
|
||||
$shell.NameSpace("{i[1]}:").Self.Name = "{i[2]}"''' ### Schreibt den Namen der Netzlaufwerke um
|
||||
subprocess.run(["powershell", "-Command", script], capture_output = True,text = True)
|
||||
print(script)
|
||||
print("net", "use", f"{i[1]}:", f"{i[0]}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M")
|
||||
if "85" in str(e.stderr):
|
||||
print(f"{time} - Volume exists {i[0]} {i[1]}")
|
||||
elif "1223" in str(e.stderr):
|
||||
errorcode = f"{time} - {user} has no access to {i[0]} {i[1]}"
|
||||
elif "53" in str(e.stderr):
|
||||
errorcode = f"{time} - Volume was not Found {i[0]} {i[1]}"
|
||||
elif "64" in str(e.stderr):
|
||||
errorcode = f"{time} - Volume Path not found {i[0]} {i[1]}"
|
||||
elif "1219" in str(e.stderr):
|
||||
errorcode = f"{time} - Multiconnection to Folder not allow {i[0]} {i[1]}"
|
||||
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
|
||||
# if netvolume.text == "false":
|
||||
# print(net_volume.get_netvolume())
|
||||
# if net_volume.get_netvolume() is None:
|
||||
# with open("log.txt", "a") as datei: ## Schreibt ergebnissse in Log File
|
||||
# datei.writelines(f"Keine Netvolume vorhanden!" + "\n") ## WRITE TO ERRORLOG
|
||||
# # pushover_send("Keine Netvolume vorhanden!", hostname) ## SEND ERROR LOG TO PUSHOVER
|
||||
# else:
|
||||
# for i in netvolume.json(): ##LIST FORM netvolume
|
||||
# print(i[2])
|
||||
# if i != "-":
|
||||
# if not os.path.isdir(f"{i[1]}"):
|
||||
# try:
|
||||
# result = 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
|
||||
# $shell.NameSpace("{i[1]}:").Self.Name = "{i[2]}"''' ### Schreibt den Namen der Netzlaufwerke um
|
||||
# subprocess.run(["powershell", "-Command", script], capture_output = True,text = True)
|
||||
# print(script)
|
||||
# print("net", "use", f"{i[1]}:", f"{i[0]}")
|
||||
# except subprocess.CalledProcessError as e:
|
||||
# time = datetime.datetime.now().strftime("%d.%m.%Y %H:%M")
|
||||
# if "85" in str(e.stderr):
|
||||
# print(f"{time} - Volume exists {i[0]} {i[1]}")
|
||||
# elif "1223" in str(e.stderr):
|
||||
# errorcode = f"{time} - {user} has no access to {i[0]} {i[1]}"
|
||||
# elif "53" in str(e.stderr):
|
||||
# errorcode = f"{time} - Volume was not Found {i[0]} {i[1]}"
|
||||
# elif "64" in str(e.stderr):
|
||||
# errorcode = f"{time} - Volume Path not found {i[0]} {i[1]}"
|
||||
# elif "1219" in str(e.stderr):
|
||||
# errorcode = f"{time} - Multiconnection to Folder not allow {i[0]} {i[1]}"
|
||||
# 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
|
||||
# # pushover_send(errorcode, hostname) ## SEND ERROR LOG TO PUSHOVER
|
||||
#
|
||||
# while True:
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ def get_winver():
|
|||
|
||||
def get_local_ip():
|
||||
powershell_script = '''
|
||||
(Get-NetIPAddress | Where-Object { $_.PrefixOrigin -eq "Dhcp" }).IPAddress
|
||||
Get-NetIPAddress | Where-Object { $_.PrefixOrigin -eq "Dhcp" -and $_.InterfaceAlias -like "*Ethernet*" } | Select-Object -ExpandProperty IPAddress
|
||||
'''
|
||||
result = subprocess.check_output(["powershell.exe", "-command", powershell_script], universal_newlines=True)#
|
||||
ip = result.rsplit('.',1)
|
||||
|
|
@ -97,4 +97,16 @@ def get_lastlogon(user):
|
|||
result = subprocess.check_output(["powershell.exe", "-command", powershell_script], universal_newlines=True)
|
||||
return result
|
||||
|
||||
print(get_cpu_brand())
|
||||
def get_client_info():
|
||||
powershell_script = f'''Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty ProductType'''
|
||||
result = subprocess.check_output(["powershell.exe", "-command", powershell_script], universal_newlines=True)
|
||||
if result[0] == "1":
|
||||
return "Client"
|
||||
else:
|
||||
return "Server"
|
||||
|
||||
def get_smb_credential():
|
||||
powershell_script = f'''Get-SmbConnection | Select-Object -ExpandProperty Credential'''
|
||||
result = subprocess.check_output(["powershell.exe", "-command", powershell_script], universal_newlines=True)
|
||||
result.split("\\")
|
||||
return result[1]
|
||||
Loading…
Reference in New Issue