wavefront-sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +20 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +1157 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +58 -0
  8. data/LICENSE.txt +27 -0
  9. data/README.md +103 -0
  10. data/Rakefile +18 -0
  11. data/lib/wavefront-sdk/alert.rb +195 -0
  12. data/lib/wavefront-sdk/base.rb +251 -0
  13. data/lib/wavefront-sdk/cloudintegration.rb +88 -0
  14. data/lib/wavefront-sdk/credentials.rb +79 -0
  15. data/lib/wavefront-sdk/dashboard.rb +157 -0
  16. data/lib/wavefront-sdk/event.rb +173 -0
  17. data/lib/wavefront-sdk/exception.rb +39 -0
  18. data/lib/wavefront-sdk/externallink.rb +77 -0
  19. data/lib/wavefront-sdk/maintenancewindow.rb +75 -0
  20. data/lib/wavefront-sdk/message.rb +36 -0
  21. data/lib/wavefront-sdk/metric.rb +52 -0
  22. data/lib/wavefront-sdk/mixins.rb +60 -0
  23. data/lib/wavefront-sdk/proxy.rb +95 -0
  24. data/lib/wavefront-sdk/query.rb +96 -0
  25. data/lib/wavefront-sdk/response.rb +56 -0
  26. data/lib/wavefront-sdk/savedsearch.rb +88 -0
  27. data/lib/wavefront-sdk/search.rb +58 -0
  28. data/lib/wavefront-sdk/source.rb +131 -0
  29. data/lib/wavefront-sdk/user.rb +108 -0
  30. data/lib/wavefront-sdk/validators.rb +395 -0
  31. data/lib/wavefront-sdk/version.rb +1 -0
  32. data/lib/wavefront-sdk/webhook.rb +73 -0
  33. data/lib/wavefront-sdk/write.rb +225 -0
  34. data/pkg/wavefront-client-3.5.0.gem +0 -0
  35. data/spec/.rubocop.yml +14 -0
  36. data/spec/spec_helper.rb +157 -0
  37. data/spec/wavefront-sdk/alert_spec.rb +83 -0
  38. data/spec/wavefront-sdk/base_spec.rb +88 -0
  39. data/spec/wavefront-sdk/cloudintegration_spec.rb +54 -0
  40. data/spec/wavefront-sdk/credentials_spec.rb +55 -0
  41. data/spec/wavefront-sdk/dashboard_spec.rb +74 -0
  42. data/spec/wavefront-sdk/event_spec.rb +83 -0
  43. data/spec/wavefront-sdk/externallink_spec.rb +65 -0
  44. data/spec/wavefront-sdk/maintenancewindow_spec.rb +48 -0
  45. data/spec/wavefront-sdk/message_spec.rb +19 -0
  46. data/spec/wavefront-sdk/metric_spec.rb +21 -0
  47. data/spec/wavefront-sdk/mixins_spec.rb +27 -0
  48. data/spec/wavefront-sdk/proxy_spec.rb +41 -0
  49. data/spec/wavefront-sdk/query_spec.rb +51 -0
  50. data/spec/wavefront-sdk/resources/test.conf +10 -0
  51. data/spec/wavefront-sdk/response_spec.rb +47 -0
  52. data/spec/wavefront-sdk/savedsearch_spec.rb +54 -0
  53. data/spec/wavefront-sdk/search_spec.rb +47 -0
  54. data/spec/wavefront-sdk/source_spec.rb +48 -0
  55. data/spec/wavefront-sdk/user_spec.rb +56 -0
  56. data/spec/wavefront-sdk/validators_spec.rb +238 -0
  57. data/spec/wavefront-sdk/webhook_spec.rb +50 -0
  58. data/spec/wavefront-sdk/write_spec.rb +167 -0
  59. data/wavefront-sdk.gemspec +34 -0
  60. metadata +269 -0
@@ -0,0 +1,88 @@
1
+ require_relative './base'
2
+
3
+ module Wavefront
4
+ #
5
+ # View and manage Cloud Integrations. These are identified by
6
+ # a UUID.
7
+ #
8
+ class CloudIntegration < Wavefront::Base
9
+
10
+ # GET /api/v2/cloudintegration
11
+ # Get all cloud integrations for a customer
12
+ #
13
+ # @param offset [Int] integration at which the list begins
14
+ # @param limit [Int] the number of integration to return
15
+ # @return [Hash]
16
+ #
17
+ def list(offset = 0, limit = 100)
18
+ api_get('', { offset: offset, limit: limit })
19
+ end
20
+
21
+ # POST /api/v2/cloudintegration
22
+ # Create a cloud integration. Refer to the Swagger API docs for
23
+ # valid keys.
24
+ #
25
+ # @param body [Hash] description of integration
26
+ # @return [Hash]
27
+ #
28
+ def create(body)
29
+ raise ArgumentError unless body.is_a?(Hash)
30
+ api_post('', body, 'application/json')
31
+ end
32
+
33
+ # DELETE /api/v2/cloudintegration/{id}
34
+ # Delete a specific cloud integration
35
+ #
36
+ # Deleting an active integration moves it to 'trash', from where
37
+ # it can be restored with an #undelete operation. Deleting an
38
+ # integration in 'trash' removes it for ever.
39
+ #
40
+ # @param id [String] ID of the integration
41
+ # @return [Hash]
42
+ #
43
+ def delete(id)
44
+ wf_cloudintegration_id?(id)
45
+ api_delete(id)
46
+ end
47
+
48
+ # GET /api/v2/cloudintegration/{id}
49
+ # Get a specific cloud integration
50
+ #
51
+ # @param id [String] ID of the integration
52
+ # @return [Hash]
53
+ #
54
+ def describe(id)
55
+ wf_cloudintegration_id?(id)
56
+ api_get(id)
57
+ end
58
+
59
+ # PUT /api/v2/cloudintegration/{id}
60
+ # Update a specific cloud integration
61
+ #
62
+ # @param id [String] ID of the integration
63
+ # @param body [Hash] description of integration
64
+ #
65
+ def update(id, body)
66
+ wf_cloudintegration_id?(id)
67
+ raise ArgumentError unless body.is_a?(Hash)
68
+ api_put(id, body)
69
+ end
70
+
71
+ # POST /api/v2/cloudintegration/{id}/undelete
72
+ # Undelete a specific cloud integration
73
+ #
74
+ # @param id [String] ID of the integration
75
+ # @return [Hash]
76
+ #
77
+ def undelete(id)
78
+ wf_cloudintegration_id?(id)
79
+ api_post([id, 'undelete'].uri_concat)
80
+ end
81
+ end
82
+
83
+ # A standard response.
84
+ #
85
+ class Response
86
+ class CloudIntegration < Base; end
87
+ end
88
+ end
@@ -0,0 +1,79 @@
1
+ require 'pathname'
2
+ require 'inifile'
3
+
4
+ module Wavefront
5
+
6
+ # Helper methods to get Wavefront credentials
7
+ #
8
+ class Credentials
9
+ attr_reader :opts, :config, :creds, :proxy
10
+
11
+ # Gives you an object of credentials and options for speaking to
12
+ # Wavefront. It will look in the following places:
13
+ #
14
+ # ~/.wavefront
15
+ # /etc/wavefront/credentials
16
+ # WAVEFRONT_ENDPOINT and WAVEFRONT_TOKEN environment variables
17
+ #
18
+ # @param options [Hash] keys may be 'file', which
19
+ # specifies a config file which will be loaded and parsed. If
20
+ # no file is supplied, those listed above will be used.;
21
+ # and/or 'profile' which select a profile section from 'file'
22
+ #
23
+ def initialize(options = {})
24
+ raw = load_from_file(options)
25
+ raw = env_override(raw)
26
+ populate(raw)
27
+ end
28
+
29
+ def env_override(raw)
30
+ { endpoint: 'WAVEFRONT_ENDPOINT',
31
+ token: 'WAVEFRONT_TOKEN',
32
+ proxy: 'WAVEFRONT_PROXY'
33
+ }.each { |k, v| raw[k] = ENV[v] if ENV[v] }
34
+ raw
35
+ end
36
+
37
+ def populate(raw)
38
+ @config = raw
39
+ @creds = raw.select { |k, _v| [:endpoint, :token].include?(k) }
40
+ @proxy = raw.select { |k, _v| [:proxy, :port].include?(k) }
41
+ end
42
+
43
+ def load_from_file(opts)
44
+ ret = {}
45
+
46
+ profile = opts[:profile] || 'default'
47
+
48
+ c_file = if opts.key?(:file)
49
+ Array(Pathname.new(opts[:file]))
50
+ else
51
+ [Pathname.new('/etc/wavefront/credentials'),
52
+ Pathname.new(ENV['HOME']) + '.wavefront']
53
+ end
54
+
55
+ c_file.each do |f|
56
+ next unless f.exist?
57
+ ret = load_profile(f, profile)
58
+ ret[:file] = f
59
+ end
60
+
61
+ ret
62
+ end
63
+
64
+ # Load in configuration (optionally) given section of an
65
+ # ini-style configuration file not there, we don't consider that
66
+ # an error.
67
+ #
68
+ # @param file [Pathname] the file to read
69
+ # @param profile [String] the section in the config to read
70
+ # @return [Hash] options loaded from file. Each key becomes a
71
+ # symbol
72
+ #
73
+ def load_profile(file, profile = 'default')
74
+ IniFile.load(file)[profile].each_with_object({}) do |(k, v), memo|
75
+ memo[k.to_sym] = v
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,157 @@
1
+ require_relative './base'
2
+
3
+ module Wavefront
4
+ #
5
+ # View and manage dashboards.
6
+ #
7
+ class Dashboard < Wavefront::Base
8
+
9
+ # GET /api/v2/dashboard
10
+ # Get all dashboards for a customer.
11
+ #
12
+ # @param offset [Int] dashboard at which the list begins
13
+ # @param limit [Int] the number of dashboard to return
14
+ # @return [Hash]
15
+ #
16
+ def list(offset = 0, limit = 100)
17
+ api_get('', { offset: offset, limit: limit })
18
+ end
19
+
20
+ # POST /api/v2/dashboard
21
+ # Create a specific dashboard.
22
+ # Refer to the Swagger API docs for valid keys.
23
+ #
24
+ # @param body [Hash] description of dashboard
25
+ # @return [Hash]
26
+ #
27
+ def create(body)
28
+ raise ArgumentError unless body.is_a?(Hash)
29
+ api_post('', body, 'application/json')
30
+ end
31
+
32
+ # DELETE /api/v2/dashboard/{id}
33
+ # Delete a specific dashboard.
34
+ # Deleting an active dashboard moves it to 'trash', from where it can
35
+ # be restored with an #undelete operation. Deleting an dashboard in
36
+ # 'trash' removes it for ever.
37
+ #
38
+ # @param id [String] ID of the dashboard
39
+ # @return [Hash]
40
+ #
41
+ def delete(id)
42
+ wf_dashboard_id?(id)
43
+ api_delete(id)
44
+ end
45
+
46
+ # GET /api/v2/dashboard/{id}
47
+ # Get a specific dashboard / Get a specific historical version of a
48
+ # specific dashboard.
49
+ #
50
+ # @param id [String] ID of the dashboard
51
+ # @param version [Integer] version of dashboard
52
+ # @return [Hash]
53
+ #
54
+ def describe(id, version = nil)
55
+ wf_dashboard_id?(id)
56
+ wf_version?(version) if version
57
+ fragments = [id]
58
+ fragments += ['history', version] if version
59
+ api_get(fragments.uri_concat)
60
+ end
61
+
62
+ # PUT /api/v2/dashboard/{id}
63
+ # Update a specific dashboard.
64
+ #
65
+ # Refer to the Swagger API docs for valid keys.
66
+ #
67
+ # @param body [Hash] description of dashboard
68
+ # @return [Hash]
69
+ #
70
+ def update(id, body)
71
+ wf_dashboard_id?(id)
72
+ raise ArgumentError unless body.is_a?(Hash)
73
+ api_put(id, body)
74
+ end
75
+
76
+ # GET /api/v2/dashboard/{id}/history
77
+ # Get the version history of an dashboard.
78
+ #
79
+ # @param id [String] ID of the dashboard
80
+ # @return [Hash]
81
+ #
82
+ def history(id)
83
+ wf_dashboard_id?(id)
84
+ api_get([id, 'history'].uri_concat)
85
+ end
86
+
87
+ # GET /api/v2/dashboard/{id}/tag
88
+ # Get all tags associated with a specific dashboard.
89
+ #
90
+ # @param id [String] ID of the dashboard
91
+ # @returns [Hash] object describing the dashboard with status and
92
+ # response keys
93
+ #
94
+ def tags(id)
95
+ wf_dashboard_id?(id)
96
+ api_get([id, 'tag'].uri_concat)
97
+ end
98
+
99
+ # POST /api/v2/dashboard/{id}/tag
100
+ # Set all tags associated with a specific dashboard.
101
+ #
102
+ # @param id [String] ID of the dashboard
103
+ # @param tags [Array] list of tags to set.
104
+ # @returns [Hash] object describing the dashboard with status and
105
+ # response keys
106
+ #
107
+ def tag_set(id, tags)
108
+ wf_dashboard_id?(id)
109
+ tags = Array(tags)
110
+ tags.each { |t| wf_string?(t) }
111
+ api_post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
112
+ end
113
+
114
+ # DELETE /api/v2/dashboard/{id}/tag/{tagValue}
115
+ # Remove a tag from a specific dashboard.
116
+ #
117
+ # @param id [String] ID of the dashboard
118
+ # @param tag [String] tag to delete
119
+ # @returns [Hash] object with 'status' key and empty 'repsonse'
120
+ #
121
+ def tag_delete(id, tag)
122
+ wf_dashboard_id?(id)
123
+ wf_string?(tag)
124
+ api_delete([id, 'tag', tag].uri_concat)
125
+ end
126
+
127
+ # PUT /api/v2/dashboard/{id}/tag/{tagValue}
128
+ # Add a tag to a specific dashboard.
129
+ #
130
+ # @param id [String] ID of the dashboard
131
+ # @param tag [String] tag to set.
132
+ # @returns [Hash] object with 'status' key and empty 'repsonse'
133
+ #
134
+ def tag_add(id, tag)
135
+ wf_dashboard_id?(id)
136
+ wf_string?(tag)
137
+ api_put([id, 'tag', tag].uri_concat)
138
+ end
139
+
140
+ # POST /api/v2/dashboard/{id}/undelete
141
+ # Move an dashboard from 'trash' back into active service.
142
+ #
143
+ # @param id [String] ID of the dashboard
144
+ # @return [Hash]
145
+ #
146
+ def undelete(id)
147
+ wf_dashboard_id?(id)
148
+ api_post([id, 'undelete'].uri_concat)
149
+ end
150
+ end
151
+
152
+ # A standard response.
153
+ #
154
+ class Response
155
+ class Dashboard < Base; end
156
+ end
157
+ end
@@ -0,0 +1,173 @@
1
+ require_relative './base'
2
+
3
+ module Wavefront
4
+ #
5
+ # View and manage events. Events are identified by their millisecond
6
+ # epoch timestamp.
7
+ #
8
+ class Event < Wavefront::Base
9
+ @update_keys = [:startTime, :endTime, :name, :annotations]
10
+
11
+ # GET /api/v2/event
12
+ # List all the events for a customer within a time range.
13
+ #
14
+ # @param from [Time, Integer] start of time range. The API
15
+ # requires this time as epoch milliseconds, but we will also
16
+ # accept it as a Ruby Time object.
17
+ # @param to [Time, Integer] end ot time range. Can be epoch
18
+ # millisecods or a Ruby time. If not supplied, defaults to the
19
+ # current time.
20
+ # @cursor [String] I think this is the 
21
+ # must start with a timestamp.
22
+ # @limit [Integer] the number of events to return
23
+ # @return [Hash]
24
+ #
25
+ def list(from = nil, to = nil, limit = 100, cursor = nil)
26
+ raise ArgumentError unless from && to
27
+ from = parse_time(from, true)
28
+ to = parse_time(to, true)
29
+ wf_ms_ts?(from)
30
+ wf_ms_ts?(to)
31
+ wf_event_id?(cursor) if cursor
32
+ raise ArgumentError unless limit.is_a?(Integer)
33
+
34
+ api_get('', { earliestStartTimeEpochMillis: from,
35
+ latestStartTimeEpochMillis: to,
36
+ cursor: cursor,
37
+ limit: limit }.select { |_k, v| v })
38
+ end
39
+
40
+ # POST /api/v2/event
41
+ # Create a specific event.
42
+ #
43
+ # We used to validate keys and provide helpers for time fields.
44
+ # Now ensuring a valid hash is entirely left up to the user.
45
+ # Refer to the Swagger docs for more information.
46
+ #
47
+ # @param body [Hash] description of event
48
+ # @return [Hash]
49
+ #
50
+ def create(body)
51
+ raise ArgumentError unless body.is_a?(Hash)
52
+ api_post('', body, 'application/json')
53
+ end
54
+
55
+ # DELETE /api/v2/event/{id}
56
+ # Delete a specific event.
57
+ #
58
+ # @param id [String] ID of the alert
59
+ # @return [Hash]
60
+ #
61
+ def delete(id)
62
+ wf_event_id?(id)
63
+ api_delete(id)
64
+ end
65
+
66
+ # GET /api/v2/event/{id}
67
+ # Get a specific event / Get a specific historical version of a
68
+ # specific event.
69
+ #
70
+ # @param id [String] ID of the event
71
+ # @param version [Integer] version of event
72
+ # @return [Hash]
73
+ #
74
+ def describe(id, version = nil)
75
+ wf_event_id?(id)
76
+ wf_version?(version) if version
77
+ fragments = [id]
78
+ fragments += ['history', version] if version
79
+ api_get(fragments.uri_concat)
80
+ end
81
+
82
+ # PUT /api/v2/event/{id}
83
+ # Update a specific event
84
+ #
85
+ # This method helps you update one or more properties of an event.
86
+ #
87
+ # @param id [String] a Wavefront Event ID
88
+ # @param body [Hash] description of event.
89
+ # @param modify [Bool] if this is true, then the existing event
90
+ # object will be fetched and merged with the user-supplied body.
91
+ # The resulting object will be passed to the API. If this is
92
+ # false, the body will be passed through unmodified.
93
+ # @return [Hash]
94
+ #
95
+ def update(id, body, modify = true)
96
+ wf_event_id?(id)
97
+ raise ArgumentError unless body.is_a?(Hash)
98
+
99
+ return api_put(id, body, 'application/json') unless modify
100
+
101
+ api_put(id, hash_for_update(describe(id), body), 'application/json')
102
+ end
103
+
104
+ # POST /api/v2/event/{id}/close
105
+ # Close a specific event.
106
+ #
107
+ # @param id [String] the ID of the event
108
+ #
109
+ def close(id)
110
+ wf_event_id?(id)
111
+ api_post([id, 'close'].uri_concat)
112
+ end
113
+
114
+ # GET /api/v2/event/{id}/tag
115
+ # Get all tags associated with a specific event
116
+ #
117
+ # @param id [String] ID of the event
118
+ # @returns [Hash] object describing the event with status and
119
+ # response keys
120
+ #
121
+ def tags(id)
122
+ wf_event_id?(id)
123
+ api_get([id, 'tag'].uri_concat)
124
+ end
125
+
126
+ # POST /api/v2/event/{id}/tag
127
+ # Set all tags associated with a specific event.
128
+ #
129
+ # @param id [String] ID of the event
130
+ # @param tags [Array] list of tags to set.
131
+ # @returns [Hash] object describing the event with status and
132
+ # response keys
133
+ #
134
+ def tag_set(id, tags)
135
+ wf_event_id?(id)
136
+ tags = Array(tags)
137
+ tags.each { |t| wf_string?(t) }
138
+ api_post([id, 'tag'].uri_concat, tags, 'application/json')
139
+ end
140
+
141
+ # DELETE /api/v2/event/{id}/tag/{tagValue}
142
+ # Remove a tag from a specific event.
143
+ #
144
+ # @param id [String] ID of the event
145
+ # @param tag [String] tag to delete
146
+ # @returns [Hash] object with 'status' key and empty 'repsonse'
147
+ #
148
+ def tag_delete(id, tag)
149
+ wf_event_id?(id)
150
+ wf_string?(tag)
151
+ api_delete([id, 'tag', tag].uri_concat)
152
+ end
153
+
154
+ # PUT /api/v2/event/{id}/tag/{tagValue}
155
+ # Add a tag to a specific event.
156
+ #
157
+ # @param id [String] ID of the event
158
+ # @param tag [String] tag to set.
159
+ # @returns [Hash] object with 'status' key and empty 'repsonse'
160
+ #
161
+ def tag_add(id, tag)
162
+ wf_event_id?(id)
163
+ wf_string?(tag)
164
+ api_put([id, 'tag', tag].uri_concat)
165
+ end
166
+ end
167
+
168
+ # A standard response.
169
+ #
170
+ class Response
171
+ class Event < Base; end
172
+ end
173
+ end