From c5581cad0b1bf81e2e4b13ca1f4035a902876911 Mon Sep 17 00:00:00 2001 From: Eddie Sheffield Date: Fri, 20 Mar 2015 11:34:09 -0400 Subject: [PATCH] Add functionality for counting events Similar to the existing streams functionality, this patch exposes in klugman the ability added to quincy to count filtered events. There are corresponding changes in winchester, quincy, and quince. Change-Id: I83bbf901552e5de8e53487ef72016a171a8367eb --- klugman/v1.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- setup.cfg | 2 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/klugman/v1.py b/klugman/v1.py index 636cd3a..6b4a681 100644 --- a/klugman/v1.py +++ b/klugman/v1.py @@ -247,11 +247,58 @@ class Events(object): return base.get(version.base_url, cmd, params) +class NumEvents(object): + """usage: + klugman.py num-events [options] + + options: + --debug + --name + return events of type + --from + list events generated before datetime + --to + list events generated after datetime + --traits + list events with specific traits + + Trait format: + "trait:value;trait:value;..." + """ + + def cmdline(self, version, cmdline): + arguments = docopt(NumEvents.__doc__, argv=cmdline) + debug = version.base_args['--debug'] + if debug: + print arguments + + response = self.do_event(version, arguments) + raw_rows = response.json(object_hook=jsonutil.object_hook) + + keys = ['count'] + base.dump_response(keys, raw_rows) + + def do_event(self, version, arguments): + _from = arguments.get('--from') + _to = arguments.get('--to') + name = arguments.get('--name') + traits = arguments.get('--traits') + + cmd = "events/count" + params = base.remove_empty({'from_datetime': _from, + 'to_datetime': _to, + 'event_name': name, + 'traits': traits}) + + return base.get(version.base_url, cmd, params) + + class V1(base.Impl): """usage: klugman.py streams [...] [options] klugman.py num-streams [...] [options] klugman.py events [...] [options] + klugman.py num-events [...] [options] -h, --help show command options """ @@ -259,5 +306,6 @@ class V1(base.Impl): def __init__(self, base_url, base_args): cmds = {'streams': Streams(), 'num-streams': NumStreams(), - 'events': Events()} + 'events': Events(), + 'num-events': NumEvents()} super(V1, self).__init__(base_url, base_args, cmds, V1.__doc__) diff --git a/setup.cfg b/setup.cfg index 6c6e5dd..93750e1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = klugman -version = 0.2 +version = 0.3 author = Dark Secret Software Inc. author-email = admin@darksecretsoftware.com summary = StackTach.v3 Client