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,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ WINDOW = '1493324005091'.freeze
6
+ WINDOW_BODY = {
7
+ reason: 'testing SDK',
8
+ title: 'test window',
9
+ start: Time.now.to_i,
10
+ end: Time.now.to_i + 600,
11
+ tags: %w(testtag1 testtag2),
12
+ hostTags: %w(hosttag1 hosttag2)
13
+ }.freeze
14
+
15
+ # Unit tests for MaintenanceWindow class
16
+ #
17
+ class WavefrontMaintenanceWindowTest < WavefrontTestBase
18
+ def test_list
19
+ should_work(:list, 10, '?offset=10&limit=100')
20
+ should_work(:list, [20, 30], '?offset=20&limit=30')
21
+ end
22
+
23
+ def test_describe
24
+ should_work(:describe, WINDOW, WINDOW)
25
+ should_be_invalid(:describe, 'abcdefg')
26
+ assert_raises(ArgumentError) { wf.describe }
27
+ end
28
+
29
+ def test_create
30
+ should_work(:create, WINDOW_BODY, '', :post,
31
+ JSON_POST_HEADERS, WINDOW_BODY.to_json)
32
+ assert_raises(ArgumentError) { wf.create }
33
+ assert_raises(ArgumentError) { wf.create('test') }
34
+ end
35
+
36
+ def test_delete
37
+ should_work(:delete, WINDOW, WINDOW, :delete)
38
+ should_be_invalid(:delete, 'abcdefg')
39
+ assert_raises(ArgumentError) { wf.delete }
40
+ end
41
+
42
+ def test_update
43
+ should_work(:update, [WINDOW, WINDOW_BODY], WINDOW, :put,
44
+ JSON_POST_HEADERS, WINDOW_BODY.to_json)
45
+ should_be_invalid(:update, ['abcde', WINDOW_BODY])
46
+ assert_raises(ArgumentError) { wf.update }
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ MESSAGE = 'message_id'.freeze # don't know what these look like yet
6
+
7
+ # Unit tests for Message class
8
+ #
9
+ class WavefrontMessageTest < WavefrontTestBase
10
+ def test_list
11
+ should_work(:list, 10, '?offset=10&limit=100&unreadOnly=true')
12
+ should_work(:list, [12, 34, false], '?offset=12&limit=34&unreadOnly=false')
13
+ end
14
+
15
+ def test_read
16
+ should_work(:read, MESSAGE, "#{MESSAGE}/read", :post, POST_HEADERS)
17
+ should_be_invalid(:read, 'bad id')
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ # Unit tests for Metric class
6
+ #
7
+ class WavefrontMetricTest < WavefrontTestBase
8
+ def api_base
9
+ 'chart/metric'
10
+ end
11
+
12
+ def test_detail
13
+ should_work(:detail, 'metric.1', 'detail?m=metric.1')
14
+ should_work(:detail, ['metric.1', %w(host1 host2)],
15
+ 'detail?m=metric.1&h=host1&h=host2')
16
+ should_work(:detail, ['metric.1', %w(host1 host2), 'abc'],
17
+ 'detail?m=metric.1&h=host1&h=host2&c=abc')
18
+ assert_raises(ArgumentError) { wf.detail }
19
+ assert_raises(ArgumentError) { wf.detail('m1', 'm2') }
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+ require_relative '../../lib/wavefront-sdk/mixins'
5
+
6
+ # Test SDK mixins
7
+ #
8
+ class WavefrontMixinsTest < MiniTest::Test
9
+ include Wavefront::Mixins
10
+
11
+ def test_parse_time
12
+ base_t = Time.now.to_i
13
+ assert_equal parse_time(1_469_711_187), 1_469_711_187
14
+ assert_equal parse_time('2016-07-28 14:25:36 +0100'), 1_469_712_336
15
+ assert_equal parse_time('2016-07-28'), 1_469_664_000
16
+ assert_instance_of Fixnum, parse_time(Time.now)
17
+ assert_instance_of Fixnum, parse_time(Time.now, true)
18
+ assert parse_time(Time.now) >= base_t
19
+ assert parse_time(Time.now, true) >= base_t * 1000
20
+ assert parse_time(Time.now, true) < base_t * 1001
21
+ assert_instance_of Fixnum, parse_time(DateTime.now)
22
+ assert_instance_of Fixnum, parse_time(DateTime.now, true)
23
+ assert_raises(Wavefront::Exception::InvalidTimestamp) do
24
+ parse_time('nonsense')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ PROXY = 'fd248f53-378e-4fbe-bbd3-efabace8d724'.freeze
6
+
7
+ # Unit tests for proxy class
8
+ #
9
+ class WavefrontProxyTest < WavefrontTestBase
10
+ def test_list
11
+ should_work(:list, 10, '?offset=10&limit=100')
12
+ end
13
+
14
+ def test_describe
15
+ should_work(:describe, PROXY, PROXY)
16
+ should_be_invalid(:describe)
17
+ assert_raises(ArgumentError) { wf.describe }
18
+ end
19
+
20
+ def test_delete
21
+ should_work(:delete, PROXY, PROXY, :delete)
22
+ should_be_invalid('delete')
23
+ end
24
+
25
+ def test_rename
26
+ should_work(:rename, [PROXY, 'newname'],
27
+ [PROXY, { name: 'newname' }.to_json], :put,
28
+ JSON_POST_HEADERS)
29
+ assert_raises(ArgumentError) { wf.rename }
30
+ assert_raises(ArgumentError) { wf.rename('abc123') }
31
+ assert_raises(Wavefront::Exception::InvalidProxyId) do
32
+ wf.rename('abc', 'name')
33
+ end
34
+ end
35
+
36
+ def test_undelete
37
+ should_work(:undelete, PROXY, ["#{PROXY}/undelete", nil],
38
+ :post, POST_HEADERS)
39
+ should_be_invalid('undelete')
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'date'
4
+ require_relative '../spec_helper'
5
+
6
+ SERIES = 'test.metric'.freeze
7
+ T = Time.now.freeze
8
+ T_MS = T.to_datetime.strftime('%Q').freeze
9
+ TE = (T + 10).freeze
10
+ TE_MS = TE.to_datetime.strftime('%Q')
11
+ Q = "ts(\"#{SERIES}\")".freeze
12
+ QE = URI.encode(Q).freeze
13
+
14
+ # Unit tests for Query class
15
+ #
16
+ class WavefrontQueryTest < WavefrontTestBase
17
+ def api_base
18
+ 'chart'
19
+ end
20
+
21
+ def test_query
22
+ should_work(:query, [Q, 'd', T_MS], "api?q=#{QE}&g=d&s=#{T_MS}")
23
+ should_work(:query, [Q, 'h', T], "api?q=#{QE}&g=h&s=#{T_MS}")
24
+ should_work(:query, [Q, 'm', T, TE],
25
+ "api?q=#{QE}&g=m&s=#{T_MS}&e=#{TE_MS}")
26
+ should_work(:query, [Q, 'h', T, nil, {}], "api?q=#{Q}&g=h&s=#{T_MS}")
27
+ should_work(:query, [Q, 'h', T, nil, { strict: true,
28
+ summarization: 'MAX' }],
29
+ "api?q=#{QE}&g=h&s=#{T_MS}&strict=true&summarization=MAX")
30
+
31
+ assert_raises(ArgumentError) { wf.query }
32
+
33
+ assert_raises(Wavefront::Exception::InvalidGranularity) do
34
+ wf.query('ts("m")', 'x')
35
+ end
36
+
37
+ assert_raises(Wavefront::Exception::InvalidTimestamp) do
38
+ wf.query('ts("m")', 'd')
39
+ end
40
+ end
41
+
42
+ def test_raw
43
+ should_work(:raw, [SERIES, 'src'], "raw?metric=#{SERIES}&source=src")
44
+ should_work(:raw, [SERIES, 'src', T],
45
+ "raw?metric=#{SERIES}&source=src&startTime=#{T_MS}")
46
+ should_work(:raw, [SERIES, 'src', T, TE],
47
+ "raw?metric=#{SERIES}&source=src&startTime=#{T_MS}" \
48
+ "&endTime=#{TE_MS}")
49
+ assert_raises(ArgumentError) { wf.raw }
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ [default]
2
+ token = 12345678-abcd-1234-abcd-123456789012
3
+ endpoint = default.wavefront.com
4
+ proxy = wavefront.localnet
5
+ sourceformat = raw
6
+
7
+ [other]
8
+ token = abcdefab-0123-abcd-0123-abcdefabcdef
9
+ endpoint = other.wavefront.com
10
+ proxy = otherwf.localnet
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require_relative '../spec_helper'
4
+ require_relative '../../lib/wavefront-sdk/exception'
5
+ require_relative '../../lib/wavefront-sdk/response'
6
+
7
+ WF_JSON = '{"status":{"result":"OK","message":"","code":200},' \
8
+ '"response":{"items":[{"name":"test agent"}],"offset":0,' \
9
+ '"limit":100,"totalItems":3,"moreItems":false}}'
10
+
11
+ # Unit tests for Response class
12
+
13
+ class WavefrontResponseTest < MiniTest::Test
14
+
15
+ def test_initialize_good_data
16
+ wf = Wavefront::Response::Base.new(WF_JSON, 200)
17
+ assert_instance_of(Wavefront::Response::Base, wf)
18
+ assert_respond_to(wf, :status)
19
+ assert_respond_to(wf, :response)
20
+ assert_respond_to(wf.response, :items)
21
+ refute_respond_to(wf, :to_a)
22
+ [:code, :message, :result].each { |m| assert_respond_to(wf.status, m) }
23
+ assert_equal(wf.status.code, 200)
24
+ assert_instance_of(Array, wf.response.items)
25
+ end
26
+
27
+ def test_initialize_bad_data
28
+ assert_raises(Wavefront::Exception::InvalidResponse) do
29
+ Wavefront::Response::Base.new('merp', 200)
30
+ end
31
+
32
+ assert_raises(Wavefront::Exception::InvalidResponse) do
33
+ Wavefront::Response::Base.new(
34
+ '{"status":{"result":"OK","message":"","code":200}', 200)
35
+ end
36
+
37
+ assert_raises(Wavefront::Exception::InvalidResponse) do
38
+ Wavefront::Response::Base.new(
39
+ '{"status":{"result":"OK","message":"","code":200}', 200)
40
+ end
41
+
42
+ assert_raises(Wavefront::Exception::InvalidResponse) do
43
+ Wavefront::Response::Base.new(
44
+ '{"response":{"items":[{"name":"test agent"}],"offset":0 }', 200)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ SAVED_SEARCH = 'e2hLH2FR'.freeze
6
+ SAVED_SEARCH_BODY = {
7
+ query: {
8
+ foo: '{"searchTerms":[{"type":"freetext","value":"foo"}]}'
9
+ },
10
+ entityType: 'DASHBOARD'
11
+ }.freeze
12
+
13
+ # Unit tests for SavedSearch class
14
+ #
15
+ class WavefrontSavedSearchTest < WavefrontTestBase
16
+ def test_list
17
+ should_work(:list, [], '?offset=0&limit=100')
18
+ should_work(:list, 10, '?offset=10&limit=100')
19
+ should_work(:list, [20, 250], '?offset=20&limit=250')
20
+ end
21
+
22
+ def test_create
23
+ should_work(:create, SAVED_SEARCH_BODY, '', :post, JSON_POST_HEADERS,
24
+ SAVED_SEARCH_BODY.to_json)
25
+ assert_raises(ArgumentError) { wf.create }
26
+ assert_raises(ArgumentError) { wf.create('test') }
27
+ end
28
+
29
+ def test_delete
30
+ should_work(:delete, SAVED_SEARCH, SAVED_SEARCH, :delete)
31
+ should_be_invalid(:delete)
32
+ end
33
+
34
+ def test_describe
35
+ should_work(:describe, SAVED_SEARCH, SAVED_SEARCH)
36
+ should_be_invalid(:describe)
37
+ end
38
+
39
+ def test_update
40
+ should_work(:update, [SAVED_SEARCH, SAVED_SEARCH_BODY],
41
+ SAVED_SEARCH, :put, JSON_POST_HEADERS,
42
+ SAVED_SEARCH_BODY.to_json)
43
+ should_be_invalid(:update, ['abcde', SAVED_SEARCH_BODY])
44
+ assert_raises(ArgumentError) { wf.update }
45
+ end
46
+
47
+ def test_entity
48
+ %w(ALERT EVENT MAINTENANCE_WINDOW DASHBOARD SOURCE AGENT).each do |e|
49
+ should_work(:entity, e, "type/#{e}?offset=0&limit=100")
50
+ should_work(:entity, [e, 20], "type/#{e}?offset=20&limit=100")
51
+ should_work(:entity, [e, 20, 50], "type/#{e}?offset=20&limit=50")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ SEARCH_BODY = {
6
+ limit: 10,
7
+ offset: 0,
8
+ query: [{ key: 'name',
9
+ value: 'Wavefront',
10
+ matchingMethod: 'CONTAINS' }],
11
+ sort: { field: 'string',
12
+ ascending: true }
13
+ }.freeze
14
+
15
+ # Unit tests for Search class
16
+ #
17
+ class WavefrontSearchTest < WavefrontTestBase
18
+ def test_search
19
+ should_work(:search, ['agent', SEARCH_BODY], 'agent', :post,
20
+ JSON_POST_HEADERS, SEARCH_BODY.to_json)
21
+ should_work(:search, ['agent', SEARCH_BODY, true], 'agent/deleted',
22
+ :post, JSON_POST_HEADERS, SEARCH_BODY.to_json)
23
+ assert_raises(ArgumentError) { wf.search }
24
+ assert_raises(ArgumentError) { wf.search('ALERT', 'junk') }
25
+ end
26
+
27
+ def test_facet_search
28
+ should_work(:facet_search, ['agent', SEARCH_BODY],
29
+ 'agent/facets', :post, JSON_POST_HEADERS,
30
+ SEARCH_BODY.to_json)
31
+
32
+ should_work(:facet_search, ['agent', SEARCH_BODY, true],
33
+ 'agent/deleted/facets', :post, JSON_POST_HEADERS,
34
+ SEARCH_BODY.to_json)
35
+
36
+ should_work(:facet_search, ['agent', SEARCH_BODY, false, 'Tags'],
37
+ 'agent/Tags', :post, JSON_POST_HEADERS,
38
+ SEARCH_BODY.to_json)
39
+
40
+ should_work(:facet_search, ['agent', SEARCH_BODY, true, 'Tags'],
41
+ 'agent/deleted/Tags', :post, JSON_POST_HEADERS,
42
+ SEARCH_BODY.to_json)
43
+
44
+ assert_raises(ArgumentError) { wf.facet_search }
45
+ assert_raises(ArgumentError) { wf.facet_search('ALERT', 'junk') }
46
+ end
47
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ SOURCE = '74a247a9-f67c-43ad-911f-fabafa9dc2f3joyent'
6
+ SOURCE_BODY = {
7
+ sourceName: 'source.name',
8
+ tags: {
9
+ sourceTag1: true
10
+ },
11
+ description: 'Source Description'
12
+ }.freeze
13
+
14
+ # Unit tests for Source class
15
+ #
16
+ class WavefrontSourceTest < WavefrontTestBase
17
+ def test_list
18
+ should_work(:list, 10, '?offset=10&limit=100')
19
+ end
20
+
21
+ def test_create
22
+ should_work(:create, SOURCE_BODY, '', :post,
23
+ JSON_POST_HEADERS, SOURCE_BODY.to_json)
24
+ assert_raises(ArgumentError) { wf.create }
25
+ assert_raises(ArgumentError) { wf.create('test') }
26
+ end
27
+
28
+ def test_describe
29
+ should_work(:describe, SOURCE, SOURCE)
30
+ assert_raises(ArgumentError) { wf.describe }
31
+ end
32
+
33
+ def test_delete
34
+ should_work(:delete, SOURCE, SOURCE, :delete)
35
+ should_be_invalid(:delete)
36
+ end
37
+
38
+ def test_update
39
+ should_work(:update, [SOURCE, SOURCE_BODY], SOURCE, :put,
40
+ JSON_POST_HEADERS, SOURCE_BODY.to_json)
41
+ should_be_invalid(:update, ['!invalid source!', SOURCE_BODY])
42
+ assert_raises(ArgumentError) { wf.update }
43
+ end
44
+
45
+ def test_tags
46
+ tag_tester(SOURCE)
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ USER = 'user@example.com'.freeze
6
+ GROUP = 'agent_management'.freeze
7
+
8
+ USER_BODY = {
9
+ emailAddress: USER,
10
+ groups: %w(browse)
11
+ }.freeze
12
+
13
+ # Unit tests for User class
14
+ #
15
+ class WavefrontUserTest < WavefrontTestBase
16
+ def test_list
17
+ should_work(:list, nil, '')
18
+ end
19
+
20
+ def test_describe
21
+ should_work(:describe, USER, USER)
22
+ should_be_invalid(:describe, 'abcdefg')
23
+ assert_raises(ArgumentError) { wf.describe }
24
+ end
25
+
26
+ def test_create
27
+ should_work(:create, [USER_BODY, true], '?sendEmail=true', :post,
28
+ JSON_POST_HEADERS, USER_BODY.to_json)
29
+ assert_raises(ArgumentError) { wf.create }
30
+ assert_raises(ArgumentError) { wf.create('test') }
31
+ end
32
+
33
+ def test_delete
34
+ should_work(:delete, USER, USER, :delete)
35
+ should_be_invalid(:delete, 'abcdefg')
36
+ assert_raises(ArgumentError) { wf.delete }
37
+ end
38
+
39
+ def test_grant
40
+ should_work(:grant, [USER, GROUP], 'user%40example.com/grant',
41
+ :post, JSON_POST_HEADERS.merge(
42
+ {'Content-Type': 'application/x-www-form-urlencoded'}),
43
+ "group=#{GROUP}")
44
+ should_be_invalid(:grant, ['abcde', GROUP])
45
+ assert_raises(ArgumentError) { wf.grant }
46
+ end
47
+
48
+ def test_revoke
49
+ should_work(:revoke, [USER, GROUP], 'user%40example.com/revoke',
50
+ :post, JSON_POST_HEADERS.merge(
51
+ {'Content-Type': 'application/x-www-form-urlencoded'}),
52
+ "group=#{GROUP}")
53
+ should_be_invalid(:revoke, ['abcde', GROUP])
54
+ assert_raises(ArgumentError) { wf.revoke }
55
+ end
56
+ end