Last active
October 18, 2015 21:49
-
-
Save teriyakichild/d76d9398b83a7552a826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getpass | |
import sys | |
import time | |
from pyzabbix import ZabbixAPI | |
def get_zapi(host, user, password): | |
zapi = ZabbixAPI(host) | |
zapi.session.verify = False | |
zapi.login(user, password) | |
return zapi | |
def get_history(zapi, itemid, time_from, time_till): | |
items = zapi.item.get(itemids=item, output=['value_type']) | |
if len(items) == 1: | |
value_type = items[0]['value_type'] | |
else: | |
raise Exception('Item not foudn') | |
ret = zapi.history.get(itemids=itemid, | |
time_from=time_from, | |
time_till=time_till, | |
history=value_type, | |
output='extend' | |
) | |
return ret | |
if __name__ == '__main__': | |
host = sys.argv[1] | |
item = sys.argv[2] | |
minutes_ago = int(sys.argv[3]) | |
seconds_ago = minutes_ago * 60 | |
now = int(time.time()) | |
user = getpass.getuser() | |
password = getpass.getpass() | |
zapi = get_zapi(host, user, password) | |
results = get_history(zapi, item, (now - seconds_ago), now) | |
print results | |
import pdb;pdb.set_trace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment