wavefront-client 3.5.3 → 3.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -2
  3. data/README-cli.md +84 -60
  4. data/bin/wavefront +84 -69
  5. data/lib/wavefront/alerting.rb +14 -3
  6. data/lib/wavefront/batch_writer.rb +7 -0
  7. data/lib/wavefront/cli.rb +15 -17
  8. data/lib/wavefront/cli/alerts.rb +15 -10
  9. data/lib/wavefront/cli/batch_write.rb +12 -3
  10. data/lib/wavefront/cli/events.rb +19 -3
  11. data/lib/wavefront/cli/sources.rb +22 -12
  12. data/lib/wavefront/cli/ts.rb +9 -1
  13. data/lib/wavefront/cli/write.rb +7 -0
  14. data/lib/wavefront/client.rb +9 -5
  15. data/lib/wavefront/client/version.rb +1 -1
  16. data/lib/wavefront/constants.rb +20 -0
  17. data/lib/wavefront/events.rb +26 -4
  18. data/lib/wavefront/metadata.rb +23 -6
  19. data/lib/wavefront/opt_handler.rb +61 -0
  20. data/spec/cli_spec.rb +584 -0
  21. data/spec/spec_helper.rb +42 -0
  22. data/spec/wavefront/alerting_spec.rb +8 -9
  23. data/spec/wavefront/batch_writer_spec.rb +1 -1
  24. data/spec/wavefront/cli/alerts_spec.rb +5 -4
  25. data/spec/wavefront/cli/batch_write_spec.rb +4 -2
  26. data/spec/wavefront/cli/events_spec.rb +3 -2
  27. data/spec/wavefront/cli/sources_spec.rb +3 -2
  28. data/spec/wavefront/cli/write_spec.rb +4 -2
  29. data/spec/wavefront/cli_spec.rb +11 -43
  30. data/spec/wavefront/client_spec.rb +2 -2
  31. data/spec/wavefront/events_spec.rb +1 -1
  32. data/spec/wavefront/metadata_spec.rb +1 -1
  33. data/spec/wavefront/mixins_spec.rb +1 -1
  34. data/spec/wavefront/opt_handler_spec.rb +89 -0
  35. data/spec/wavefront/resources/conf.yaml +10 -0
  36. data/spec/wavefront/response_spec.rb +3 -3
  37. data/spec/wavefront/validators_spec.rb +1 -1
  38. data/spec/wavefront/writer_spec.rb +1 -1
  39. metadata +9 -3
  40. data/.ruby-version +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beeb02e2fa86d2049cf941fe782f4a57aff4320a
4
- data.tar.gz: 1a7fc2bdf6fd1f8015856519daee209889199377
3
+ metadata.gz: 5c289e188276ac63035e6acd3ea84ab59721e63b
4
+ data.tar.gz: eb9d96bae403aa21ed775bf37bb5ad85d8c078c3
5
5
  SHA512:
6
- metadata.gz: 0f3b60f1c518d9dae1cce42fe8b246c2f60d561008ef6ce941029db9d1ad029f61994e1fd102da4583729f574e2687b7fd22f9ef01affab80b6de1866cf9a25b
7
- data.tar.gz: a3a604a315860308f795c813abfe45a3cd0cf9c9d50d8c85529429a5f854a0c2742b58f81bef024d2f9025c70096a10c62a968c46f3716f65cf6d7cf209c808d
6
+ metadata.gz: 18b87b4ff437336b124a353fb982bdea69c0a34ed32314a0fad69db6f636cb33c0b529cad6dffa95137ef18a952b1ad0d1066959e01fa25e652bceb04e78b5e8
7
+ data.tar.gz: c926ec0a4245bba66b92f64daa28cbb300c8abad127d3a2f302b6c05b14e234e0109b6986678bb220c6651886125a716e96a154e75ac5c7ee81fc9a25d0564e1
@@ -4,8 +4,10 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1.10
7
- - 2.2.5
8
- - 2.3.1
7
+ - 2.2.6
8
+ - 2.3.3
9
+ - 2.4.0
10
+ before_install: gem install bundler --no-rdoc --no-ri
9
11
  deploy:
10
12
  provider: rubygems
11
13
  api_key:
@@ -12,11 +12,18 @@ The following options are valid in almost all contexts.
12
12
  ```
13
13
  -c, --config=FILE path to configuration file [default: ~/.wavefront]
14
14
  -P, --profile=NAME profile in configuration file [default: default]
15
- -t, --token=TOKEN Wavefront authentication token
16
15
  -D, --debug enable debug mode
16
+ -V, --verbose enable verbose mode
17
17
  -h, --help show help for command
18
18
  ```
19
19
 
20
+ Debug mode will show you combined options, and debug output from
21
+ `rest-client`. It also shows the full stack trace should a command
22
+ fail.
23
+
24
+ In the following usage examples, the global options have been omitted
25
+ to save space.
26
+
20
27
  ## `ts` Mode: Retrieving Timeseries Data
21
28
 
22
29
  The `ts` command is used to submit a standard timeseries query to
@@ -26,13 +33,13 @@ query.
26
33
 
27
34
  ```
28
35
  Usage:
29
- wavefront ts [-c file] [-P profile] [-E endpoint] [-t token] [-OD]
36
+ wavefront ts [-c file] [-P profile] [-E endpoint] [-t token] [-ODV]
30
37
  [-S | -m | -H | -d] [-s time] [-e time] [-f format] [-p num]
31
38
  [-X bool] <query>
32
39
 
33
40
  Options:
34
- -E, --endpoint=URI cluster endpoint [default:
35
- metrics.wavefront.com]
41
+ -E, --endpoint=URI cluster endpoint [metrics.wavefront.com]
42
+ -t, --token=TOKEN Wavefront authentication token
36
43
  -S, --seconds query granularity of seconds
37
44
  -m, --minutes query granularity of minutes
38
45
  -H, --hours query granularity of hours
@@ -41,13 +48,12 @@ Options:
41
48
  strptime parseable format
42
49
  -e, --end=TIME end of query window in epoch seconds or
43
50
  strptime parseable format
44
- -f, --format=STRING output format (raw, ruby, graphite,
45
- highcharts, human)
46
- [default: raw]
51
+ -f, --format=STRING output format (raw, ruby, graphite, highcharts, human)
52
+ [raw]
47
53
  -p, --prefixlength=NUM number of path elements to treat as prefix
48
- in schema manipulation. [default: 1]
54
+ in schema manipulation. [1]
49
55
  -X, --strict=BOOL Do not return points outside the query
50
- window. [default: true]
56
+ window. [true]
51
57
  -O, --includeObsoleteMetrics include metrics unreported for > 4 weeks
52
58
  ```
53
59
 
@@ -106,17 +112,18 @@ formatters.
106
112
 
107
113
  ```
108
114
  Usage:
109
- wavefront alerts [-c file] [-P profile] [-E endpoint] [-t token]
115
+ wavefront alerts [-D] [-c file] [-P profile] [-E endpoint] [-t token] [-V]
110
116
  [-f format] [-p tag] [ -s tag] <state>
111
117
 
112
118
  Options:
113
- -E, --endpoint=URI cluster endpoint [default: metrics.wavefront.com]
114
- -f, --format=STRING output format (ruby, json, human)
115
- [default: human]
116
- -p, --private=TAG retrieve only alerts with named private tags,
117
- comma delimited.
118
- -s, --shared=TAG retrieve only alerts with named shared tags, comma
119
- delimited.
119
+ -E, --endpoint=URI cluster endpoint [metrics.wavefront.com]
120
+ -t, --token=TOKEN Wavefront authentication token
121
+ -f, --alertformat=STRING output format (ruby, json, human)
122
+ []
123
+ -p, --private=TAG retrieve only alerts with named private tags,
124
+ comma delimited.
125
+ -s, --shared=TAG retrieve only alerts with named shared tags,
126
+ comma delimited.
120
127
  ```
121
128
 
122
129
  ### Examples
@@ -160,26 +167,29 @@ The `event` command is used to open and close Wavefront events.
160
167
 
161
168
  ```
162
169
  Usage:
163
- wavefront event create [-V] [-c file] [-P profile] [-E endpoint] [-t token]
164
- [-d description] [-s time] [-i | -e time] [-l level] [-t type]
170
+ wavefront event create [-DV] [-c file] [-P profile] [-E endpoint] [-t token]
171
+ [-d description] [-s time] [-i | -e time] [-l level] [-T type]
165
172
  [-H host] [-n] <event>
166
- wavefront event close [-V] [-c file] [-P profile] [-E endpoint] [-t token]
173
+ wavefront event close [-DV] [-c file] [-P profile] [-E endpoint] [-t token]
167
174
  [<event>] [<timestamp>]
168
- wavefront event delete [-V] <timestamp> <event>
175
+ wavefront event delete [-DV] [-c file] [-P profile] [-E endpoint] [-t token]
176
+ <timestamp> <event>
169
177
  wavefront event show
170
178
  wavefront event --help
171
179
 
172
180
  Options:
173
- -E, --endpoint=URI cluster endpoint [default: metrics.wavefront.com]
181
+ -E, --endpoint=URI cluster endpoint [metrics.wavefront.com]
182
+ -t, --token=TOKEN Wavefront authentication token
174
183
  -i, --instant create an instantaneous event
175
- -V, --verbose be verbose
176
184
  -s, --start=TIME time at which event begins
177
185
  -e, --end=TIME time at which event ends
178
186
  -l, --level=LEVEL level of event (info, smoke, warn, severe)
179
187
  -T, --type=TYPE type of event
180
188
  -d, --desc=STRING description of event
181
- -H, --host=STRING list of hosts to tag with even (comma separated)
189
+ -H, --host=STRING list of hosts to tag with event (comma separated)
182
190
  -n, --nostate do not create a local file recording the event
191
+
192
+ View events in detail using the 'ts' command with the 'events()' function.
183
193
  ```
184
194
 
185
195
  To close an event in the Wavefront API it must be identified by its
@@ -266,19 +276,31 @@ Usage:
266
276
  [-p port] [-H host] [-n] [-T tag...] <metric> <value>
267
277
  wavefront write file [-DV] [-c file] [-P profile] [-E proxy] [-H host]
268
278
  [-p port] [-n] [-F format] [-m metric] [-T tag...] <file>
279
+ wavefront write --help
269
280
 
270
- Options:
271
- -E, --proxy=URI proxy endpoint [default: wavefront]
272
- -t, --time=TIME time of data point (omit to use current time)
273
- -H, --host=STRING source host [default: box]
274
- -p, --port=INT Wavefront proxy port [default: 2878]
275
- -T, --tag=TAG point tag in key=value form
276
- -F, --format=STRING format of input file or stdin [default: tmv]
277
- -n, --noop show the metric without sending it
278
- -m, --metric=STRING the metric path to which contents of a file will be
279
- assigned. If the file contains a metric name, the two
280
- will be concatenated
281
+ Global options:
282
+ -c, --config=FILE path to configuration file [/home/rob/.wavefront]
283
+ -P, --profile=NAME profile in configuration file [default]
284
+ -D, --debug enable debug mode
281
285
  -V, --verbose be verbose
286
+ -h, --help show this message
287
+
288
+ Options:
289
+ -E, --proxy=URI proxy endpoint [wavefront]
290
+ -t, --time=TIME time of data point (omit to use current time)
291
+ -H, --host=STRING source host [box]
292
+ -p, --port=INT Wavefront proxy port [2878]
293
+ -T, --tag=TAG point tag in key=value form
294
+ -F, --infileformat=STRING format of input file or stdin [tmv]
295
+ -n, --noop show the metric without sending it
296
+ -m, --metric=STRING the metric path to which contents of a
297
+ file will be assigned. If the file
298
+ contains a metric name, the two will be
299
+ concatenated
300
+
301
+ Files are whitespace separated, and fields can be defined with the -F
302
+ option. Use 't' for timestamp; 'm' for metric name; 'v' for value
303
+ and 'T' for tags. Put 'T' last.
282
304
  ```
283
305
 
284
306
  `write` has two sub-commands: `write point` and `write file`. Both
@@ -364,37 +386,34 @@ sources. Note that source tags are not the same as point tags.
364
386
 
365
387
  ```
366
388
  Usage:
367
- wavefront source list [-c file] [-P profile] [-E endpoint] [-t token]
368
- [-f format] [-T tag ...] [-at] [-s source] [-l limit] <pattern>
369
- wavefront source show [-c file] [-P profile] [-E endpoint] [-t token]
389
+ wavefront source list [-c file] [-P profile] [-E endpoint] [-t token] [-DV]
390
+ [-f format] [-T tag ...] [-ag] [-s source] [-l limit] <pattern>
391
+ wavefront source show [-c file] [-P profile] [-E endpoint] [-t token] [-DV]
370
392
  [-f format] <host> ...
371
393
  wavefront source describe [-c file] [-P profile] [-E endpoint] [-t token]
372
- [-H host ... ] <description>
394
+ [-DV] [-H host ... ] <description>
373
395
  wavefront source undescribe [-c file] [-P profile] [-E endpoint] [-t token]
374
- [<host>] ...
396
+ [-DV] [<host>] ...
375
397
  wavefront source tag add [-c file] [-P profile] [-E endpoint] [-t token]
376
- [-H host ... ] <tag> ...
398
+ [-DV] [-H host ... ] <tag> ...
377
399
  wavefront source tag delete [-c file] [-P profile] [-E endpoint] [-t token]
378
- [-H host ... ] <tag> ...
379
- wavefront source untag [-c file] [-P profile] [-E endpoint] [-t token]
400
+ [-DV] [-H host ... ] <tag> ...
401
+ wavefront source untag [-c file] [-P profile] [-E endpoint] [-t token] [-DV]
380
402
  [<host>] ...
381
403
  wavefront source --help
382
404
 
383
- Global options:
384
- -c, --config=FILE path to configuration file [default: /home/rob/.wavefront]
385
- -P, --profile=NAME profile in configuration file [default: default]
386
- -D, --debug enable debug mode
387
- -h, --help show this message
388
-
389
405
  Options:
390
- -a, --all including hidden sources in 'human' output
391
- -t, --tags show tag counts in 'human' output
392
- -T, --tagged=STRING only list sources with this tag in 'human' output
393
- -s, --start=STRING start the list after the named source
394
- -l, --limit=NUMBER only list NUMBER sources
395
- -H, --host=STRING source to manipulate
396
- -f, --format=STRING output format (ruby, json, human)
397
- [default: human]
406
+ -E, --endpoint=URI cluster endpoint [metrics.wavefront.com]
407
+ -t, --token=TOKEN Wavefront authentication token
408
+ -a, --all including hidden sources in 'human' output
409
+ -g, --tags show tag counts in 'human' output
410
+ -T, --tagged=STRING only list sources with this tag when using
411
+ 'human' output
412
+ -s, --start=STRING start the list after the named source
413
+ -l, --limit=NUMBER only list NUMBER sources
414
+ -H, --host=STRING source to manipulate
415
+ -f, --sourceformat=STRING output format (ruby, json, human)
416
+ [human]
398
417
  ```
399
418
 
400
419
  Tags and descriptions can be applied to multiple sources by repeated
@@ -480,7 +499,9 @@ string.
480
499
  Passing tokens and endpoints into the `wavefront` command can become
481
500
  tiresome, so you can put such data into an `ini`-style configuration
482
501
  file. By default this file should be located at `${HOME}/.wavefront`,
483
- though you can override the location with the `-c` flag.
502
+ though you can override the location with the `-c` flag. You can
503
+ also put a system-wide file at `/etc/wavefront/client.conf`, though
504
+ the user-specific file will take precedentce.
484
505
 
485
506
  You can switch between Wavefront accounts using profile stanzas,
486
507
  selected with the `-P` option. If `-P` is not supplied, the
@@ -493,16 +514,19 @@ A configuration file looks like this:
493
514
  [default]
494
515
  token = abcdefab-1234-abcd-1234-abcdefabcdef
495
516
  endpoint = companya.wavefront.com
496
- format = human
517
+ format = json
518
+ alertformat = human
497
519
 
498
520
  [companyb]
499
521
  token = 12345678-abcd-0123-abcd-123456789abc
500
522
  endpoint = metrics.wavefront.com
523
+ proxy = wavefront.local
524
+ sourceformat = json
501
525
  ```
502
526
 
503
527
  The key for each key-value pair can match any long option show in the
504
528
  command `help`, so you can set, for instance, a default output
505
- format, as shown above.
529
+ format for timeseries, alerts and source commands, as shown above.
506
530
 
507
531
  If an option is defined by a command-line switch, and in the
508
532
  configuration file, the config file will win.
@@ -15,17 +15,19 @@
15
15
  #
16
16
 
17
17
  require 'pathname'
18
+
19
+ # uncomment for development
20
+ $LOAD_PATH.<< Pathname.new(__FILE__).dirname.realpath.parent + 'lib'
21
+
18
22
  require 'wavefront/client'
19
23
  require 'wavefront/client/version'
20
24
  require 'wavefront/cli'
25
+ require 'wavefront/opt_handler'
21
26
  require 'docopt'
22
- require 'socket'
23
27
  include Wavefront::Constants
24
28
 
25
29
  def sanitize_keys(hash)
26
- hash.each_with_object({}) do |(k, v), aggr|
27
- aggr[k.delete('-').to_sym] = v
28
- end
30
+ hash.each_with_object({}) { |(k, v), aggr| aggr[k.delete('-').to_sym] = v }
29
31
  end
30
32
 
31
33
  ME = Pathname.new(__FILE__).basename
@@ -33,19 +35,20 @@ ME = Pathname.new(__FILE__).basename
33
35
  # If we are a normal user, look for wavefront config in our home
34
36
  # directory; if not, look in /etc
35
37
  #
36
- DEF_CF = if ENV['HOME']
37
- Pathname.new(ENV['HOME']) + '.wavefront'
38
- else
39
- Pathname.new('/etc/wavefront/client.conf')
40
- end
38
+ conf_file = if ENV['HOME']
39
+ Pathname.new(ENV['HOME']) + '.wavefront'
40
+ else
41
+ Pathname.new('/etc/wavefront/client.conf')
42
+ end
41
43
 
42
44
  # The global_opts are available in every command.
43
45
  #
44
46
  global_opts = %(
45
47
  Global options:
46
- -c, --config=FILE path to configuration file [default: #{DEF_CF}]
47
- -P, --profile=NAME profile in configuration file [default: default]
48
+ -c, --config=FILE path to configuration file [#{conf_file}]
49
+ -P, --profile=NAME profile in configuration file [#{DEFAULT_OPTS[:profile]}]
48
50
  -D, --debug enable debug mode
51
+ -n, --noop don't perform API calls
49
52
  -V, --verbose be verbose
50
53
  -h, --help show this message
51
54
  )
@@ -56,12 +59,12 @@ Global options:
56
59
  usage = {
57
60
  ts: %(
58
61
  Usage:
59
- #{ME} ts [-c file] [-P profile] [-E endpoint] [-t token] [-ODV]
62
+ #{ME} ts [-c file] [-P profile] [-E endpoint] [-t token] [-ODnV]
60
63
  [-S | -m | -H | -d] [-s time] [-e time] [-f format] [-p num]
61
64
  [-X bool] <query>
62
65
  #{global_opts}
63
66
  Options:
64
- -E, --endpoint=URI cluster endpoint [default: #{DEFAULT_HOST}]
67
+ -E, --endpoint=URI cluster endpoint [#{DEFAULT_OPTS[:endpoint]}]
65
68
  -t, --token=TOKEN Wavefront authentication token
66
69
  -S, --seconds query granularity of seconds
67
70
  -m, --minutes query granularity of minutes
@@ -72,73 +75,76 @@ Options:
72
75
  -e, --end=TIME end of query window in epoch seconds or
73
76
  strptime parseable format
74
77
  -f, --format=STRING output format (#{FORMATS.join(', ')})
75
- [default: #{DEFAULT_FORMAT}]
78
+ [#{DEFAULT_OPTS[:format]}]
76
79
  -p, --prefixlength=NUM number of path elements to treat as prefix
77
- in schema manipulation. [default: #{DEFAULT_PREFIX_LENGTH}]
80
+ in schema manipulation. [#{DEFAULT_OPTS[:prefixlength]}]
78
81
  -X, --strict=BOOL Do not return points outside the query
79
- window. [default: #{DEFAULT_STRICT}]
82
+ window. [#{DEFAULT_OPTS[:strict]}]
80
83
  -O, --includeObsoleteMetrics include metrics unreported for > 4 weeks
81
84
  ),
82
85
 
83
86
  alerts: %(
84
87
  Usage:
85
- #{ME} alerts [-c file] [-P profile] [-E endpoint] [-t token] [-V]
88
+ #{ME} alerts [-DnV] [-c file] [-P profile] [-E endpoint] [-t token]
86
89
  [-f format] [-p tag] [ -s tag] <state>
87
90
  #{global_opts}
88
91
  Options:
89
- -E, --endpoint=URI cluster endpoint [default: #{DEFAULT_HOST}]
90
- -t, --token=TOKEN Wavefront authentication token
91
- -f, --format=STRING output format (#{ALERT_FORMATS.join(', ')})
92
- [default: #{DEFAULT_ALERT_FORMAT}]
93
- -p, --private=TAG retrieve only alerts with named private tags,
94
- comma delimited.
95
- -s, --shared=TAG retrieve only alerts with named shared tags, comma
96
- delimited.
92
+ -E, --endpoint=URI cluster endpoint [#{DEFAULT_OPTS[:endpoint]}]
93
+ -t, --token=TOKEN Wavefront authentication token
94
+ -f, --alertformat=STRING output format (#{ALERT_FORMATS.join(', ')})
95
+ [#{DEFAULT_OPTS[:aformat]}]
96
+ -p, --private=TAG retrieve only alerts with named private tags,
97
+ comma delimited.
98
+ -s, --shared=TAG retrieve only alerts with named shared tags,
99
+ comma delimited.
97
100
  ),
98
101
 
99
102
  event: %(
100
103
  Usage:
101
- #{ME} event create [-V] [-c file] [-P profile] [-E endpoint] [-t token]
104
+ #{ME} event create [-DnV] [-c file] [-P profile] [-E endpoint] [-t token]
102
105
  [-d description] [-s time] [-i | -e time] [-l level] [-T type]
103
- [-H host] [-n] <event>
104
- #{ME} event close [-V] [-c file] [-P profile] [-E endpoint] [-t token]
106
+ [-H host] [-N] <event>
107
+ #{ME} event close [-DnV] [-c file] [-P profile] [-E endpoint] [-t token]
105
108
  [<event>] [<timestamp>]
106
- #{ME} event delete [-V] <timestamp> <event>
109
+ #{ME} event delete [-DnV] [-c file] [-P profile] [-E endpoint] [-t token]
110
+ <timestamp> <event>
107
111
  #{ME} event show
108
112
  #{ME} event --help
109
113
  #{global_opts}
110
114
  Options:
115
+ -E, --endpoint=URI cluster endpoint [#{DEFAULT_OPTS[:endpoint]}]
116
+ -t, --token=TOKEN Wavefront authentication token
111
117
  -i, --instant create an instantaneous event
112
118
  -s, --start=TIME time at which event begins
113
119
  -e, --end=TIME time at which event ends
114
120
  -l, --level=LEVEL level of event (#{EVENT_LEVELS.join(', ')})
115
121
  -T, --type=TYPE type of event
116
122
  -d, --desc=STRING description of event
117
- -H, --host=STRING list of hosts to tag with even (comma separated)
118
- -n, --nostate do not create a local file recording the event
123
+ -H, --host=STRING list of sources to which event applies (comma separated)
124
+ -N, --nostate do not create a local file recording the event
119
125
 
120
126
  View events in detail using the 'ts' command with the 'events()' function.
121
127
  ),
122
128
 
123
129
  write: %(
124
130
  Usage:
125
- #{ME} write point [-DV] [-c file] [-P profile] [-E proxy] [-t time]
131
+ #{ME} write point [-DnV] [-c file] [-P profile] [-E proxy] [-t time]
126
132
  [-p port] [-H host] [-n] [-T tag...] <metric> <value>
127
- #{ME} write file [-DV] [-c file] [-P profile] [-E proxy] [-H host]
133
+ #{ME} write file [-DnV] [-c file] [-P profile] [-E proxy] [-H host]
128
134
  [-p port] [-n] [-F format] [-m metric] [-T tag...] <file>
129
135
  #{ME} write --help
130
136
  #{global_opts}
131
137
  Options:
132
- -E, --proxy=URI proxy endpoint [default: #{DEFAULT_PROXY}]
133
- -t, --time=TIME time of data point (omit to use current time)
134
- -H, --host=STRING source host [default: #{Socket.gethostname}]
135
- -p, --port=INT Wavefront proxy port [default: #{DEFAULT_PROXY_PORT}]
136
- -T, --tag=TAG point tag in key=value form
137
- -F, --format=STRING format of input file or stdin [default: #{DEFAULT_INFILE_FORMAT}]
138
- -n, --noop show the metric without sending it
139
- -m, --metric=STRING the metric path to which contents of a file will be
140
- assigned. If the file contains a metric name, the two
141
- will be concatenated
138
+ -E, --proxy=URI proxy endpoint [#{DEFAULT_OPTS[:proxy]}]
139
+ -t, --time=TIME time of data point (omit to use current time)
140
+ -H, --host=STRING source host [#{DEFAULT_OPTS[:host]}]
141
+ -p, --port=INT Wavefront proxy port [#{DEFAULT_OPTS[:port]}]
142
+ -T, --tag=TAG point tag in key=value form
143
+ -F, --infileformat=STRING format of input file or stdin [#{DEFAULT_OPTS[:infileformat]}]
144
+ -m, --metric=STRING the metric path to which contents of a
145
+ file will be assigned. If the file
146
+ contains a metric name, the two will be
147
+ concatenated
142
148
 
143
149
  Files are whitespace separated, and fields can be defined with the -F
144
150
  option. Use 't' for timestamp; 'm' for metric name; 'v' for value
@@ -146,31 +152,33 @@ and 'T' for tags. Put 'T' last.
146
152
  ),
147
153
  source: %(
148
154
  Usage:
149
- #{ME} source list [-c file] [-P profile] [-E endpoint] [-t token] [-V]
150
- [-f format] [-T tag ...] [-at] [-s source] [-l limit] <pattern>
151
- #{ME} source show [-c file] [-P profile] [-E endpoint] [-t token] [-V]
155
+ #{ME} source list [-c file] [-P profile] [-E endpoint] [-t token] [-DnV]
156
+ [-f format] [-T tag ...] [-ag] [-s source] [-l limit] <pattern>
157
+ #{ME} source show [-c file] [-P profile] [-E endpoint] [-t token] [-DnV]
152
158
  [-f format] <host> ...
153
159
  #{ME} source describe [-c file] [-P profile] [-E endpoint] [-t token]
154
- [-V] [-H host ... ] <description>
160
+ [-DnV] [-H host ... ] <description>
155
161
  #{ME} source undescribe [-c file] [-P profile] [-E endpoint] [-t token]
156
- [-V] [<host>] ...
162
+ [-DnV] [<host>] ...
157
163
  #{ME} source tag add [-c file] [-P profile] [-E endpoint] [-t token]
158
- [-V] [-H host ... ] <tag> ...
164
+ [-DnV] [-H host ... ] <tag> ...
159
165
  #{ME} source tag delete [-c file] [-P profile] [-E endpoint] [-t token]
160
- [-V] [-H host ... ] <tag> ...
161
- #{ME} source untag [-c file] [-P profile] [-E endpoint] [-t token] [-V]
166
+ [-DnV] [-H host ... ] <tag> ...
167
+ #{ME} source untag [-c file] [-P profile] [-E endpoint] [-t token] [-DnV]
162
168
  [<host>] ...
163
169
  #{ME} source --help
164
170
  #{global_opts}
165
171
  Options:
166
- -a, --all including hidden sources in 'human' output
167
- -t, --tags show tag counts in 'human' output
168
- -T, --tagged=STRING only list sources with this tag in 'human' output
169
- -s, --start=STRING start the list after the named source
170
- -l, --limit=NUMBER only list NUMBER sources
171
- -H, --host=STRING source to manipulate
172
- -f, --format=STRING output format (#{ALERT_FORMATS.join(', ')})
173
- [default: #{DEFAULT_ALERT_FORMAT}]
172
+ -E, --endpoint=URI cluster endpoint [#{DEFAULT_OPTS[:endpoint]}]
173
+ -t, --token=TOKEN Wavefront authentication token
174
+ -a, --all including hidden sources in 'human' output
175
+ -g, --tags show tag counts in 'human' output
176
+ -T, --tagged=STRING only list sources with this tag when using
177
+ 'human' output
178
+ -s, --start=STRING start the list after the named source
179
+ -l, --limit=NUMBER only list NUMBER sources
180
+ -H, --host=STRING source to manipulate
181
+ -f, --sourceformat=STRING output format (#{SOURCE_FORMATS.join(', ')}) [#{DEFAULT_OPTS[:sourceformat]}]
174
182
  ),
175
183
  default: %(
176
184
  Wavefront CLI
@@ -190,29 +198,33 @@ Commands:
190
198
  Use '#{ME} <command> --help' for further information.)
191
199
  }
192
200
 
193
- # Parse the input. We have to do this twice because of the nested
194
- # help/option parser generation.
201
+ # Parse the input. The first Docopt.docopt handles the default
202
+ # options, the second works on the command.
195
203
  #
196
204
  begin
197
205
  opts = Docopt.docopt(usage[:default], version: Wavefront::Client::VERSION)
198
206
  rescue Docopt::Exit => e
199
- cmd = ARGV.length > 0 ? ARGV.first.to_sym : nil
207
+
208
+ cmd = ARGV.empty? ? nil : ARGV.first.to_sym
200
209
 
201
210
  if usage.keys.include?(cmd)
202
211
  begin
203
212
  opts = sanitize_keys(Docopt.docopt(usage[cmd]))
204
213
  rescue Docopt::Exit => e
205
- abort e.message
214
+ abort e.message # command help
206
215
  end
207
216
  else
208
- abort e.message
217
+ abort e.message # default help
209
218
  end
210
219
  end
211
220
 
212
- # Load the config file. Values in there take priority, otherwise
213
- # default (unset) options will win.
214
- #
215
- opts.merge!(Wavefront::Cli.new(opts, nil).load_profile || {})
221
+ opts = Wavefront::OptHandler.new(conf_file, opts).opts
222
+
223
+ if opts[:debug]
224
+ require 'pp'
225
+ puts 'Combined options:'
226
+ pp opts
227
+ end
216
228
 
217
229
  case cmd
218
230
  when :ts
@@ -238,7 +250,10 @@ when :write
238
250
  end
239
251
 
240
252
  begin
253
+ cli.validate_opts
241
254
  cli.run
242
255
  rescue => e
243
- abort "#{cmd} query failed. #{e}"
256
+ STDERR.puts "#{cmd} query failed. #{e}"
257
+ STDERR.puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" if opts[:debug]
258
+ exit 1
244
259
  end