参考下面函数:
def getValueFromHost(host,itemName):
'''
:param host: host name,usually ip,like '10.189.66.131',but need to be string type.
:param itemName: like "*cpu_model*", need to be string type.
:return: The last value of itemName for specific 'host'. String type.
'''
for h in zapi.item.get(output=["itemid", "name", "hostid", "value_type", "lastvalue"], host=host,
search={"name": '*'+itemName+'*'}, searchWildcardsEnabled='1'):
return (h['lastvalue'])
def getValueFromItem(host,item):
'''
:param host:
:param item:
:return: return 数组
'''
data=[]
for eachItem in item:
data.append(getValueFromHost(host,eachItem))
return data
另外,获取某主机资产清单值,使用以下函数:
def getInventorydataFromHostName(hostname,item):
for h in zapi.host.get(output=['host'], filter={'host': hostname},
selectInventory=[item]):
return h['inventory'][item]
另外,预先导入:
from pyzabbix import ZabbixAPI, ZabbixAPIException
from datetime import datetime
import time
import warnings
