wavefront-cli 6.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -7
  3. data/.travis.yml +4 -5
  4. data/HISTORY.md +34 -1
  5. data/README.md +3 -4
  6. data/lib/wavefront-cli/account.rb +119 -0
  7. data/lib/wavefront-cli/alert.rb +29 -0
  8. data/lib/wavefront-cli/base.rb +10 -12
  9. data/lib/wavefront-cli/cloudintegration.rb +12 -0
  10. data/lib/wavefront-cli/commands/.rubocop.yml +12 -6
  11. data/lib/wavefront-cli/commands/account.rb +61 -0
  12. data/lib/wavefront-cli/commands/alert.rb +1 -0
  13. data/lib/wavefront-cli/commands/base.rb +1 -1
  14. data/lib/wavefront-cli/commands/cloudintegration.rb +4 -1
  15. data/lib/wavefront-cli/commands/proxy.rb +2 -1
  16. data/lib/wavefront-cli/commands/query.rb +4 -1
  17. data/lib/wavefront-cli/commands/role.rb +44 -0
  18. data/lib/wavefront-cli/commands/spy.rb +0 -5
  19. data/lib/wavefront-cli/commands/usergroup.rb +7 -11
  20. data/lib/wavefront-cli/commands/write.rb +7 -2
  21. data/lib/wavefront-cli/config.rb +3 -1
  22. data/lib/wavefront-cli/controller.rb +6 -66
  23. data/lib/wavefront-cli/display/account.rb +122 -0
  24. data/lib/wavefront-cli/display/alert.rb +8 -0
  25. data/lib/wavefront-cli/display/base.rb +1 -1
  26. data/lib/wavefront-cli/display/cloudintegration.rb +15 -2
  27. data/lib/wavefront-cli/display/printer/long.rb +6 -1
  28. data/lib/wavefront-cli/display/proxy.rb +16 -0
  29. data/lib/wavefront-cli/display/role.rb +66 -0
  30. data/lib/wavefront-cli/display/settings.rb +1 -0
  31. data/lib/wavefront-cli/display/usergroup.rb +18 -14
  32. data/lib/wavefront-cli/event.rb +2 -0
  33. data/lib/wavefront-cli/exception_handler.rb +87 -0
  34. data/lib/wavefront-cli/externallink.rb +4 -6
  35. data/lib/wavefront-cli/helpers/load_file.rb +1 -1
  36. data/lib/wavefront-cli/opt_handler.rb +5 -3
  37. data/lib/wavefront-cli/output/hcl/base.rb +1 -1
  38. data/lib/wavefront-cli/proxy.rb +5 -0
  39. data/lib/wavefront-cli/query.rb +13 -7
  40. data/lib/wavefront-cli/role.rb +54 -0
  41. data/lib/wavefront-cli/serviceaccount.rb +0 -6
  42. data/lib/wavefront-cli/spy.rb +0 -8
  43. data/lib/wavefront-cli/usergroup.rb +8 -8
  44. data/lib/wavefront-cli/version.rb +1 -1
  45. data/lib/wavefront-cli/write.rb +33 -11
  46. data/spec/.rubocop.yml +13 -6
  47. data/spec/support/minitest_assertions.rb +2 -4
  48. data/spec/test_mixins/delete.rb +1 -2
  49. data/spec/wavefront-cli/account_spec.rb +303 -0
  50. data/spec/wavefront-cli/alert_spec.rb +28 -0
  51. data/spec/wavefront-cli/cloudintegration_spec.rb +19 -6
  52. data/spec/wavefront-cli/commands/write_spec.rb +1 -1
  53. data/spec/wavefront-cli/config_spec.rb +1 -1
  54. data/spec/wavefront-cli/controller_spec.rb +2 -0
  55. data/spec/wavefront-cli/event_spec.rb +1 -1
  56. data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
  57. data/spec/wavefront-cli/output/wavefront/query_spec.rb +2 -2
  58. data/spec/wavefront-cli/query_spec.rb +20 -3
  59. data/spec/wavefront-cli/role_spec.rb +187 -0
  60. data/spec/wavefront-cli/serviceaccount_spec.rb +3 -3
  61. data/spec/wavefront-cli/usergroup_spec.rb +48 -43
  62. data/spec/wavefront-cli/write_spec.rb +44 -0
  63. data/wavefront-cli.gemspec +6 -6
  64. metadata +27 -36
  65. data/lib/wavefront-cli/commands/user.rb +0 -54
  66. data/lib/wavefront-cli/display/user.rb +0 -103
  67. data/lib/wavefront-cli/user.rb +0 -92
  68. data/spec/wavefront-cli/resources/responses/user-list.json +0 -1
  69. data/spec/wavefront-cli/user_spec.rb +0 -311
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99fe3332878acc67af828d3ab48a10f585c6166c6a350357a22d732695ff5b93
4
- data.tar.gz: bc3fc9708705d8bf4a8706daf8d24a8dd6882b71d3690843b3a58bb1d3772b65
3
+ metadata.gz: d831cf75206998d12f64271f13ce2b98c5cdeef18470b7f8e366f38c46a186e7
4
+ data.tar.gz: 8a0e75fe5bd16d0893d52a863daf04ed599418d848ee024d0c4177cb3837e30c
5
5
  SHA512:
6
- metadata.gz: a56fdece8a0122f64e076cdfa7846b698777a77528810d3ea6dc7d6b24febed750340fa8d717ae939af936f371de13a64fba3b076992e6b69403c75c1f32f841
7
- data.tar.gz: 2a3eeb43b52d61315e4ef6bbf6e6d80c0995a625b5d9a7233628011cbd4599dfc3602106e2d1e6bc628c571147d3e330fe3dc4819faa223e46d2943f732049f6
6
+ metadata.gz: 10a9becb4fd55031ce4913718b9a6e65f5bc05b92ba961ee8474889733991a816e455deaed6dec4869b1058d2c8fee515c51e4f6bc4091ee3e1560f7de1bc8e1
7
+ data.tar.gz: ac4a999ea2d23fc62c04612fdccb51c0bf3f66cf2017ea2980e58f3d684d2e145f53ebae429461498b832521154f674687a6cb3eaef438fb466e050ea7388e70
@@ -1,14 +1,19 @@
1
1
  ---
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.5
5
+ NewCops: enable
5
6
 
6
7
  Metrics/ClassLength:
7
8
  Max: 400
8
9
 
9
- Style/HashEachMethods:
10
- Enabled: true
11
- Style/HashTransformKeys:
12
- Enabled: true
13
- Style/HashTransformValues:
14
- Enabled: true
10
+ Style/IfUnlessModifier:
11
+ Enabled: false # because it wants to make lines >80 chars
12
+ Style/StringConcatenation:
13
+ Enabled: false
14
+ Style/OptionalBooleanParameter:
15
+ Enabled: false
16
+
17
+ # Is nothing sacred?
18
+ Layout/LineLength:
19
+ Max: 80
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.4.9
5
- - 2.5.7
6
- - 2.6.5
7
- - 2.7.0
4
+ - 2.5.8
5
+ - 2.6.6
6
+ - 2.7.1
8
7
  before_install: gem install bundler --no-document
9
8
  deploy:
10
9
  provider: rubygems
@@ -14,7 +13,7 @@ deploy:
14
13
  on:
15
14
  tags: true
16
15
  repo: snltd/wavefront-cli
17
- ruby: 2.6.5
16
+ ruby: 2.6.6
18
17
  notifications:
19
18
  email: false
20
19
  slack:
data/HISTORY.md CHANGED
@@ -1,14 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## 8.0.1 (2020-09-28)
4
+ * If the user specifies a config stanza and it is not found, exit with an
5
+ error rather than silently falling back to env vars.
6
+
7
+ ## 8.0.0 (2020-09-20
8
+ * Drop Ruby 2.4.0 support. (Breaking change.)
9
+ >>>>>>> master
10
+
11
+ ## 7.2.0 (2020-08-12)
12
+ * Add `cloudintegration awsid generate` command.
13
+ * Add `cloudintegration awsid delete <external_id>` command.
14
+ * Add `cloudintegration awsid validate <external_id>` command.
15
+ * Require 5.1.x of [the SDK](https://github.com/snltd/wavefront-sdk).
16
+
17
+ ## 7.1.0 (2020-08-07)
18
+ * Remove `user` command. (Breaking change.)
19
+ * Add `account` command.
20
+ * Complete coverage of roles and user groups.
21
+ * Add `alert affected hosts` command to show which hosts are affected by one
22
+ or all firing alerts.
23
+ * Remove obsolete `group` subcommands. (`grant` and `revoke`).
24
+ * Add `write noise` command to send a flow of random data to an endpoint.
25
+ * Better information when working with cloud integrations.
26
+
27
+ ## 7.0.0 (unreleased)
28
+
29
+ ## 6.1.0 (2020-06-02)
30
+ * Add `-A` flag to `proxy list` command, to only list active proxies
31
+
3
32
  ## 6.0.0 (2020-04-07)
4
33
  * Remove `cluster` command. (Breaking change.)
34
+ * Add `role` command.
35
+ * Add `--nocache`, `--nostrict` and `--histogram-view` options to `query`
36
+ command.
37
+ * Require 5.x of [the SDK](https://github.com/snltd/wavefront-sdk).
5
38
 
6
39
  ## 5.1.2 (2020-02-28)
7
40
  * Fix regression in HCL dashboard export.
8
41
  * Properly handle unavailable port when sending distributions to a proxy.
9
42
 
10
43
  ## 5.1.1 (2020-02-20)
11
- * Say whether `--upsert` did and update or an import.
44
+ * Say whether `--upsert` did an update or an import.
12
45
 
13
46
  ## 5.1.0 (2020-02-20)
14
47
  * Add `-U` (`--upsert`) option to `import` sub-commands.
data/README.md CHANGED
@@ -15,7 +15,7 @@ $ gem install wavefront-cli
15
15
 
16
16
  It is built on [our Wavefront Ruby
17
17
  SDK](https://github.com/snltd/wavefront-sdk) and requires Ruby >=
18
- 2.4. It has no "native extension" dependencies.
18
+ 2.5. It has no "native extension" dependencies.
19
19
 
20
20
  For a far more comprehensive overview/tutorial, please read [this
21
21
  article](https://sysdef.xyz/article/wavefront-cli).
@@ -51,7 +51,6 @@ Commands:
51
51
  source view and manage source tags and descriptions
52
52
  spy monitor traffic going into Wavefront
53
53
  usage view and manage usage reports
54
- user view and manage Wavefront users
55
54
  usergroup view and manage Wavefront user groups
56
55
  webhook view and manage webhooks
57
56
  window view and manage maintenance windows
@@ -103,7 +102,7 @@ $ wf proxy list
103
102
 
104
103
  You can get more verbose listings with the `-l` flag. Results may be
105
104
  paginated. You can progress through pages with the `-L` and `-o`
106
- options, or user `--all` to get everything in one go.
105
+ options, or use `--all` to get everything in one go.
107
106
 
108
107
  ### Describing Things
109
108
 
@@ -151,7 +150,7 @@ mentioned above, human-readable listings and desctiptions may omit
151
150
  data which is not likely to be useful, or which is extremely hard to
152
151
  present in a readable way.
153
152
 
154
- If you `describe` an object like a dashboard, user, webhook etc as
153
+ If you `describe` an object like a dashboard, account, webhook etc as
155
154
  `json` or `yaml`, and send the output to a file, you can re-import
156
155
  that data. The format of the file to be imported is automatically
157
156
  detected.
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module WavefrontCli
6
+ #
7
+ # CLI coverage for the v2 'account' API.
8
+ #
9
+ class Account < WavefrontCli::Base
10
+ alias do_roles do_describe
11
+ alias do_groups do_describe
12
+ alias do_ingestionpolicy do_describe
13
+ alias do_permissions do_describe
14
+
15
+ def do_role_add_to
16
+ wf_account_id?(options[:'<id>'])
17
+ wf.add_roles(options[:'<id>'], options[:'<role>'])
18
+ end
19
+
20
+ def do_role_remove_from
21
+ wf_account_id?(options[:'<id>'])
22
+ wf.remove_roles(options[:'<id>'], options[:'<role>'])
23
+ end
24
+
25
+ def do_group_add_to
26
+ wf_account_id?(options[:'<id>'])
27
+ wf.add_user_groups(options[:'<id>'], options[:'<group>'])
28
+ end
29
+
30
+ def do_group_remove_from
31
+ wf_account_id?(options[:'<id>'])
32
+ wf.remove_user_groups(options[:'<id>'], options[:'<group>'])
33
+ end
34
+
35
+ def do_business_functions
36
+ wf_user_id?(options[:'<id>'])
37
+ wf.business_functions(options[:'<id>'])
38
+ end
39
+
40
+ def do_grant_to
41
+ wf.grant(options[:'<account>'], options[:'<permission>'])
42
+ end
43
+
44
+ def do_revoke_from
45
+ wf.revoke(options[:'<account>'], options[:'<permission>'])
46
+ end
47
+
48
+ def do_ingestionpolicy_add_to
49
+ wf_account_id?(options[:'<id>'])
50
+ wf.add_ingestion_policy(options[:'<policy>'], [options[:'<id>']])
51
+ end
52
+
53
+ def do_ingestionpolicy_remove_from
54
+ wf_account_id?(options[:'<id>'])
55
+ wf_ingestionpolicy_id?(options[:'<policy>'])
56
+ wf.remove_ingestion_policy(options[:'<policy>'], [options[:'<id>']])
57
+ end
58
+
59
+ def do_create_user
60
+ wf_user_id?(options[:'<id>'])
61
+ wf.user_create(user_body)
62
+ end
63
+
64
+ def do_invite_user
65
+ wf_user_id?(options[:'<id>'])
66
+ wf.user_invite([user_body])
67
+ end
68
+
69
+ def do_validate
70
+ wf.validate_accounts(options[:'<account>'])
71
+ end
72
+
73
+ def extra_validation
74
+ validate_policy
75
+ validate_permission
76
+ validate_roles
77
+ validate_groups
78
+ validate_accounts
79
+ end
80
+
81
+ private
82
+
83
+ def validate_policy
84
+ wf_ingestionpolicy_id?(options[:'<policy>']) if options[:'<policy>']
85
+ end
86
+
87
+ def validate_permission
88
+ wf_permission?(options[:'<permission>']) if options[:'<permission>']
89
+ end
90
+
91
+ def validate_roles
92
+ options[:'<role>'].each { |r| wf_role_id?(r) }
93
+ end
94
+
95
+ def validate_groups
96
+ options[:'<group>'].each { |g| wf_usergroup_id?(g) }
97
+ end
98
+
99
+ def validate_accounts
100
+ options[:'<account>'].each { |a| wf_account_id?(a) }
101
+ end
102
+
103
+ # Object used to create and invite users. We deal with the permissions
104
+ # seperately because if we don't supply any and they get compacted out,
105
+ # the user is created with a default set of perms, and we don't want that.
106
+ #
107
+ def user_body
108
+ raw = {
109
+ emailAddress: options[:'<id>'],
110
+ roles: options[:roleid],
111
+ ingestionPolicyId: options[:policyid],
112
+ userGroups: options[:groupid]
113
+ }.reject { |_k, v| v&.empty? }.compact
114
+
115
+ raw[:groups] = options[:permission]
116
+ raw
117
+ end
118
+ end
119
+ end
@@ -50,6 +50,14 @@ module WavefrontCli
50
50
  wf.history(options[:'<id>'], options[:offset], options[:limit])
51
51
  end
52
52
 
53
+ def do_affected_hosts
54
+ if options[:'<id>']
55
+ affected_hosts_for_id(options[:'<id>'])
56
+ else
57
+ all_affected_hosts
58
+ end
59
+ end
60
+
53
61
  def do_currently
54
62
  state = options[:'<state>'].to_s
55
63
 
@@ -146,5 +154,26 @@ module WavefrontCli
146
154
  end
147
155
  end.compact
148
156
  end
157
+
158
+ def all_affected_hosts
159
+ cannot_noop!
160
+ in_state(:firing).tap do |r|
161
+ r.response = r.response.items.each_with_object({}) do |alert, aggr|
162
+ aggr[alert[:id]] = affected_hosts_for_id(alert[:id]).response
163
+ end
164
+ end
165
+ end
166
+
167
+ def affected_hosts_for_id(id)
168
+ resp = wf.describe(id)
169
+
170
+ return if options[:noop]
171
+
172
+ return resp unless resp.ok? && resp.response.key?(:failingHostLabelPairs)
173
+
174
+ resp.tap do |r|
175
+ r.response = r.response[:failingHostLabelPairs].map { |h| h[:host] }
176
+ end
177
+ end
149
178
  end
150
179
  end
@@ -102,12 +102,10 @@ module WavefrontCli
102
102
 
103
103
  def validate_tags(key = :'<tag>')
104
104
  Array(options[key]).each do |t|
105
- begin
106
- send(:wf_tag?, t)
107
- rescue Wavefront::Exception::InvalidTag
108
- raise(WavefrontCli::Exception::InvalidInput,
109
- "'#{t}' is not a valid tag.")
110
- end
105
+ send(:wf_tag?, t)
106
+ rescue Wavefront::Exception::InvalidTag
107
+ raise(WavefrontCli::Exception::InvalidInput,
108
+ "'#{t}' is not a valid tag.")
111
109
  end
112
110
  end
113
111
 
@@ -371,9 +369,10 @@ module WavefrontCli
371
369
  def do_dump
372
370
  cannot_noop!
373
371
 
374
- if options[:format] == 'yaml'
372
+ case options[:format]
373
+ when 'yaml'
375
374
  ok_exit dump_yaml
376
- elsif options[:format] == 'json'
375
+ when 'json'
377
376
  ok_exit dump_json
378
377
  else
379
378
  abort format("Dump format must be 'json' or 'yaml'. " \
@@ -485,7 +484,6 @@ module WavefrontCli
485
484
  # @param cond [String] a search condition, like "key=value"
486
485
  # @return [Hash] of matchingMethod and negated
487
486
  #
488
- # rubocop:disable Metrics/CyclomaticComplexity
489
487
  # rubocop:disable Metrics/MethodLength
490
488
  def matching_method(cond)
491
489
  case cond
@@ -506,7 +504,6 @@ module WavefrontCli
506
504
  end
507
505
  end
508
506
  # rubocop:enable Metrics/MethodLength
509
- # rubocop:enable Metrics/CyclomaticComplexity
510
507
 
511
508
  # Return a detailed description of one item, if an ID has been
512
509
  # given, or all items if it has not.
@@ -541,7 +538,8 @@ module WavefrontCli
541
538
  #
542
539
  # rubocop:disable Metrics/MethodLength
543
540
  def extract_values(obj, key, aggr = [])
544
- if obj.is_a?(Hash)
541
+ case obj.class
542
+ when Hash
545
543
  obj.each_pair do |k, v|
546
544
  if k == key && !v.to_s.empty?
547
545
  aggr.<< v
@@ -549,7 +547,7 @@ module WavefrontCli
549
547
  extract_values(v, key, aggr)
550
548
  end
551
549
  end
552
- elsif obj.is_a?(Array)
550
+ when Array
553
551
  obj.each { |e| extract_values(e, key, aggr) }
554
552
  end
555
553
 
@@ -22,5 +22,17 @@ module WavefrontCli
22
22
  def do_disable
23
23
  wf.disable(options[:'<id>'])
24
24
  end
25
+
26
+ def do_awsid_generate
27
+ wf.create_aws_external_id
28
+ end
29
+
30
+ def do_awsid_delete
31
+ wf.delete_aws_external_id(options[:'<external_id>'])
32
+ end
33
+
34
+ def do_awsid_confirm
35
+ wf.confirm_aws_external_id(options[:'<external_id>'])
36
+ end
25
37
  end
26
38
  end
@@ -1,13 +1,19 @@
1
1
  ---
2
+ AllCops:
3
+ NewCops: enable
2
4
 
3
5
  # There are long things in here, but they're fine
4
6
  #
5
7
  Metrics/MethodLength:
6
8
  Max: 25
7
9
 
8
- Style/HashEachMethods:
9
- Enabled: true
10
- Style/HashTransformKeys:
11
- Enabled: true
12
- Style/HashTransformValues:
13
- Enabled: true
10
+ # Is nothing sacred?
11
+ Layout/LineLength:
12
+ Max: 80
13
+
14
+ Style/IfUnlessModifier:
15
+ Enabled: false # because it wants to make lines >80 chars
16
+ Style/StringConcatenation:
17
+ Enabled: false
18
+ Style/OptionalBooleanParameter:
19
+ Enabled: false
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ # Define the account command.
6
+ #
7
+ class WavefrontCommandAccount < WavefrontCommandBase
8
+ def description
9
+ "view and manage Wavefront #{things}"
10
+ end
11
+
12
+ def _commands
13
+ ["list #{CMN} [-sSal] [-O fields] [-o offset] [-L limit]",
14
+ "describe #{CMN} <id>",
15
+ "create user #{CMN} [-m permission...] [-g group-id...] " \
16
+ '[-r role-id...] [-i policy-id] <id>',
17
+ "invite user #{CMN} [-m permission...] [-g group-id...] " \
18
+ '[-r role-id...] [-i policy-id] <id>',
19
+ "delete #{CMN} <id>",
20
+ "dump #{CMN}",
21
+ "import #{CMN} [-uU] <file>",
22
+ "role #{CMN} add to <id> <role>...",
23
+ "role #{CMN} remove from <id> <role>...",
24
+ "roles #{CMN} <id>",
25
+ "ingestionpolicy #{CMN} add to <id> <policy>",
26
+ "ingestionpolicy #{CMN} remove from <id> <policy>",
27
+ "ingestionpolicy #{CMN} <id>",
28
+ "group #{CMN} add to <id> <group>...",
29
+ "group #{CMN} remove from <id> <group>...",
30
+ "groups #{CMN} <id>",
31
+ "grant #{CMN} <permission> to <account>...",
32
+ "revoke #{CMN} <permission> from <account>...",
33
+ "permissions #{CMN} <id>",
34
+ "business functions #{CMN} <id>",
35
+ "validate #{CMN} [-l] <account>...",
36
+ "search #{CMN} [-al] [-o offset] [-L limit] [-O fields] <condition>..."]
37
+ end
38
+
39
+ def _options
40
+ [common_options,
41
+ "-l, --long list #{things} in detail",
42
+ "-a, --all list all #{things}",
43
+ "-o, --offset=n start from nth #{thing}",
44
+ "-L, --limit=COUNT number of #{things} to list",
45
+ '-s, --service list only service accounts',
46
+ '-S, --user list only user accounts',
47
+ '-O, --fields=F1,F2,... only show given fields',
48
+ "-u, --update update an existing #{thing}",
49
+ "-U, --upsert import new or update existing #{thing}",
50
+ '-m, --permission=STRING Wavefront permission name',
51
+ '-g, --groupid=STRING Wavefront usergroup ID',
52
+ '-r, --roleid=STRING Wavefront role ID',
53
+ '-i, --policyid=STRING Wavefront ingestion policy ID']
54
+ end
55
+
56
+ def postscript
57
+ 'Service accounts can be partially managed with this command, but ' \
58
+ "'wf serviceaccount' has more features.\n\nFor a list of permissions, " \
59
+ "run 'wf settings list permissions'.".fold(TW, 0)
60
+ end
61
+ end