wavefront-client 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/wavefront/alerting.rb +38 -7
- data/lib/wavefront/client/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/wavefront/alerting_spec.rb +111 -0
- data/wavefront-client.gemspec +2 -2
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWVmNGM2NDQ4ZGQwNmMzZmIzN2JkZGJjMzllYTY2ZmE3NmY3MzkxMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTFiMTczNWUxOWMzNTk3OTljNmMyMzg1YTUyZDJhMGQxN2ZkNzI5YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDYwMzRiZTY0NjBhNjcyNzQwNWZmNDQ4NzI1OThlZmQyODhhMjYzNGExN2E2
|
10
|
+
YTY3NGNmN2RhYWIwYmVhMmQyN2ZhM2E0MTI1MDRkMjQ1NjhlYTYyYTFiOTkw
|
11
|
+
MTRlMjdiMjhkMjA3OWJhYTQ2YzU4OGUwYmQzZGU4NzczMzZiMDk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWE4ZmE0MWFlODcxZTg4NzE2YWY5MjFjYjc1MTRiM2E0YTJlZDE5NjYwY2Qx
|
14
|
+
Y2E4Nzg1MmY2ZjNjMWNmZjAzZWNiMzBhYzNjMTgyMmQxNDRhYzU3OTZkMzNj
|
15
|
+
MmMyNjAwYzQ4NDI2NTUzYTgwNjJjNTkzNTZhOWVkZjdiMzllZGM=
|
data/lib/wavefront/alerting.rb
CHANGED
@@ -27,22 +27,53 @@ module Wavefront
|
|
27
27
|
|
28
28
|
attr_reader :token
|
29
29
|
|
30
|
-
def initialize(token)
|
30
|
+
def initialize(token, debug=false)
|
31
31
|
@token = token
|
32
|
+
debug(debug)
|
32
33
|
end
|
33
34
|
|
34
35
|
def active(options={})
|
36
|
+
get_alerts('active', options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def all(options={})
|
40
|
+
get_alerts('all', options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def invalid(options={})
|
44
|
+
get_alerts('invalid', options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def snoozed(options={})
|
48
|
+
get_alerts('snoozed', options)
|
49
|
+
end
|
35
50
|
|
51
|
+
def affected_by_maintenance(options={})
|
52
|
+
get_alerts('affected_by_maintenance', options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_alerts(path, options={})
|
36
56
|
options[:host] ||= DEFAULT_HOST
|
37
57
|
options[:path] ||= DEFAULT_PATH
|
38
58
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
59
|
+
query = "t=#{@token}"
|
60
|
+
|
61
|
+
if options[:shared_tags]
|
62
|
+
tags = options[:shared_tags].class == Array ? options[:shared_tags] : [ options[:shared_tags] ] # Force an array, even if string given
|
63
|
+
query += "&#{tags.map{|t| "customerTag=#{t}"}.join('&')}"
|
64
|
+
end
|
65
|
+
|
66
|
+
if options[:private_tags]
|
67
|
+
tags = options[:private_tags].class == Array ? options[:private_tags] : [ options[:private_tags] ] # Force an array, even if string given
|
68
|
+
query += "&#{tags.map{|t| "userTag=#{t}"}.join('&')}"
|
69
|
+
end
|
44
70
|
|
45
|
-
|
71
|
+
uri = URI::HTTPS.build(
|
72
|
+
host: options[:host],
|
73
|
+
path: File.join(options[:path], path),
|
74
|
+
query: query
|
75
|
+
)
|
76
|
+
RestClient.get(uri.to_s)
|
46
77
|
end
|
47
78
|
|
48
79
|
private
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2015 Wavefront Inc.
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
require 'pathname'
|
19
|
+
|
20
|
+
describe Wavefront::Alerting do
|
21
|
+
before do
|
22
|
+
@wave = Wavefront::Alerting.new(TEST_TOKEN)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'has some defaults' do
|
26
|
+
expect(Wavefront::Alerting::DEFAULT_HOST).to_not be_nil
|
27
|
+
expect(Wavefront::Alerting::DEFAULT_HOST).to be_a_kind_of String
|
28
|
+
expect(Wavefront::Alerting::DEFAULT_PATH).to_not be_nil
|
29
|
+
expect(Wavefront::Alerting::DEFAULT_PATH).to be_a_kind_of String
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe "#initialize" do
|
34
|
+
it 'accepts a token option initialized and exposes token for reading' do
|
35
|
+
wave = Wavefront::Alerting.new(TEST_TOKEN)
|
36
|
+
expect(wave.token).to eq TEST_TOKEN
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'enables rest-client debugging if instructed to do so' do
|
40
|
+
wave = Wavefront::Alerting.new(TEST_TOKEN, true)
|
41
|
+
expect RestClient.log == 'stdout'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#get_alerts' do
|
46
|
+
it 'makes API request with default options' do
|
47
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}")}")
|
48
|
+
@wave.get_alerts('all')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'makes API request with specified host' do
|
52
|
+
host = 'madeup.wavefront.com'
|
53
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(host, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}")}")
|
54
|
+
@wave.get_alerts('all', { :host => host } )
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'makes API request with specified path' do
|
58
|
+
path = '/api/new_alerts'
|
59
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, path, "all?t=#{TEST_TOKEN}")}")
|
60
|
+
@wave.get_alerts('all', { :path => path })
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'makes API request with appended shared tags' do
|
64
|
+
tags = [ 'first', 'second' ]
|
65
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&customerTag=first&customerTag=second")}")
|
66
|
+
@wave.get_alerts('all', { :shared_tags => tags })
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'makes API request with appended private tags' do
|
70
|
+
tags = [ 'first', 'second' ]
|
71
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&userTag=first&userTag=second")}")
|
72
|
+
@wave.get_alerts('all', { :private_tags => tags })
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'makes API request with both appended private tags and shared tags' do
|
76
|
+
private_tag = 'first'
|
77
|
+
shared_tag = 'second'
|
78
|
+
expect(RestClient).to receive(:get).with("https://#{File.join(Wavefront::Alerting::DEFAULT_HOST, Wavefront::Alerting::DEFAULT_PATH, "all?t=#{TEST_TOKEN}&customerTag=second&userTag=first")}")
|
79
|
+
@wave.get_alerts('all', { :private_tags => private_tag, :shared_tags => shared_tag })
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#active' do
|
84
|
+
it 'requests all active alerts' do
|
85
|
+
expect(@wave).to receive(:get_alerts).with("active", {})
|
86
|
+
@wave.active
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#snoozed' do
|
91
|
+
it 'requests all snoozed alerts' do
|
92
|
+
expect(@wave).to receive(:get_alerts).with("snoozed", {})
|
93
|
+
@wave.snoozed
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#invalid' do
|
98
|
+
it 'requests all invalid alerts' do
|
99
|
+
expect(@wave).to receive(:get_alerts).with("invalid", {})
|
100
|
+
@wave.invalid
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#affected_by_maintenance' do
|
105
|
+
it 'requests all affected_by_maintenance alerts' do
|
106
|
+
expect(@wave).to receive(:get_alerts).with("affected_by_maintenance", {})
|
107
|
+
@wave.affected_by_maintenance
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/wavefront-client.gemspec
CHANGED
@@ -38,8 +38,8 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency "rake"
|
39
39
|
spec.add_development_dependency "rspec"
|
40
40
|
|
41
|
-
spec.add_dependency "rest-client", "
|
42
|
-
spec.add_dependency "slop", "
|
41
|
+
spec.add_dependency "rest-client", ">= 1.6.7", "<= 1.8"
|
42
|
+
spec.add_dependency "slop", ">= 3.4.7", "<= 3.6"
|
43
43
|
spec.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
|
44
44
|
|
45
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavefront-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Pointer
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-08-
|
15
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -60,30 +60,42 @@ dependencies:
|
|
60
60
|
name: rest-client
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- -
|
63
|
+
- - ! '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: 1.6.7
|
66
|
+
- - <=
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
66
69
|
type: :runtime
|
67
70
|
prerelease: false
|
68
71
|
version_requirements: !ruby/object:Gem::Requirement
|
69
72
|
requirements:
|
70
|
-
- -
|
73
|
+
- - ! '>='
|
71
74
|
- !ruby/object:Gem::Version
|
72
75
|
version: 1.6.7
|
76
|
+
- - <=
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.8'
|
73
79
|
- !ruby/object:Gem::Dependency
|
74
80
|
name: slop
|
75
81
|
requirement: !ruby/object:Gem::Requirement
|
76
82
|
requirements:
|
77
|
-
- - '
|
83
|
+
- - ! '>='
|
78
84
|
- !ruby/object:Gem::Version
|
79
85
|
version: 3.4.7
|
86
|
+
- - <=
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.6'
|
80
89
|
type: :runtime
|
81
90
|
prerelease: false
|
82
91
|
version_requirements: !ruby/object:Gem::Requirement
|
83
92
|
requirements:
|
84
|
-
- - '
|
93
|
+
- - ! '>='
|
85
94
|
- !ruby/object:Gem::Version
|
86
95
|
version: 3.4.7
|
96
|
+
- - <=
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3.6'
|
87
99
|
description: A simple abstraction for talking to wavefront in ruby
|
88
100
|
email:
|
89
101
|
- support@wavefront.com
|
@@ -113,6 +125,7 @@ files:
|
|
113
125
|
- lib/wavefront/writer.rb
|
114
126
|
- spec/example_response.json
|
115
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/wavefront/alerting_spec.rb
|
116
129
|
- spec/wavefront/client_spec.rb
|
117
130
|
- spec/wavefront/metadata_spec.rb
|
118
131
|
- spec/wavefront/mixins_spec.rb
|
@@ -146,6 +159,7 @@ summary: A simple abstraction for talking to wavefront in ruby
|
|
146
159
|
test_files:
|
147
160
|
- spec/example_response.json
|
148
161
|
- spec/spec_helper.rb
|
162
|
+
- spec/wavefront/alerting_spec.rb
|
149
163
|
- spec/wavefront/client_spec.rb
|
150
164
|
- spec/wavefront/metadata_spec.rb
|
151
165
|
- spec/wavefront/mixins_spec.rb
|