简体   繁体   English

使用 python api 从 zabbix 获取历史记录

[英]getting history from zabbix with python api

i have one question about getting history from zabbix with python.我有一个关于使用 python 从 zabbix 获取历史的问题。 I'm only start learn python, so please don't dislike) so, i have little script python, who get the host, who showing all items, and i try from this information get history for the one second, but then don't filter.我才刚刚开始学习python,所以请不要不喜欢)所以,我有一个小脚本python,谁得到主机,谁显示所有项目,我尝试从这个信息中获取一秒钟的历史记录,但是然后不要' t 过滤器。

>>> from pyzabbix import ZabbixAPI
>>> zapi = ZabbixAPI("http://192.168.55.128/zabbix")
>>> zapi.login("admin", "zabbix")
>>> for host in zapi.host.get(filter={'groupids': '9'}):
...     print host
>>>for item in zapi.item.get(filter={'host':'Zabbix server', 'name' : 'Processor load (5 min average per core)'}):
...     print item
>>> history = zapi.history.get({"itemid" : "23297","time_from":"2014-10-04 00:10:00", "time_till":"2014-10-04 00:10:01", "output":"extend" })
>>> print history

and after this, i have all items, and no filter time, why?在此之后,我拥有所有项目,并且没有过滤时间,为什么? help please.请帮忙。 PS what i must filter, so them return to me only the value (for the setting date) PS我必须过滤什么,所以他们只返回给我的值(设置日期)

Thanks谢谢

In time_from and time_till parameters, try using a Unix timestamp, like so: time_fromtime_till参数中,尝试使用Unix时间戳,如下所示:

>>> history = zapi.history.get({"itemids":"23297", "time_from":"1412370600", "time_till":"1412370601", "output":"extend" })
>>> print history

I don't know if anyone else has had this issue but it's 2022 and after a whole week being frustrated the answer posted down is the only thing that has helped me AND ACTUALLY WORKED:我不知道其他人是否遇到过这个问题,但现在是 2022 年,经过整整一周的沮丧之后,发布的答案是唯一对我有帮助并且确实有效的方法:

history=zapi.history.get(hostids=['10333'],itemids[56411],time_from=1489420800,time_till=1489562140) history=zapi.history.get(hostids=['10333'],itemids[56411],time_from=1489420800,time_till=1489562140)

history=zapi.history.get(hostids=['10333'],itemids=
[56411],time_from=1489420800,time_till=1489562140)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM