From f3d1606d6b9ab8064a97476ed7cc1e24dbdeab75 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 21 Mar 2015 16:33:28 -0400 Subject: [PATCH] add event cli commands --- lib/api/event.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/lib/api/event.js b/lib/api/event.js index 1e64bdb..167eb92 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -139,5 +139,71 @@ function query(start, end, parameters, callback){ module.exports = { create: create, get: get, - query: query + query: query, + getUsage: function(){ + return [ + "${command} event get ", + "${command} event query [--priority ] [--sources ] [--tags ]", + "${command} event create <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]" + ]; + }, + getHelp: function(){ + return [ + "Event:", + " Commands:", + " get <event-id> get the event with the provided <event-id>", + " query <from> <to> query the event stream between <from> and <to> POSIX timestamps", + " create <title> <text> create a new event with <title> and <text>", + " Options:", + " --priority <priority> the priority of the event \"normal\" or \"low\"", + " --sources <sources> a comma separated list of sources (e.g. \"users,jenkins,chef\")", + " --tags <tags> a comma separated list of \"tag:value\"'s", + " --time <time> a POSIX timestamp for when the event happened", + " --host <host> the host to associate the event to", + " --type <type> the event type \"error\", \"warning\", \"info\" or \"success\"", + " --agg-key <agg-key> an aggregation key to use to associate like events", + " --source <source> the source to associate with this event (e.g. \"users\", \"jenkins\", etc)" + ]; + }, + handleCli: function(subcommand, args, callback){ + if(subcommand === "get" && args._.length > 4){ + get(parseInt(args._[4]), callback); + } else if(subcommand === "query" && args._.length > 5){ + var from = parseInt(args._[4]); + var to = parseInt(args._[5]); + var parameters = {}; + if(args["sources"]){ + parameters.sources = args["sources"]; + } + if(args["tags"]){ + parameters.tags = args["tags"]; + } + query(from, to, parameters, callback); + } else if(subcommand === "create" && args._.length > 5){ + var title = args._[4]; + var text = args._[5]; + var properties = {}; + if(args["priority"]){ + properties.priority = args["priority"]; + } + if(args["host"]){ + properties.host = args["host"]; + } + if(args["time"]){ + properties.date_happened = parseInt(args["time"]); + } + if(args["tags"]){ + properties.tags = args["tags"].split(","); + } + if(args["agg-key"]){ + properties.aggregation_key = args["agg-key"]; + } + if(args["source"]){ + properties.source_type_name = args["source"]; + } + create(title, text, properties, callback); + } else { + callback("unknown subcommand or arguments try `dogapi event --help` for help", false); + } + } };