我试图用zabbixhostid -> itemid -> history
API捕捉以下序列,但它没有返回任何内容。我需要这个脚本来返回ZABBIX收集的最后一个值,包括item id+hostname
脚本
from zabbix.api import ZabbixAPI
from datetime import datetime
import time
zapi = ZabbixAPI(url='http://192.168.1.250/zabbix', user='Admin', password='zabbix')
fromTimestamp = int(time.mktime(datetime.now().timetuple()))
tillTimestamp = int(fromTimestamp - 60 * 60 * 1) # 1 hours
# Get only the host of the specified hostgroup
hosts = zapi.host.get(groupids='15',output='extend')
for host in hosts:
items = zapi.item.get(itemid='28689', host=host['host'], output='extend' )
for item in items:
values = zapi.history.get(itemids=item['itemid'], time_from=fromTimestamp, time_till=tillTimestamp, output='extend')
for historyValue in values:
print(host['host'],item['itemid'],historyValue['value'])
输出
什么也不能回报我
期望输出
^{pr2}$
您的代码中有一些问题(静态
itemid
,在history.get
中缺少参数等等),我将尝试总结所有问题。在您正在按静态主机组id进行筛选,因此我假设您有多个主机,并且您需要每个主机的特定项的值,如下所示:
输出应该类似于:
一个工作的python实现:
^{pr2}$相关问题 更多 >
编程相关推荐