|
|
|
@ -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 <event-id>", |
|
|
|
"${command} event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]", |
|
|
|
"${command} event create <title> <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); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |