import paramiko,os,time
#!/usr/bin/env python
#Please modify server_info with your XMS info
server_info = {
'hostname': '172.16.83.60',
'port':'22',
'username': 'root',
'passwd':'2@WSX3edc'
}
result = {}
def install_paramiko(wait_time = 120):
while True:
prompt_input = input('paramiko is a python module. It is not installed by default. Hv paramiko installed before(Y/N)?')
if prompt_input=='N':
os.system('pip install paramiko')
print('please wait 120 second for paramiko to be installed')
time.sleep(wait_time)
break
elif prompt_input =='Y':
break
else:
print('Dear, This script need paramiko installed')
def analyze_conn(lines):
for line in lines:
if line.startswith("pooled.datasource.url="):
result["pooled.datasource.url"] = line
if "jdbc:jtds:sqlserver" in line:
result["driver type"] = "JDTS"
if "useNTLMv2=true" in line:
result["Authentication"] = "Windows Authentication"
else:
result["Authentication"] = "SQL Authentication"
if "ssl=off" in line:
result["SSL"] = "Off"
else:
result["SSL"] = "On"
else:
result["driver type"] = "JDBC"
if "authenticationScheme" in line:
result["Authentication"] = "Windows Authentication"
else:
result["Authentication"] = "SQL Authentication"
if "encrypt=true" in line:
result["SSL"] = "On"
else:
result["SSL"] = "Off"
return result
print(result)
return result
install_paramiko()
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_info['hostname'], server_info['port'], server_info['username'], server_info['passwd'])
stdin, stdout, stderr = ssh.exec_command('cat /opt/sas/sw/tomcat/inst1/webapps/ROOT/WEB-INF/classes/ew-config.properties')
ew_text = stdout.read().decode()
f_save = open(".temp.txt", 'w+')
print(ew_text, file=f_save)
f_open = open('.temp.txt')
analyze_conn(f_open)
print("Driver Type : {0}".format(result["driver type"]))
print ("Authentication : {0}".format(result["Authentication"]))
print ("SSL : {0}".format(result["SSL"]))
print ("pooled.datasource.url: {0}".format(result["pooled.datasource.url"]))
ssh.close()