我很难为下面提到的ZabbixAPILayer类编写测试用例。我不知道我怎么能嘲笑那里的“zabbix\u conn\u obj”。任何帮助都将不胜感激。谢谢!你知道吗
文件:externalapi/apilayer.py公司你知道吗
from zabbix.api import ZabbixAPI
import json
import time
class ZabbixAPILayer(object):
def uptime(self,arg,zabbix_conn_obj):
try:
getUpdateItem = zabbix_conn_obj.do_request("item.get", {"host":arg})
lastclock=getUpdateItem['result'][37].get('lastclock')
lastclock=int(lastclock)
curclock=int(time.time())
check_val=curclock-lastclock
limit=60*1000
if check_val<limit:
lastval=getUpdateItem['result'][37].get('lastvalue')
return time.strftime("%H:%M:%S", time.gmtime(float(getUpdateItem['result'][37].get('lastvalue'))))
else:
return "-"
except:
return "NOT AVAILABLE"
.....
class APILayer(ZabbixAPILayer):
def __init__(self):
self.zabbix_conn_obj=ZabbixAPI(url=settings.ZABBIX_URL, user=settings.ZABBIX_USER, password=settings.ZABBIX_PWD)
def uptime(self,arg):
return super(APILayer,self).uptime(arg,self.zabbix_conn_obj)
.....
文件:基本/管理员.py你知道吗
......
from ..externalapis.apilayer import APILayer
......
gen_obj= APILayer()
gen_obj.uptime()
......
谢谢你的评论。让它工作!我就是这样做的
相关问题 更多 >
编程相关推荐