wavefront-cli 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/Gemfile +1 -1
  4. data/README.md +21 -21
  5. data/Rakefile +2 -2
  6. data/bin/{wavefront → wf} +6 -2
  7. data/lib/wavefront-cli/alert.rb +7 -6
  8. data/lib/wavefront-cli/base.rb +27 -6
  9. data/lib/wavefront-cli/commands/alert.rb +2 -1
  10. data/lib/wavefront-cli/commands/base.rb +54 -29
  11. data/lib/wavefront-cli/commands/dashboard.rb +1 -0
  12. data/lib/wavefront-cli/commands/event.rb +7 -3
  13. data/lib/wavefront-cli/commands/integration.rb +2 -1
  14. data/lib/wavefront-cli/commands/link.rb +2 -2
  15. data/lib/wavefront-cli/commands/proxy.rb +2 -1
  16. data/lib/wavefront-cli/commands/savedsearch.rb +2 -1
  17. data/lib/wavefront-cli/commands/source.rb +3 -2
  18. data/lib/wavefront-cli/commands/webhook.rb +2 -1
  19. data/lib/wavefront-cli/commands/window.rb +2 -1
  20. data/lib/wavefront-cli/commands/write.rb +10 -6
  21. data/lib/wavefront-cli/constants.rb +1 -1
  22. data/lib/wavefront-cli/controller.rb +6 -4
  23. data/lib/wavefront-cli/dashboard.rb +6 -6
  24. data/lib/wavefront-cli/display/alert.rb +8 -4
  25. data/lib/wavefront-cli/display/base.rb +115 -170
  26. data/lib/wavefront-cli/display/cloudintegration.rb +2 -2
  27. data/lib/wavefront-cli/display/event.rb +1 -1
  28. data/lib/wavefront-cli/display/maintenancewindow.rb +1 -1
  29. data/lib/wavefront-cli/display/metric.rb +6 -7
  30. data/lib/wavefront-cli/display/printer/base.rb +24 -0
  31. data/lib/wavefront-cli/display/printer/long.rb +186 -0
  32. data/lib/wavefront-cli/display/printer/terse.rb +55 -0
  33. data/lib/wavefront-cli/display/query.rb +1 -2
  34. data/lib/wavefront-cli/display/savedsearch.rb +1 -1
  35. data/lib/wavefront-cli/display/source.rb +7 -3
  36. data/lib/wavefront-cli/display/webhook.rb +3 -4
  37. data/lib/wavefront-cli/event.rb +62 -23
  38. data/lib/wavefront-cli/exception.rb +1 -1
  39. data/lib/wavefront-cli/opt_handler.rb +6 -6
  40. data/lib/wavefront-cli/query.rb +5 -6
  41. data/lib/wavefront-cli/source.rb +5 -1
  42. data/lib/wavefront-cli/string.rb +59 -0
  43. data/lib/wavefront-cli/version.rb +1 -1
  44. data/lib/wavefront-cli/write.rb +4 -1
  45. data/spec/spec_helper.rb +1 -1
  46. data/spec/wavefront-cli/alert_spec.rb +16 -5
  47. data/spec/wavefront-cli/base_spec.rb +5 -2
  48. data/spec/wavefront-cli/cli_help_spec.rb +7 -5
  49. data/spec/wavefront-cli/cloudintegration_spec.rb +9 -0
  50. data/spec/wavefront-cli/commands/alert_spec.rb +16 -0
  51. data/spec/wavefront-cli/commands/base_spec.rb +133 -0
  52. data/spec/wavefront-cli/commands/dashboard_spec.rb +16 -0
  53. data/spec/wavefront-cli/commands/event_spec.rb +17 -0
  54. data/spec/wavefront-cli/commands/integration_spec.rb +21 -0
  55. data/spec/wavefront-cli/commands/link_spec.rb +21 -0
  56. data/spec/wavefront-cli/commands/message_spec.rb +16 -0
  57. data/spec/wavefront-cli/commands/metric_spec.rb +16 -0
  58. data/spec/wavefront-cli/commands/proxy_spec.rb +16 -0
  59. data/spec/wavefront-cli/commands/query_spec.rb +16 -0
  60. data/spec/wavefront-cli/commands/spec_helper.rb +4 -0
  61. data/spec/wavefront-cli/commands/webhook_spec.rb +16 -0
  62. data/spec/wavefront-cli/commands/window_spec.rb +21 -0
  63. data/spec/wavefront-cli/commands/write_spec.rb +17 -0
  64. data/spec/wavefront-cli/dashboard_spec.rb +14 -4
  65. data/spec/wavefront-cli/display/base_spec.rb +162 -0
  66. data/spec/wavefront-cli/display/printer/base_spec.rb +20 -0
  67. data/spec/wavefront-cli/display/printer/long_spec.rb +137 -0
  68. data/spec/wavefront-cli/display/printer/terse_spec.rb +46 -0
  69. data/spec/wavefront-cli/display/spec_helper.rb +5 -0
  70. data/spec/wavefront-cli/event_spec.rb +9 -0
  71. data/spec/wavefront-cli/externallink_spec.rb +9 -0
  72. data/spec/wavefront-cli/maintanancewindow_spec.rb +10 -0
  73. data/spec/wavefront-cli/proxy_spec.rb +9 -0
  74. data/spec/wavefront-cli/savedsearch_spec.rb +9 -0
  75. data/spec/wavefront-cli/source_spec.rb +13 -1
  76. data/spec/wavefront-cli/string_spec.rb +51 -0
  77. data/spec/wavefront-cli/user_spec.rb +2 -2
  78. data/spec/wavefront-cli/webhook_spec.rb +9 -0
  79. data/wavefront-cli.gemspec +5 -5
  80. metadata +59 -22
  81. data/Gemfile.lock +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88361573bacb11ad77961b36c20cbd1fee3a0275
4
- data.tar.gz: 759b6a5b0c5f3287d7658d676fc27ba68d2bcdc6
3
+ metadata.gz: abded61ee10732bf7af826637d39e1a736db92bc
4
+ data.tar.gz: bf039ef6b77cde28bcd7f6c3c1d2e8f141e86f9c
5
5
  SHA512:
6
- metadata.gz: 266b8c096a7b57896158b1f54bee0615108024984279a9ebfba714725ddb48eac9648ba8da2e96fbcfc2769614166b6e4c074dd163d55d5df0c0e767bc731a19
7
- data.tar.gz: 77f79a1bf985a89dd1f4fa71151efa85ba53289e640456a4997d2c7f6285d12b3c6fb2259aadae20ac4efc8ff0e3bcf58faaf95ff45061bb98f800799eeb2e63
6
+ metadata.gz: e99d3375a2f2693e3b18974a8cd6099d642d3e78bbe88a752fef943d21fbc93432028ff59e5d345074aa1c93990de9b1bfd1a6da9e3f3f8e49eed647ab32554a
7
+ data.tar.gz: b5a9e93eef9dda6708651c49736aa7d69008553c633494d955153fc1440afb80cfdc0a296ecdfc30b18cb5b2c3d87254463ba8cffae44277d32b23aa7f7b738a
data/.travis.yml CHANGED
@@ -8,9 +8,10 @@ before_install: gem install bundler --no-rdoc --no-ri
8
8
  deploy:
9
9
  provider: rubygems
10
10
  api_key:
11
- secure: dfmL5JwBn+u3cUmyAaDsApDa7ljGajGNz3GDcKd2J8FOt7+a758/lmL8EQ34sDT1ZFotrxn/y1RbgXlaDxAE1XDfrZbjckmx7a6wa2sqR3kBraJ2tx7CiXodbw3Z8XZf9WLb0kYGmlLtI73GNcuunMt/9f1cobqWISRLHw6b7amlO7GW2ZBZgzRS+N8TSS2dicIvKMo5HoMYU+uWLM4zDFBPnGNcMiWxh8ysLzJoKqA9kbBUyCVEZ03MlV7G71ObvWCLasKnZ3W5U+K1NbgU7mgMYfl9KIcA4y9hQ9hUCijk40SmT7ffy3P2gq8zblC/4x5Eefpau9X/bdLwXoRCIzqk05t4f45wstj2auHGK0HJwOYRtx8apdaLSgyJ5lQpGcbCRu40WR9mDkaM8m9n3u2o6GJmftCg3AN1QtsourmQB84x67LEbHzValMaokrbCol4XeWqlC+dCNLPixemQRBvcNfI3V9C6RqVGfjpoGlSTI+RkQqwm01PcxpeqIVfdMd1wnfUuAOywUO6UpvtK9TZaxg0NnVElXpPseQbtzulLwZ7R5Y3A4Ss8Z7w43c1KHxTkg54FWUOp065ItjAc4lmyORXq/2+F7sMvRN6dtCLaXTUlkYuU3cjFLIPlLGFYgqq4T4xQa+e5NEK1XW7nghv+IRfKfyVeZsB0WpY+uc=
11
+ secure: dpVC480pAmGQrkEeugPowxhYzM8Er9UDhY02u2P5ytrCXC9J05uGKvN8uZ6H8SJr1ZKUb7OGxCq+EVKrA/q1s6Cv07Xl9u1HiOR0cB4ZUW3wBl6TGdl7c/rcor5AQxjELTcWnhCJvTzB+i46a1s4AcWjGBIVEY7/b1iloj/Sm0U43UZPcWPaIl5xfnANBk6v9F5eEfQy5IXlQUQKtRLXzgyqwyJi7DQcNcnEXA0O33KKwka7QDQsycYE7axEiJGOBt0PbYiRUXRZBxKWnsrtq9Sk9QukYsZSQqZgkykV6ImvMYzWI/vUwDRl+dJWmyAG6K2mz4kqMjhiMkB4ctbj5sxDG1BzsBlNTTEb0P8PGBEYgcf4VBd7XDlEt0Sythp6ztn9EVtw35M22n5Q7sdgalf6TFrzQpp9sec3o4AqO3IXUIqRN4VD4vPRQVBJHcwFOuZ3EUO0VekUzCUO3R/mG4oHUIQ9VgRzrUuyYpCwuwWyoVKVA/AukHHW6Y7El2g+JlpP+ijf0ABpqusHENELVWnuCRcv36sxbyM6Rbt2JrT9FrG1oSAELz4yMS86Qhq104II89d6apGJT3thUH8n9m2KA16DmxQYXkNamfygCn3D5ogC2gcIgVicQnJma+405Pv43/a+PaKy/oKr3/H7IJJmoqHfiMyG9DtkFTWQrfA=
12
12
  gem: wavefront-cli
13
13
  on:
14
14
  tags: true
15
15
  repo: snltd/wavefront-cli
16
16
  ruby: 2.3.4
17
+
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
  gemspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Wavefront CLI
2
- [![Build Status](https://travis-ci.org/snltd/wavefront-cli.svg?branch=master)](https://travis-ci.org/snltd/wavefront-cli) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-cli/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-cli) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-cli/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-cli) [![Known Vulnerabilities](https://snyk.io/test/github/snltd/wavefront-cli/badge.svg)](https://snyk.io/test/github/snltd/wavefront-cli) [![Gem Version](https://badge.fury.io/rb/wavefront-cli.svg)](https://badge.fury.io/rb/wavefront-cli) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-cli?type=total)
2
+ [![Build Status](https://travis-ci.org/snltd/wavefront-cli.svg?branch=master)](https://travis-ci.org/snltd/wavefront-cli) [![Code Climate](https://codeclimate.com/github/snltd/wavefront-cli/badges/gpa.svg)](https://codeclimate.com/github/snltd/wavefront-cli) [![Issue Count](https://codeclimate.com/github/snltd/wavefront-cli/badges/issue_count.svg)](https://codeclimate.com/github/snltd/wavefront-cli) [![Dependency Status](https://gemnasium.com/badges/github.com/snltd/wavefront-cli.svg)](https://gemnasium.com/github.com/snltd/wavefront-cli) [![Gem Version](https://badge.fury.io/rb/wavefront-cli.svg)](https://badge.fury.io/rb/wavefront-cli) ![](http://ruby-gem-downloads-badge.herokuapp.com/wavefront-cli?type=total)
3
3
 
4
4
 
5
5
  This package provides a command-line interface to Wavefront's API. Each API path
@@ -9,13 +9,13 @@ It is built on [the Wavefront Ruby
9
9
  SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >= 2.2.
10
10
 
11
11
  ```
12
- $ wavefront --help
12
+ $ wf --help
13
13
  Wavefront CLI
14
14
 
15
15
  Usage:
16
- wavefront [options] command [options]
17
- wavefront --version
18
- wavefront --help
16
+ wf [options] command [options]
17
+ wf --version
18
+ wf --help
19
19
 
20
20
  Commands:
21
21
  alert view and manage alerts
@@ -34,7 +34,7 @@ Commands:
34
34
  webhook view and manage webhooks
35
35
  write send data points to a Wavefront proxy
36
36
 
37
- Use 'wavefront <command> --help' for further information.
37
+ Use 'wf <command> --help' for further information.
38
38
  ```
39
39
 
40
40
  ## General Rules
@@ -71,7 +71,7 @@ Most commands have a `list` subcommand, which will produce brief
71
71
  column.
72
72
 
73
73
  ```
74
- $ wavefront proxy list
74
+ $ wf proxy list
75
75
  457d6cf3-5171-45e0-8d31-5c980be889ea test agent
76
76
  917102d1-a10e-997b-ba63-95058f98d4fb Agent on wavefront-2017-03-13-02
77
77
  926dfb4c-23c6-4fb9-8c8d-833625ab8f6f Agent on shark-wavefront
@@ -85,7 +85,7 @@ Most commands have a `describe` subcommand which will tell you more about the
85
85
  object.
86
86
 
87
87
  ```
88
- $ wavefront proxy describe 917102d1-a10e-497b-ba63-95058f98d4fb
88
+ $ wf proxy describe 917102d1-a10e-497b-ba63-95058f98d4fb
89
89
  name Agent on wavefront-2017-03-13-02
90
90
  id 917102d1-a10e-497b-ba63-95058f98d4fb
91
91
  version 4.7
@@ -121,22 +121,22 @@ If you `describe` an object like a dashboard, user, webhook etc as `json` or
121
121
  `yaml`, and send the output to a file, you can re-import that data. The format of the file to be imported is automatically detected.
122
122
 
123
123
  ```
124
- $ wavefront user list
124
+ $ wf user list
125
125
  slackboy@gmail.com
126
126
  sysdef.limited@gmail.com
127
- $ wavefront user describe -f json sysdef.limited@gmail.com > user.json
127
+ $ wf user describe -f json sysdef.limited@gmail.com > user.json
128
128
  $ cat user.json
129
129
  {"identifier":"sysdef.limited@gmail.com","customer":"sysdef","groups":["agent_management"]}
130
- $ wavefront user delete sysdef.limited@gmail.com
130
+ $ wf user delete sysdef.limited@gmail.com
131
131
  Deleted user 'sysdef.limited@gmail.com'.
132
- $ wavefront user list
132
+ $ wf user list
133
133
  slackboy@gmail.com
134
- $ wavefront user import user.json
134
+ $ wf user import user.json
135
135
  Imported user.
136
136
  identifier sysdef.limited@gmail.com
137
137
  customer sysdef
138
138
  groups agent_management
139
- $ wavefront user list
139
+ $ wf user list
140
140
  slackboy@gmail.com
141
141
  sysdef.limited@gmail.com
142
142
  ```
@@ -154,7 +154,7 @@ method](https://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html#method-
154
154
  method can parse unaided. For instance:
155
155
 
156
156
  ```
157
- $ wavefront --start 12:15 --end 12:20 ...
157
+ $ wf command --start 12:15 --end 12:20 ...
158
158
  ```
159
159
 
160
160
  will define a window between 12:15 and 12:20pm today. If you ran
@@ -162,7 +162,7 @@ that in the morning, the time would be invalid, and you would get a
162
162
  400 error from Wavefront, so something of the form
163
163
  `2016-04-17T12:25:00` would remove all ambiguity.
164
164
 
165
- There is no need to include a timezone in your time: the `wavefront`
165
+ There is no need to include a timezone in your time: the `wf`
166
166
  CLI will automatically use your local timezone when it parses the
167
167
  string.
168
168
 
@@ -185,20 +185,20 @@ fail. This output can be very verbose.
185
185
  Writing a single point is simple:
186
186
 
187
187
  ```
188
- $ wavefront write point cli.example 10
188
+ $ wf write point cli.example 10
189
189
  ```
190
190
 
191
191
  and you can add point tags, if you like.
192
192
 
193
193
  ```
194
- $ wavefront write point cli.example 9.4 -E wavefront -T proxy=wavefront \
194
+ $ wf write point cli.example 9.4 -E wavefront -T proxy=wavefront \
195
195
  -T from=README
196
196
  ```
197
197
 
198
198
  or force a timestamp:
199
199
 
200
200
  ```
201
- $ wavefront write point -t 16:53:14 cli.example 8
201
+ $ wf write point -t 16:53:14 cli.example 8
202
202
  ```
203
203
 
204
204
  More usefully, you can write from a file. Your file must contain multiple
@@ -212,11 +212,11 @@ $ cat datafile
212
212
  1496767813 dev.cli.test 12.1
213
213
  1496767813 dev.cli.test 10.0
214
214
  1496767813 dev.cli.test 14.5
215
- $ wavefront write file -F tmv datafile
215
+ $ wf write file -F tmv datafile
216
216
  ```
217
217
 
218
218
  If you set the file to `-`, you can read from standard in:
219
219
 
220
220
  ```
221
- $ while true; do echo $RANDOM; sleep 1; done | wavefront write file -m cli.demo -Fv -
221
+ $ while true; do echo $RANDOM; sleep 1; done | wf write file -m cli.demo -Fv -
222
222
  ```
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rubocop/rake_task'
5
5
  task default: :test
6
6
 
7
7
  Rake::TestTask.new do |t|
8
- t.pattern = 'spec/wavefront-cli/*_spec.rb'
8
+ t.pattern = 'spec/wavefront-cli/**/*_spec.rb'
9
9
  t.warning = false
10
10
  end
11
11
 
@@ -14,5 +14,5 @@ RuboCop::RakeTask.new(:rubocop) do |t|
14
14
  end
15
15
 
16
16
  YARD::Rake::YardocTask.new do |t|
17
- t.files = ['lib/wavefront-cli/*rb']
17
+ t.files = ['lib/wavefront-cli/**/*.rb']
18
18
  end
@@ -5,10 +5,14 @@ require 'io/console'
5
5
  require_relative '../lib/wavefront-cli/controller'
6
6
 
7
7
  begin
8
- TW = IO.console.winsize.last
8
+ tw = IO.console.winsize.last
9
9
  rescue
10
- TW = 80
10
+ tw = 80
11
11
  end
12
12
 
13
+ tw = 80 if tw < 60
14
+
15
+ TW = tw
16
+
13
17
  CMD = Pathname.new(__FILE__).basename
14
18
  WavefrontCliController.new(ARGV)
@@ -18,13 +18,13 @@ module WavefrontCli
18
18
  end
19
19
 
20
20
  def do_delete
21
- print (if wf.describe(options[:'<id>']).status.code == 200
22
- 'Soft'
23
- else
24
- 'Permanently'
25
- end)
21
+ word = if wf.describe(options[:'<id>']).status.code == 200
22
+ 'Soft'
23
+ else
24
+ 'Permanently'
25
+ end
26
26
 
27
- puts " deleting alert '#{options[:'<id>']}'."
27
+ puts "#{word} deleting alert '#{options[:'<id>']}'."
28
28
  wf.delete(options[:'<id>'])
29
29
  end
30
30
 
@@ -41,6 +41,7 @@ module WavefrontCli
41
41
  #
42
42
  # @param raw [Hash] Ruby hash of imported data
43
43
  #
44
+ # rubocop:disable Metrics/MethodLength
44
45
  def import_to_create(raw)
45
46
  ret = %w(name condition minutes target severity displayExpression
46
47
  additionalInformation).each_with_object({}) do |k, aggr|
@@ -1,8 +1,6 @@
1
-
2
1
  require 'yaml'
3
2
  require 'json'
4
3
  require 'wavefront-sdk/validators'
5
- # require_relative './constants'
6
4
  require_relative './exception'
7
5
 
8
6
  module WavefrontCli
@@ -89,7 +87,10 @@ module WavefrontCli
89
87
  # @return [Hash] containing `token` and `endpoint`.
90
88
  #
91
89
  def mk_creds
92
- { token: options[:token], endpoint: options[:endpoint] }
90
+ { token: options[:token],
91
+ endpoint: options[:endpoint],
92
+ agent: "wavefront-cli-#{WF_CLI_VERSION}"
93
+ }
93
94
  end
94
95
 
95
96
  # Make a common wavefront-sdk options object from standard CLI
@@ -98,12 +99,14 @@ module WavefrontCli
98
99
  # @return [Hash] containing `debug`, `verbose`, and `noop`.
99
100
  #
100
101
  def mk_opts
101
- { debug: options[:debug], verbose: options[:verbose],
102
- noop: options[:noop] }
102
+ { debug: options[:debug],
103
+ verbose: options[:verbose],
104
+ noop: options[:noop],
105
+ }
103
106
  end
104
107
 
105
108
  # To allow a user to default to different output formats for
106
- # different object, we define a format for each class. For
109
+ # different object, we are able to define a format for each class.
107
110
  # instance, `alertformat` or `agentformat`. This method returns
108
111
  # such a string appropriate for the inheriting class.
109
112
  #
@@ -166,6 +169,8 @@ module WavefrontCli
166
169
  # this output. Used to find a suitable humanize method.
167
170
  #
168
171
  def display(data, method)
172
+ exit if options[:noop]
173
+
169
174
  [:status, :response].each do |b|
170
175
  abort "no #{b} block in API response" unless data.respond_to?(b)
171
176
  end
@@ -290,6 +295,22 @@ module WavefrontCli
290
295
  wf.update(options[:'<id>'], k => v)
291
296
  end
292
297
 
298
+ def do_search
299
+ require 'wavefront-sdk/search'
300
+ wfs = Wavefront::Search.new(mk_creds, mk_opts)
301
+
302
+ query = options[:'<condition>'].each_with_object([]) do |c, aggr|
303
+ key, value = c.split(/\W/, 2)
304
+ q = { key: key, value: value }
305
+ q[:matchingMethod] = 'EXACT' if c.start_with?("#{key}=")
306
+ q[:matchingMethod] = 'STARTSWITH' if c.start_with?("#{key}^")
307
+ aggr.<< q
308
+ end
309
+
310
+ wfs.search(klass_word, query, { limit: options[:limit],
311
+ offset: options[:offset] || options[:cursor]})
312
+ end
313
+
293
314
  def do_tags
294
315
  wf.tags(options[:'<id>'])
295
316
  end
@@ -17,6 +17,7 @@ class WavefrontCommandAlert < WavefrontCommandBase
17
17
  "snooze #{CMN} [-T time] <id>",
18
18
  "update #{CMN} <key=value> <id>",
19
19
  "unsnooze #{CMN} <id>",
20
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>...",
20
21
  "tags #{CMN} [-f format] <id>",
21
22
  "tag set #{CMN} <id> <tag>...",
22
23
  "tag clear #{CMN} <id>",
@@ -28,11 +29,11 @@ class WavefrontCommandAlert < WavefrontCommandBase
28
29
  def _options
29
30
  [common_options,
30
31
  '-l, --long list alerts in detail',
32
+ '-a, --all list all alerts',
31
33
  '-v, --version=INTEGER describe only this version of alert',
32
34
  '-o, --offset=n start from nth alert',
33
35
  '-L, --limit=COUNT number of alerts to list',
34
36
  '-T, --time=SECONDS how long to snooze (default 3600)',
35
- '-a, --all list all alerts',
36
37
  '-f, --format=STRING output format']
37
38
  end
38
39
  end
@@ -1,9 +1,12 @@
1
+ require_relative '../string'
2
+
1
3
  CMN = '[-DnV] [-c file] [-P profile] [-E endpoint] [-t token]'.freeze
2
4
 
3
5
  # A base class which all command classes extend.
4
6
  #
5
7
  class WavefrontCommandBase
6
8
  # All commands have these options
9
+ # @return [Array]
7
10
  #
8
11
  def global_options
9
12
  ['-c, --config=FILE path to configuration file',
@@ -15,13 +18,22 @@ class WavefrontCommandBase
15
18
  end
16
19
 
17
20
  # Many commands have these options
21
+ # @return [Array]
18
22
  #
19
23
  def common_options
20
24
  ['-E, --endpoint=URI cluster endpoint',
21
25
  '-t, --token=TOKEN Wavefront authentication token']
22
26
  end
23
27
 
28
+ # Inheriting classes must override this method
29
+ # @return [Array]
30
+ #
31
+ def _options
32
+ []
33
+ end
34
+
24
35
  # Anything which takes tags provides the same interface
36
+ # @return [Array]
25
37
  #
26
38
  def tag_commands
27
39
  ["tags #{CMN} [-f format] <id>",
@@ -31,75 +43,88 @@ class WavefrontCommandBase
31
43
  "tag delete #{CMN} <id> <tag>"]
32
44
  end
33
45
 
34
- # The command keyword
46
+ # Inheriting classes must override this method
47
+ # @return [Array]
48
+ #
49
+ def _commands
50
+ []
51
+ end
52
+
53
+ # @return [String] the command keyword
35
54
  #
36
55
  def word
37
56
  self.class.name.sub(/WavefrontCommand/, '').downcase
38
57
  end
39
58
 
40
- # Returns the name of the SDK class which does the work for this
41
- # command.
59
+ # @return [String] the name of the SDK class which does the work
60
+ # for this command.
42
61
  #
43
62
  def sdk_class
44
63
  word.capitalize
45
64
  end
46
65
 
66
+ # @return [String] the name of the SDK file which does the work
67
+ # for this command.
68
+ #
47
69
  def sdk_file
48
70
  word
49
71
  end
50
72
 
51
- # Returns a string describing the subcommands the command offers.
73
+ # @param term_width [Integer] force a terminal width. Makes
74
+ # testing far simpler.
75
+ # @return [String] the subcommands the command offers.
52
76
  #
53
- def commands
77
+ #
78
+ def commands(term_width = TW)
54
79
  _commands.flatten.each_with_object("Usage:\n") do |cmd, ret|
55
- ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold + "\n"
80
+ ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold(term_width) + "\n"
56
81
  end + " #{CMD} #{word} --help"
57
82
  end
58
83
 
59
- # Returns a string describing the options the command understands.
84
+ # @param term_width [Integer] force a terminal width. Makes
85
+ # testing far simpler.
86
+ # @return [String] the options the command understands.
87
+ #
60
88
  #
61
- def options
62
- width = column_widths
89
+ def options(term_width = TW)
90
+ width = option_column_width
63
91
  ret = "Global options:\n"
64
- global_options.each { |o| ret.<< opt_row(o, width) }
92
+ global_options.each { |o| ret.<< opt_row(o, width, term_width) }
65
93
  ret.<< "\nOptions:\n"
66
- _options.flatten.each { |o| ret.<< opt_row(o, width) }
94
+ _options.flatten.each { |o| ret.<< opt_row(o, width, term_width) }
67
95
  ret
68
96
  end
69
97
 
70
- def opt_row(opt, width)
98
+ # Formats an option string.
99
+ #
100
+ # @param opt [String] the option string
101
+ # @param width [Integer] the width of the short + long options
102
+ # columns. This is used to indent following lines
103
+ # @param term_width [Integer] the width of the user's terminal
104
+ #
105
+ def opt_row(opt, width, term_width = TW)
71
106
  format(" %s %-#{width}s %s\n", *opt.split(/\s+/, 3))
107
+ .opt_fold(term_width, width + 5)
72
108
  end
73
109
 
74
- def column_widths
110
+ # @return [Integer] the width of the column containing short and
111
+ # long options
112
+ #
113
+ def option_column_width
75
114
  (global_options + _options).flatten.map do |o|
76
115
  o.split(/\s+/, 3)[0..1].join(' ').size
77
116
  end.max
78
117
  end
79
118
 
80
- # Returns a string which will be printed underneath the options.
119
+ # @return [String] which will be printed underneath the options.
81
120
  #
82
121
  def postscript
83
122
  ''
84
123
  end
85
124
 
86
- # Returns a full options string which docopt understands
125
+ # @return [String] a full options string which docopt understands
87
126
  #
88
127
  def docopt
89
128
  commands + "\n\n" + options + "\n" + postscript
90
129
  end
91
130
  end
92
-
93
- # Extensions to the String class to help with formatting.
94
- #
95
- class String
96
-
97
- # Fold long command lines. We can't break on a space inside
98
- # [square brackets] or it confuses docopt.
99
- #
100
- def cmd_fold(width = TW, indent = 10)
101
- gsub(/\s(?=\w+\])/, '^').
102
- scan(/\S.{0,#{width - 8}}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent).
103
- gsub('^', ' ')
104
- end
105
- end
@@ -15,6 +15,7 @@ class WavefrontCommandDashboard < WavefrontCommandBase
15
15
  "delete #{CMN} <id>",
16
16
  "undelete #{CMN} <id>",
17
17
  "history #{CMN} [-b] [-f format] [-o offset] [-L limit] <id>",
18
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>...",
18
19
  tag_commands]
19
20
  end
20
21
 
@@ -9,13 +9,16 @@ class WavefrontCommandEvent < WavefrontCommandBase
9
9
 
10
10
  def _commands
11
11
  ["list #{CMN} [-l] [-f format] [-s start] [-e end] [-L limit] " \
12
- '[-o offset]',
12
+ '[-o cursor]',
13
13
  "describe #{CMN} [-f format] <id>",
14
14
  "create #{CMN} [-d description] [-s time] [-i | -e time] " \
15
15
  '[-S severity] [-T type] [-H host...] [-N] <event>',
16
16
  "close #{CMN} [<id>]",
17
17
  "delete #{CMN} <id>",
18
18
  "update #{CMN} <key=value> <id>",
19
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>...",
20
+ "wrap #{CMN} [-C command] [-d description] [-S severity] [-T type] " \
21
+ '[-H host...] <event>',
19
22
  tag_commands,
20
23
  'show [-D]']
21
24
  end
@@ -23,7 +26,7 @@ class WavefrontCommandEvent < WavefrontCommandBase
23
26
  def _options
24
27
  [common_options,
25
28
  '-l, --long list events in detail',
26
- '-o, --offset=n start list from nth event',
29
+ '-o, --cursor=EVENT start listing from given event',
27
30
  '-L, --limit=COUNT number of events to list',
28
31
  '-s, --start=TIME time at which event/window begins',
29
32
  '-e, --end=TIME time at which even/window ends',
@@ -34,7 +37,8 @@ class WavefrontCommandEvent < WavefrontCommandBase
34
37
  '-H, --host=STRING source to which event applies',
35
38
  '-N, --nostate do not create a local file recording ' \
36
39
  'the event',
37
- '-f, --format=STRING output format']
40
+ '-C, --command=COMMAND command to run',
41
+ '-f, --format=STRING output format']
38
42
  end
39
43
 
40
44
  def postscript
@@ -20,7 +20,8 @@ class WavefrontCommandIntegration < WavefrontCommandBase
20
20
  "describe #{CMN} [-f format] <id>",
21
21
  "delete #{CMN} <id>",
22
22
  "undelete #{CMN} <id>",
23
- "import #{CMN} <file>"]
23
+ "import #{CMN} <file>",
24
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
24
25
  end
25
26
 
26
27
  def _options
@@ -20,8 +20,8 @@ class WavefrontCommandLink < WavefrontCommandBase
20
20
  "describe #{CMN} [-f format] <id>",
21
21
  "delete #{CMN} <id>",
22
22
  "import #{CMN} <file>",
23
- "update #{CMN} <key=value> <id>"
24
- ]
23
+ "update #{CMN} <key=value> <id>",
24
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
25
25
  end
26
26
 
27
27
  def _options
@@ -12,7 +12,8 @@ class WavefrontCommandProxy < WavefrontCommandBase
12
12
  "describe #{CMN} [-f format] <id>",
13
13
  "delete #{CMN} <id>",
14
14
  "undelete #{CMN} <id>",
15
- "rename #{CMN} <id> <name>"]
15
+ "rename #{CMN} <id> <name>",
16
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
16
17
  end
17
18
 
18
19
  def _options
@@ -19,7 +19,8 @@ class WavefrontCommandSavedsearch < WavefrontCommandBase
19
19
  ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
20
20
  "describe #{CMN} [-f format] <id>",
21
21
  "delete #{CMN} <id>",
22
- "import #{CMN} <file>"]
22
+ "import #{CMN} <file>",
23
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
23
24
  end
24
25
 
25
26
  def _options
@@ -8,18 +8,19 @@ class WavefrontCommandSource < WavefrontCommandBase
8
8
  end
9
9
 
10
10
  def _commands
11
- ["list #{CMN} [-l] [-f format] [-o offset] [-L limit] [-a]",
11
+ ["list #{CMN} [-l] [-f format] [-o cursor] [-L limit] [-a]",
12
12
  "describe #{CMN} [-f format] <id>",
13
13
  "description set #{CMN} <id> <description>",
14
14
  "description clear #{CMN} <id>",
15
15
  "clear #{CMN} <id>",
16
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>...",
16
17
  tag_commands]
17
18
  end
18
19
 
19
20
  def _options
20
21
  [common_options,
21
22
  '-l, --long list sources in detail',
22
- '-o, --offset=n start list from nth source',
23
+ '-o, --cursor=SOURCE start list given source',
23
24
  '-L, --limit=COUNT number of sources to list',
24
25
  '-a, --all list all sources, including cluster',
25
26
  '-f, --format=STRING output format']
@@ -12,7 +12,8 @@ class WavefrontCommandWebhook < WavefrontCommandBase
12
12
  "describe #{CMN} [-f format] <id>",
13
13
  "delete #{CMN} <id>",
14
14
  "import #{CMN} <file>",
15
- "update #{CMN} <key=value> <id>"]
15
+ "update #{CMN} <key=value> <id>",
16
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
16
17
  end
17
18
 
18
19
  def _options
@@ -20,7 +20,8 @@ class WavefrontCommandWindow < WavefrontCommandBase
20
20
  "describe #{CMN} [-f format] <id>",
21
21
  "delete #{CMN} <id>",
22
22
  "import #{CMN} <file>",
23
- "update #{CMN} <key=value> <id>"]
23
+ "update #{CMN} <key=value> <id>",
24
+ "search #{CMN} [-f format] [-o offset] [-L limit] [-l] <condition>..."]
24
25
  end
25
26
 
26
27
  def _options
@@ -9,9 +9,10 @@ class WavefrontCommandWrite < WavefrontCommandBase
9
9
 
10
10
  def _commands
11
11
  ['point [-DnV] [-c file] [-P profile] [-E proxy] [-t time] ' \
12
- '[-p port] [-H host] [-n] [-T tag...] <metric> <value>',
12
+ '[-p port] [-H host] [-n] [-T tag...] <metric> <value>',
13
13
  'file [-DnV] [-c file] [-P profile] [-E proxy] [-H host] ' \
14
- '[-p port] [-n] [-F format] [-m metric] [-T tag...] <file>']
14
+ '[-p port] [-n] [-F format] [-m metric] [-T tag...] ' \
15
+ '[-r rate] <file>']
15
16
  end
16
17
 
17
18
  def _options
@@ -24,12 +25,15 @@ class WavefrontCommandWrite < WavefrontCommandBase
24
25
  '-F, --infileformat=STRING format of input file or stdin',
25
26
  '-m, --metric=STRING the metric path to which contents of ' \
26
27
  'a file will be assigned. If the file contains a metric name, ' \
27
- 'the two will be concatenated']
28
+ 'the two will be dot-concatenated, with this value first',
29
+ '-r, --rate=INTEGER throttle point sending to this many ' \
30
+ 'points per second']
28
31
  end
29
32
 
30
33
  def postscript
31
- %(Files are whitespace separated, and fields can be defined
32
- with the -F option. Use 't' for timestamp; 'm' for metric
33
- name; 'v' for value and 'T' for tags. Put 'T' last.)
34
+ 'Files are whitespace separated, and fields can be defined ' \
35
+ "with the '-F' option. Use 't' for timestamp; 'm' for metric " \
36
+ "name; 'v' for value, 's' for source, and 'T' for tags. Put 'T' " \
37
+ 'last.'.cmd_fold(TW, 0)
34
38
  end
35
39
  end
@@ -11,7 +11,7 @@ module WavefrontCli
11
11
  #
12
12
  DEFAULT_OPTS = {
13
13
  endpoint: 'metrics.wavefront.com',
14
- format: :human,
14
+ format: :human
15
15
  }.freeze
16
16
  end
17
17
  end