我们正在尝试计算 glassfish 中的实例。当使用 len() 函数时,它总是返回 1 而不是 0。也许它用空白空间或其他东西填充 list[0]。这是我们的代码。
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.get('hostname'),int(self.get('port')),self.get('username'),allow_agent=True)
#try:
stdin, stdout, stderr = ssh.exec_command('~/glassfish3/glassfish/bin/asadmin list-instances')
result = stdout.readlines()
#except Exception, e:
# return MonitoringResult(MonitoringResult.OK,'all instances up!')
result = "".join(result)
#line = re.compile(r'\bnot\s\D*\n')
#rline = "".join(line.findall((result)))
line2=re.compile(r'\bnot')
rline2 = ";".join(line2.findall((result)))
print(rline2)
i = 0
listr = rline2.split(";")
while(i < (len(listr)):
i+=1
print(i)
if rline2:
return MonitoringResult(MonitoringResult.CRITICAL,'instance down')
else:
return MonitoringResult(MonitoringResult.OK, 'All instances are up')