wavefront-cli 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +20 -0
  3. data/.gitignore +4 -0
  4. data/.travis.yml +16 -0
  5. data/Gemfile +2 -0
  6. data/Gemfile.lock +65 -0
  7. data/README.md +221 -0
  8. data/Rakefile +18 -0
  9. data/bin/wavefront +14 -0
  10. data/lib/wavefront-cli/alert.rb +60 -0
  11. data/lib/wavefront-cli/base.rb +320 -0
  12. data/lib/wavefront-cli/cloudintegration.rb +12 -0
  13. data/lib/wavefront-cli/commands/alert.rb +38 -0
  14. data/lib/wavefront-cli/commands/base.rb +105 -0
  15. data/lib/wavefront-cli/commands/dashboard.rb +29 -0
  16. data/lib/wavefront-cli/commands/event.rb +44 -0
  17. data/lib/wavefront-cli/commands/integration.rb +33 -0
  18. data/lib/wavefront-cli/commands/link.rb +34 -0
  19. data/lib/wavefront-cli/commands/message.rb +23 -0
  20. data/lib/wavefront-cli/commands/metric.rb +20 -0
  21. data/lib/wavefront-cli/commands/proxy.rb +25 -0
  22. data/lib/wavefront-cli/commands/query.rb +32 -0
  23. data/lib/wavefront-cli/commands/savedsearch.rb +32 -0
  24. data/lib/wavefront-cli/commands/source.rb +27 -0
  25. data/lib/wavefront-cli/commands/user.rb +24 -0
  26. data/lib/wavefront-cli/commands/webhook.rb +25 -0
  27. data/lib/wavefront-cli/commands/window.rb +33 -0
  28. data/lib/wavefront-cli/commands/write.rb +35 -0
  29. data/lib/wavefront-cli/constants.rb +17 -0
  30. data/lib/wavefront-cli/controller.rb +134 -0
  31. data/lib/wavefront-cli/dashboard.rb +27 -0
  32. data/lib/wavefront-cli/display/alert.rb +44 -0
  33. data/lib/wavefront-cli/display/base.rb +304 -0
  34. data/lib/wavefront-cli/display/cloudintegration.rb +18 -0
  35. data/lib/wavefront-cli/display/dashboard.rb +21 -0
  36. data/lib/wavefront-cli/display/event.rb +19 -0
  37. data/lib/wavefront-cli/display/externallink.rb +13 -0
  38. data/lib/wavefront-cli/display/maintenancewindow.rb +19 -0
  39. data/lib/wavefront-cli/display/message.rb +8 -0
  40. data/lib/wavefront-cli/display/metric.rb +22 -0
  41. data/lib/wavefront-cli/display/proxy.rb +13 -0
  42. data/lib/wavefront-cli/display/query.rb +69 -0
  43. data/lib/wavefront-cli/display/savedsearch.rb +17 -0
  44. data/lib/wavefront-cli/display/source.rb +26 -0
  45. data/lib/wavefront-cli/display/user.rb +16 -0
  46. data/lib/wavefront-cli/display/webhook.rb +24 -0
  47. data/lib/wavefront-cli/display/write.rb +19 -0
  48. data/lib/wavefront-cli/event.rb +162 -0
  49. data/lib/wavefront-cli/exception.rb +5 -0
  50. data/lib/wavefront-cli/externallink.rb +16 -0
  51. data/lib/wavefront-cli/maintenancewindow.rb +16 -0
  52. data/lib/wavefront-cli/message.rb +19 -0
  53. data/lib/wavefront-cli/metric.rb +24 -0
  54. data/lib/wavefront-cli/opt_handler.rb +62 -0
  55. data/lib/wavefront-cli/proxy.rb +22 -0
  56. data/lib/wavefront-cli/query.rb +74 -0
  57. data/lib/wavefront-cli/savedsearch.rb +24 -0
  58. data/lib/wavefront-cli/source.rb +20 -0
  59. data/lib/wavefront-cli/user.rb +25 -0
  60. data/lib/wavefront-cli/version.rb +1 -0
  61. data/lib/wavefront-cli/webhook.rb +8 -0
  62. data/lib/wavefront-cli/write.rb +244 -0
  63. data/spec/spec_helper.rb +197 -0
  64. data/spec/wavefront-cli/alert_spec.rb +44 -0
  65. data/spec/wavefront-cli/base_spec.rb +47 -0
  66. data/spec/wavefront-cli/cli_help_spec.rb +47 -0
  67. data/spec/wavefront-cli/cloudintegration_spec.rb +24 -0
  68. data/spec/wavefront-cli/dashboard_spec.rb +37 -0
  69. data/spec/wavefront-cli/event_spec.rb +19 -0
  70. data/spec/wavefront-cli/externallink_spec.rb +18 -0
  71. data/spec/wavefront-cli/maintanancewindow_spec.rb +19 -0
  72. data/spec/wavefront-cli/message_spec.rb +28 -0
  73. data/spec/wavefront-cli/metric_spec.rb +22 -0
  74. data/spec/wavefront-cli/proxy_spec.rb +26 -0
  75. data/spec/wavefront-cli/query_spec.rb +63 -0
  76. data/spec/wavefront-cli/resources/conf.yaml +10 -0
  77. data/spec/wavefront-cli/savedsearch_spec.rb +18 -0
  78. data/spec/wavefront-cli/source_spec.rb +18 -0
  79. data/spec/wavefront-cli/user_spec.rb +31 -0
  80. data/spec/wavefront-cli/webhook_spec.rb +17 -0
  81. data/wavefront-cli.gemspec +36 -0
  82. metadata +279 -0
@@ -0,0 +1,12 @@
1
+ require_relative './base'
2
+
3
+ module WavefrontCli
4
+ #
5
+ # CLI coverage for the v2 'cloudintegration' API.
6
+ #
7
+ class CloudIntegration < WavefrontCli::Base
8
+ def validator_exception
9
+ Wavefront::Exception::InvalidCloudIntegrationId
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './base'
2
+
3
+ # Define the Alert command
4
+ #
5
+ class WavefrontCommandAlert < WavefrontCommandBase
6
+ def description
7
+ 'view and manage alerts'
8
+ end
9
+
10
+ def _commands
11
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
12
+ "describe #{CMN} [-f format] [-v version] <id>",
13
+ "delete #{CMN} <id>",
14
+ "undelete #{CMN} <id>",
15
+ "history #{CMN} [-f format] [-o offset] [-L limit] <id>",
16
+ "import #{CMN} <file>",
17
+ "snooze #{CMN} [-T time] <id>",
18
+ "update #{CMN} <key=value> <id>",
19
+ "unsnooze #{CMN} <id>",
20
+ "tags #{CMN} [-f format] <id>",
21
+ "tag set #{CMN} <id> <tag>...",
22
+ "tag clear #{CMN} <id>",
23
+ "tag add #{CMN} <id> <tag>",
24
+ "tag delete #{CMN} <id> <tag>",
25
+ "summary #{CMN} [-a]"]
26
+ end
27
+
28
+ def _options
29
+ [common_options,
30
+ '-l, --long list alerts in detail',
31
+ '-v, --version=INTEGER describe only this version of alert',
32
+ '-o, --offset=n start from nth alert',
33
+ '-L, --limit=COUNT number of alerts to list',
34
+ '-T, --time=SECONDS how long to snooze (default 3600)',
35
+ '-a, --all list all alerts',
36
+ '-f, --format=STRING output format']
37
+ end
38
+ end
@@ -0,0 +1,105 @@
1
+ CMN = '[-DnV] [-c file] [-P profile] [-E endpoint] [-t token]'.freeze
2
+
3
+ # A base class which all command classes extend.
4
+ #
5
+ class WavefrontCommandBase
6
+ # All commands have these options
7
+ #
8
+ def global_options
9
+ ['-c, --config=FILE path to configuration file',
10
+ '-P, --profile=NAME profile in configuration file',
11
+ '-D, --debug enable debug mode',
12
+ '-n, --noop do not perform API calls',
13
+ '-V, --verbose be verbose',
14
+ '-h, --help show this message']
15
+ end
16
+
17
+ # Many commands have these options
18
+ #
19
+ def common_options
20
+ ['-E, --endpoint=URI cluster endpoint',
21
+ '-t, --token=TOKEN Wavefront authentication token']
22
+ end
23
+
24
+ # Anything which takes tags provides the same interface
25
+ #
26
+ def tag_commands
27
+ ["tags #{CMN} [-f format] <id>",
28
+ "tag set #{CMN} <id> <tag>...",
29
+ "tag clear #{CMN} <id>",
30
+ "tag add #{CMN} <id> <tag>",
31
+ "tag delete #{CMN} <id> <tag>"]
32
+ end
33
+
34
+ # The command keyword
35
+ #
36
+ def word
37
+ self.class.name.sub(/WavefrontCommand/, '').downcase
38
+ end
39
+
40
+ # Returns the name of the SDK class which does the work for this
41
+ # command.
42
+ #
43
+ def sdk_class
44
+ word.capitalize
45
+ end
46
+
47
+ def sdk_file
48
+ word
49
+ end
50
+
51
+ # Returns a string describing the subcommands the command offers.
52
+ #
53
+ def commands
54
+ _commands.flatten.each_with_object("Usage:\n") do |cmd, ret|
55
+ ret.<< ' ' + "#{CMD} #{word} #{cmd}\n".cmd_fold + "\n"
56
+ end + " #{CMD} #{word} --help"
57
+ end
58
+
59
+ # Returns a string describing the options the command understands.
60
+ #
61
+ def options
62
+ width = column_widths
63
+ ret = "Global options:\n"
64
+ global_options.each { |o| ret.<< opt_row(o, width) }
65
+ ret.<< "\nOptions:\n"
66
+ _options.flatten.each { |o| ret.<< opt_row(o, width) }
67
+ ret
68
+ end
69
+
70
+ def opt_row(opt, width)
71
+ format(" %s %-#{width}s %s\n", *opt.split(/\s+/, 3))
72
+ end
73
+
74
+ def column_widths
75
+ (global_options + _options).flatten.map do |o|
76
+ o.split(/\s+/, 3)[0..1].join(' ').size
77
+ end.max
78
+ end
79
+
80
+ # Returns a string which will be printed underneath the options.
81
+ #
82
+ def postscript
83
+ ''
84
+ end
85
+
86
+ # Returns a full options string which docopt understands
87
+ #
88
+ def docopt
89
+ commands + "\n\n" + options + "\n" + postscript
90
+ end
91
+ 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
@@ -0,0 +1,29 @@
1
+ require_relative './base'
2
+
3
+ # Define the dashboard command.
4
+ #
5
+ class WavefrontCommandDashboard < WavefrontCommandBase
6
+ def description
7
+ 'view and manage dashboards'
8
+ end
9
+
10
+ def _commands
11
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
12
+ "describe #{CMN} [-f format] [-v version] <id>",
13
+ "import #{CMN} [-f format] [-F] <file>",
14
+ "update #{CMN} <key=value> <id>",
15
+ "delete #{CMN} <id>",
16
+ "undelete #{CMN} <id>",
17
+ "history #{CMN} [-b] [-f format] [-o offset] [-L limit] <id>",
18
+ tag_commands]
19
+ end
20
+
21
+ def _options
22
+ [common_options,
23
+ '-l, --long list dashboards in detail',
24
+ '-o, --offset=n start list from nth dashboard or revision',
25
+ '-L, --limit=COUNT number of dashboards or revisions to list',
26
+ '-v, --version=INTEGER version of dashboard',
27
+ '-f, --format=STRING output format']
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ require_relative './base'
2
+
3
+ # Define the event command.
4
+ #
5
+ class WavefrontCommandEvent < WavefrontCommandBase
6
+ def description
7
+ 'open, close, view, and manage events'
8
+ end
9
+
10
+ def _commands
11
+ ["list #{CMN} [-l] [-f format] [-s start] [-e end] [-L limit] " \
12
+ '[-o offset]',
13
+ "describe #{CMN} [-f format] <id>",
14
+ "create #{CMN} [-d description] [-s time] [-i | -e time] " \
15
+ '[-S severity] [-T type] [-H host...] [-N] <event>',
16
+ "close #{CMN} [<id>]",
17
+ "delete #{CMN} <id>",
18
+ "update #{CMN} <key=value> <id>",
19
+ tag_commands,
20
+ 'show [-D]']
21
+ end
22
+
23
+ def _options
24
+ [common_options,
25
+ '-l, --long list events in detail',
26
+ '-o, --offset=n start list from nth event',
27
+ '-L, --limit=COUNT number of events to list',
28
+ '-s, --start=TIME time at which event/window begins',
29
+ '-e, --end=TIME time at which even/window ends',
30
+ '-S, --severity=SEVERITY severity of event',
31
+ '-i, --instant create an instantaneous event',
32
+ '-T, --type=TYPE type of event',
33
+ '-d, --desc=STRING description of event',
34
+ '-H, --host=STRING source to which event applies',
35
+ '-N, --nostate do not create a local file recording ' \
36
+ 'the event',
37
+ '-f, --format=STRING output format']
38
+ end
39
+
40
+ def postscript
41
+ "View events in detail using the 'query' command with the " \
42
+ "'events()' function."
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ require_relative './base'
2
+
3
+ # Define the cloud integration command.
4
+ #
5
+ class WavefrontCommandIntegration < WavefrontCommandBase
6
+ def description
7
+ 'view and manage cloud integrations'
8
+ end
9
+
10
+ def sdk_file
11
+ 'cloudintegration'
12
+ end
13
+
14
+ def sdk_class
15
+ 'CloudIntegration'
16
+ end
17
+
18
+ def _commands
19
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
20
+ "describe #{CMN} [-f format] <id>",
21
+ "delete #{CMN} <id>",
22
+ "undelete #{CMN} <id>",
23
+ "import #{CMN} <file>"]
24
+ end
25
+
26
+ def _options
27
+ [common_options,
28
+ '-l, --long list integrations in detail',
29
+ '-o, --offset=n start from nth integration',
30
+ '-L, --limit=COUNT number of integrations to list',
31
+ '-f, --format=STRING output format']
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ require_relative './base'
2
+
3
+ # Define the external link command.
4
+ #
5
+ class WavefrontCommandLink < WavefrontCommandBase
6
+ def description
7
+ 'view and manage external links'
8
+ end
9
+
10
+ def sdk_file
11
+ 'externallink'
12
+ end
13
+
14
+ def sdk_class
15
+ 'ExternalLink'
16
+ end
17
+
18
+ def _commands
19
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
20
+ "describe #{CMN} [-f format] <id>",
21
+ "delete #{CMN} <id>",
22
+ "import #{CMN} <file>",
23
+ "update #{CMN} <key=value> <id>"
24
+ ]
25
+ end
26
+
27
+ def _options
28
+ [common_options,
29
+ '-l, --long list external links in detail',
30
+ '-o, --offset=n start from nth external link',
31
+ '-L, --limit=COUNT number of external link to list',
32
+ '-f, --format=STRING output format']
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ require_relative './base'
2
+
3
+ # Define the message command.
4
+ #
5
+ class WavefrontCommandMessage < WavefrontCommandBase
6
+ def description
7
+ 'read and mark user messages'
8
+ end
9
+
10
+ def _commands
11
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit] [-a]",
12
+ "mark #{CMN} [-f format] <id>"]
13
+ end
14
+
15
+ def _options
16
+ [common_options,
17
+ '-l, --long list messages in detail',
18
+ '-o, --offset=n start from nth message',
19
+ '-L, --limit=COUNT number of messages to list',
20
+ '-a, --all list all messages, not just unread',
21
+ '-f, --format=STRING output format']
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require_relative './base'
2
+
3
+ # Define the metric command.
4
+ #
5
+ class WavefrontCommandMetric < WavefrontCommandBase
6
+ def description
7
+ 'view metrics'
8
+ end
9
+
10
+ def _commands
11
+ ["describe #{CMN} [-f format] [-o offset] [-g glob...] <metric>"]
12
+ end
13
+
14
+ def _options
15
+ [common_options,
16
+ '-o, --offset=STRING value to start from if results > 1000',
17
+ '-g, --glob=STRING return sources matching this pattern',
18
+ '-f, --format=STRING output format']
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './base'
2
+
3
+ # Define the proxy command.
4
+ #
5
+ class WavefrontCommandProxy < WavefrontCommandBase
6
+ def description
7
+ 'view and manage Wavefront proxies'
8
+ end
9
+
10
+ def _commands
11
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
12
+ "describe #{CMN} [-f format] <id>",
13
+ "delete #{CMN} <id>",
14
+ "undelete #{CMN} <id>",
15
+ "rename #{CMN} <id> <name>"]
16
+ end
17
+
18
+ def _options
19
+ [common_options,
20
+ '-l, --long list proxies in detail',
21
+ '-o, --offset=n start from nth proxy',
22
+ '-f, --format=STRING output format',
23
+ '-L, --limit=COUNT number of proxies to list']
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require_relative './base'
2
+
3
+ # Define the query command.
4
+ #
5
+ class WavefrontCommandQuery < WavefrontCommandBase
6
+ def description
7
+ 'query the Wavefront API'
8
+ end
9
+
10
+ def _commands
11
+ ["#{CMN} [-g granularity] [-s time] [-e time] [-f format] " \
12
+ '[-ivO] [-S mode] [-N name] [-p points] <query>',
13
+ "raw #{CMN} [-H host] [-s time] [-e time] [-f format] <metric>"]
14
+ end
15
+
16
+ def _options
17
+ [common_options,
18
+ '-g, --granularity=STRING query granularity (d, h, m, or s)',
19
+ '-s, --start=TIME start of query window',
20
+ '-e, --end=TIME end of query window',
21
+ '-N, --name=STRING name identifying query',
22
+ '-p, --points=INTEGER maximum number of points to return',
23
+ '-i, --inclusive include matching series with no ' \
24
+ 'points inside the query window',
25
+ '-v, --events include events for matching series',
26
+ '-S, --summarize=STRING summarization strategy for bucketing ' \
27
+ 'points (mean, median, min, max, sum, count, last, first)',
28
+ '-O, --obsolete include metrics unreported for > 4 weeks',
29
+ '-H, --host=STRING host or source to query on',
30
+ '-f, --format=STRING output format']
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ require_relative './base'
2
+
3
+ # Define the saved search command.
4
+ #
5
+ class WavefrontCommandSavedsearch < WavefrontCommandBase
6
+ def description
7
+ 'view and manage saved searches'
8
+ end
9
+
10
+ def sdk_file
11
+ 'savedsearch'
12
+ end
13
+
14
+ def sdk_class
15
+ 'SavedSearch'
16
+ end
17
+
18
+ def _commands
19
+ ["list #{CMN} [-l] [-f format] [-o offset] [-L limit]",
20
+ "describe #{CMN} [-f format] <id>",
21
+ "delete #{CMN} <id>",
22
+ "import #{CMN} <file>"]
23
+ end
24
+
25
+ def _options
26
+ [common_options,
27
+ '-l, --long list saved searches in detail',
28
+ '-o, --offset=n start from nth saved search',
29
+ '-L, --limit=COUNT number of saved searches to list',
30
+ '-f, --format=STRING output format']
31
+ end
32
+ end