deputy 0.1.57 → 0.1.58
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/deputy.gemspec +2 -2
- data/lib/deputy.rb +15 -0
- data/spec/deputy_spec.rb +22 -16
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.58
|
data/deputy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "deputy"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.58"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = "2012-11-
|
12
|
+
s.date = "2012-11-21"
|
13
13
|
s.email = "mirko@dawanda.com"
|
14
14
|
s.executables = ["deputy"]
|
15
15
|
s.files = [
|
data/lib/deputy.rb
CHANGED
@@ -146,6 +146,7 @@ module Deputy
|
|
146
146
|
url = "http://#{url}" unless url =~ %r{://}
|
147
147
|
options[:http_basic_authentication] = extract_auth_from_url!(url)
|
148
148
|
url = add_host_to_url(url, options.delete(:host))
|
149
|
+
url = add_ip_to_url(url)
|
149
150
|
puts "getting #{url} with options: #{options.inspect}" if options[:verbose]
|
150
151
|
|
151
152
|
http_options = {}
|
@@ -228,6 +229,20 @@ module Deputy
|
|
228
229
|
|
229
230
|
def self.add_host_to_url(url, host=nil)
|
230
231
|
query = "hostname=#{host || Socket.gethostname}#{'&forced_host=true' if host}"
|
232
|
+
add_query_to_url(url, query)
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
def self.add_ip_to_url(url, ip=nil)
|
237
|
+
query = "ip=#{ip ||real_ip}"
|
238
|
+
add_query_to_url(url, query)
|
239
|
+
end
|
240
|
+
|
241
|
+
def self.real_ip
|
242
|
+
%x(host $(hostname))[/\d+.\d+.\d+.\d+/]
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.add_query_to_url(url, query)
|
231
246
|
separator = (url.include?('?') ? "&" : "?")
|
232
247
|
url + separator + query
|
233
248
|
end
|
data/spec/deputy_spec.rb
CHANGED
@@ -32,9 +32,15 @@ class OptionsPlugin < Scout::Plugin
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe Deputy do
|
35
|
+
def append_ip(url)
|
36
|
+
Deputy.add_query_to_url(url, "ip=10.10.10.10")
|
37
|
+
end
|
38
|
+
|
39
|
+
|
35
40
|
before do
|
36
41
|
srand(Time.now.to_f * 100000) # fixes rand in klass() not being random
|
37
42
|
Socket.stub!(:gethostname).and_return 'my_host'
|
43
|
+
Deputy.stub!(:real_ip).and_return '10.10.10.10'
|
38
44
|
end
|
39
45
|
|
40
46
|
it "has a VERSION" do
|
@@ -165,16 +171,16 @@ describe Deputy do
|
|
165
171
|
|
166
172
|
it "executes all plugins" do
|
167
173
|
$notify = 0
|
168
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb?hostname=my_host", :body => klass('C', :code => '$notify=1'))
|
169
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host", :body => 'OK')
|
174
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/plugins.rb?hostname=my_host"), :body => klass('C', :code => '$notify=1'))
|
175
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host"), :body => 'OK')
|
170
176
|
Deputy.run_plugins
|
171
177
|
$notify.should == 1
|
172
178
|
end
|
173
179
|
|
174
180
|
it "does not execute not-running plugins" do
|
175
181
|
$notify = 0
|
176
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb?hostname=my_host", :body => klass('C', :code => '$notify=1', :interval => 9999999))
|
177
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host", :body => 'OK')
|
182
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/plugins.rb?hostname=my_host"), :body => klass('C', :code => '$notify=1', :interval => 9999999))
|
183
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host"), :body => 'OK')
|
178
184
|
Deputy.run_plugins
|
179
185
|
$notify.should == 0
|
180
186
|
end
|
@@ -190,17 +196,17 @@ describe Deputy do
|
|
190
196
|
end
|
191
197
|
|
192
198
|
it "does not sleeps no_wait given" do
|
193
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb?hostname=my_host", :body => '')
|
194
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host", :body => 'OK')
|
199
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/plugins.rb?hostname=my_host"), :body => '')
|
200
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.finished&value=OK&hostname=my_host"), :body => 'OK')
|
195
201
|
Deputy.stub!(:send_report)
|
196
202
|
Deputy.should_not_receive(:sleep)
|
197
203
|
Deputy.run_plugins
|
198
204
|
end
|
199
205
|
|
200
206
|
it "fails with nice backtrace" do
|
201
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb?hostname=my_host", :body => klass('FooBar', :code => 'raise'))
|
202
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=Error&hostname=my_host", :body => 'OK')
|
203
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.Error&value=FooBar&hostname=my_host", :body => 'OK')
|
207
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/plugins.rb?hostname=my_host"), :body => klass('FooBar', :code => 'raise'))
|
208
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.finished&value=Error&hostname=my_host"), :body => 'OK')
|
209
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.Error&value=FooBar&hostname=my_host"), :body => 'OK')
|
204
210
|
lambda{
|
205
211
|
Deputy.run_plugins
|
206
212
|
}.should raise_error('FooBar')
|
@@ -208,9 +214,9 @@ describe Deputy do
|
|
208
214
|
|
209
215
|
it "continues to run plugins when one fails" do
|
210
216
|
$notify = 0
|
211
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb?hostname=my_host", :body => klass('FooBar', :code => 'raise') + klass('C', :code => '$notify = 1'))
|
212
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=Error&hostname=my_host", :body => 'OK')
|
213
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.Error&value=&hostname=my_host", :body => 'OK')
|
217
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/plugins.rb?hostname=my_host"), :body => klass('FooBar', :code => 'raise') + klass('C', :code => '$notify = 1'))
|
218
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.finished&value=Error&hostname=my_host"), :body => 'OK')
|
219
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Deputies.Error&value=&hostname=my_host"), :body => 'OK')
|
214
220
|
lambda{
|
215
221
|
Deputy.run_plugins
|
216
222
|
}.should raise_error
|
@@ -224,17 +230,17 @@ describe Deputy do
|
|
224
230
|
end
|
225
231
|
|
226
232
|
it "sends a report" do
|
227
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yyy&value=123&hostname=my_host", :body => 'OK')
|
233
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Xxx.yyy&value=123&hostname=my_host"), :body => 'OK')
|
228
234
|
Deputy.send_report('Xxx.yyy', '123').should == 'OK'
|
229
235
|
end
|
230
236
|
|
231
237
|
it "escapes metric names" do
|
232
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=my_host", :body => 'OK')
|
238
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=my_host"), :body => 'OK')
|
233
239
|
Deputy.send_report('Xxx.yy?y', '123').should == 'OK'
|
234
240
|
end
|
235
241
|
|
236
242
|
it "overrides host, if specified in options" do
|
237
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=general&forced_host=true", :body => 'OK')
|
243
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=general&forced_host=true"), :body => 'OK')
|
238
244
|
Deputy.send_report('Xxx.yy?y', '123', {:host => 'general'}).should == 'OK'
|
239
245
|
end
|
240
246
|
|
@@ -245,7 +251,7 @@ describe Deputy do
|
|
245
251
|
|
246
252
|
it "does not reraise if silent_on_errors configured" do
|
247
253
|
Deputy.config['silent_on_errors'] = true
|
248
|
-
FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=general&forced_host=true", :body => 'ERROR', :status => ["500", "Internal Server Error"])
|
254
|
+
FakeWeb.register_uri(:get, append_ip("http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=general&forced_host=true"), :body => 'ERROR', :status => ["500", "Internal Server Error"])
|
249
255
|
Deputy.send_report('Xxx.yy?y', '123', {:host => 'general'}).should == nil
|
250
256
|
end
|
251
257
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deputy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 111
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 58
|
10
|
+
version: 0.1.58
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-11-
|
18
|
+
date: 2012-11-21 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description:
|