我们正在尝试计算glassfish中的实例。当使用len()函数时,它总是返回1而不是0。也许它会在列表[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')
str.split
的结果不能是空的list
:如果要检查获得的列表是否包含
^{pr2}$any
非空字符串,请使用any
:如果要
filter
出空字符串,请使用filter
:或列表理解:
我刚刚意识到
str.split
可以返回一个空列表。但是只有在没有参数的情况下调用时:文档中有解释:
相关问题 更多 >
编程相关推荐