Commit c8f2474c authored by Olav Morken's avatar Olav Morken

Add get-history command.

parent 6e6b2972
#!/usr/bin/env python3
import argparse
from collections import defaultdict
import datetime
import getpass
import json
import os
......@@ -320,6 +321,18 @@ def find_dead_trapper_items(args):
))
def get_history(args):
items = invoke('item.get', itemids=args.itemid)
if not items:
print('No item with ID {itemid}'.format(itemid=args.itemid), file=sys.stderr)
sys.exit(1)
item = items[0]
for value in invoke('history.get', history=int(item['value_type']), itemids=args.itemid, sortfield='clock', sortorder='ASC'):
ts = int(value['clock']) + int(value['ns']) / 1e12
ts = datetime.datetime.utcfromtimestamp(ts)
print(ts.strftime('%Y-%m-%d %H:%M:%S.%f+0000'), value['value'])
def parse_args():
parser = argparse.ArgumentParser('Zabbix cmd line client')
subparsers = parser.add_subparsers(help='Command', dest='command')
......@@ -363,6 +376,9 @@ def parse_args():
find_dead_trapper_items = subparsers.add_parser('find-dead-trapper-items', help="Find trapper items no longer receiving data")
parser_get_history = subparsers.add_parser('get-history', help='Get history for item ID')
parser_get_history.add_argument('itemid', type=int, help='Item ID')
return parser.parse_args()
......@@ -392,6 +408,8 @@ def main():
return get_triggers(args)
elif args.command == 'find-dead-trapper-items':
return find_dead_trapper_items(args)
elif args.command == 'get-history':
return get_history(args)
else:
raise NotImplementedError('Unknown command: {command}'.format(command=args.command))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment