#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright (C) 2011-2013 Cesnet z.s.p.o # Use of this source is governed by a 3-clause BSD-style license, see LICENSE file. from warden_client import Client, Error, read_cfg import json from time import time, gmtime from math import trunc from uuid import uuid4 from pprint import pprint from os import path def gen_random_idea(): def get_precise_timestamp(): t = time() us = trunc((t-trunc(t))*1000000) g = gmtime(t) iso = '%04d-%02d-%02dT%02d:%02d:%02d.%0dZ' % (g[0:6]+(us,)) return iso return { "Format": "IDEA0", "ID": str(uuid4()), "DetectTime": get_precise_timestamp(), "Category": ["Test"], } wclient = Client(**read_cfg("warden_client.cfg")) # Also inline arguments are possible: # wclient = Client( # url = 'https://warden.example.com/warden3', # keyfile = '/opt/warden3/etc/key.pem', # certfile = '/opt/warden3/etc/cert.pem', # cafile = '/opt/warden3/etc/tcs-ca-bundle.pem', # timeout=10, # errlog={"level": "debug"}, # filelog={"level": "debug"}, # idstore="MyClient.id", # name="MyClient") print "=== Getting 10 events ===" start = time() ret = wclient.getEvents(count=10) print "Time: %f" % (time()-start) for e in ret: print e if ret: print len(ret) print "=== Sending 500 events ===" start = time() ret = wclient.sendEvents([gen_random_idea() for i in range(500)]) if ret: print ret print "Time: %f" % (time()-start) print "=== Server info ===" info = wclient.getInfo() if not isinstance(info, Error): pprint(info)