deputy 0.1.37 → 0.1.38

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.37
1
+ 0.1.38
data/deputy.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{deputy}
8
- s.version = "0.1.37"
8
+ s.version = "0.1.38"
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 = %q{2010-07-15}
12
+ s.date = %q{2010-07-16}
13
13
  s.default_executable = %q{deputy}
14
14
  s.email = %q{mirko@dawanda.com}
15
15
  s.executables = ["deputy"]
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.homepage = %q{http://github.com/dawanda/deputy}
27
27
  s.rdoc_options = ["--charset=UTF-8"]
28
28
  s.require_paths = ["lib"]
29
- s.rubygems_version = %q{1.3.7}
29
+ s.rubygems_version = %q{1.3.6}
30
30
  s.summary = %q{Report to the sheriff}
31
31
  s.test_files = [
32
32
  "spec/deputy_spec.rb",
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
38
  s.specification_version = 3
39
39
 
40
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
41
  else
42
42
  end
43
43
  else
data/lib/deputy.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'open-uri'
3
3
  require 'cgi'
4
+ require "socket"
4
5
 
5
6
  def eval_and_fetch_constants(x)
6
7
  old = Module.constants.map{|c| c.to_s}
@@ -117,16 +118,12 @@ module Deputy
117
118
 
118
119
  def self.send_report(group, value)
119
120
  raise "separate #{group} with a ." unless group.split('.',2).size == 2
120
- get "/notify?group=#{CGI.escape group}&value=#{CGI.escape value.to_s}"
121
+ get "/notify?group=#{CGI.escape group}&value=#{CGI.escape value.to_s}&hostname=#{Socket.gethostname}"
121
122
  end
122
123
 
123
124
  def self.get(path, options = {})
124
-
125
125
  url = "#{sheriff_url}#{path}"
126
- url = url.sub(%r{//(.*?):(.*?)@}, '//')
127
- auth = [$1, $2].compact
128
- options[:http_basic_authentication] = auth if auth.size == 2
129
- options['REMOTE_HOST'] = hostname
126
+ options[:http_basic_authentication] = extract_auth_from_url!(url)
130
127
 
131
128
  Timeout.timeout(config['timeout']||10) do
132
129
  open(url, options).read
@@ -148,10 +145,6 @@ module Deputy
148
145
  raise "No deputy.yml found in /etc or #{home}"
149
146
  end
150
147
 
151
- def self.hostname
152
- File.read('/etc/hostname') rescue "hostname_unknown"
153
- end
154
-
155
148
  # stolen from klarlack -- http://github.com/schoefmax/klarlack
156
149
  # to get an reliable timeout that wont fail on other platforms
157
150
  # or if sytem_timer is missing
@@ -173,4 +166,10 @@ module Deputy
173
166
  require 'timeout'
174
167
  Timeout
175
168
  end
169
+
170
+ def self.extract_auth_from_url!(url)
171
+ url.sub!(%r{//(.*?):(.*?)@}, '//')
172
+ auth = [$1, $2].compact
173
+ auth.empty? ? nil : auth
174
+ end
176
175
  end
data/spec/deputy_spec.rb CHANGED
@@ -32,6 +32,10 @@ class OptionsPlugin < Scout::Plugin
32
32
  end
33
33
 
34
34
  describe Deputy do
35
+ before do
36
+ Socket.stub!(:gethostname).and_return 'my_host'
37
+ end
38
+
35
39
  it "has a VERSION" do
36
40
  Deputy::VERSION.should =~ /^\d+\.\d+\.\d+$/
37
41
  end
@@ -143,7 +147,7 @@ describe Deputy do
143
147
  $notify = 0
144
148
  Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
145
149
  FakeWeb.register_uri(:get, "http://sheri.ff/plugins.rb", :body => klass('C', :code => '$notify=1'))
146
- FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=1", :body => 'OK')
150
+ FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Deputies.finished&value=1&hostname=my_host", :body => 'OK')
147
151
  Deputy.run_plugins
148
152
  $notify.should == 1
149
153
  end
@@ -152,14 +156,36 @@ describe Deputy do
152
156
  describe :send_report do
153
157
  it "sends a report" do
154
158
  Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
155
- FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yyy&value=123", :body => 'OK')
159
+ FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yyy&value=123&hostname=my_host", :body => 'OK')
156
160
  Deputy.send_report('Xxx.yyy', '123').should == 'OK'
157
161
  end
158
162
 
159
163
  it "escapes metric names" do
160
164
  Deputy.stub!(:sheriff_url).and_return 'http://sheri.ff'
161
- FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123", :body => 'OK')
165
+ FakeWeb.register_uri(:get, "http://sheri.ff/notify?group=Xxx.yy%3Fy&value=123&hostname=my_host", :body => 'OK')
162
166
  Deputy.send_report('Xxx.yy?y', '123').should == 'OK'
163
167
  end
164
168
  end
169
+
170
+ describe :extract_auth_from_url! do
171
+ it "finds auth" do
172
+ Deputy.extract_auth_from_url!('http://x:y@foo').should == ['x','y']
173
+ end
174
+
175
+ it "removes auth from url" do
176
+ url = 'http://x:y@foo'
177
+ Deputy.extract_auth_from_url!(url)
178
+ url.should == 'http://foo'
179
+ end
180
+
181
+ it "returns nil when auth was not found" do
182
+ Deputy.extract_auth_from_url!('http://foo').should == nil
183
+ end
184
+
185
+ it "does not alter url when auth was not found" do
186
+ url = 'http://foo'
187
+ Deputy.extract_auth_from_url!(url)
188
+ url.should == 'http://foo'
189
+ end
190
+ end
165
191
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deputy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 81
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 37
10
- version: 0.1.37
8
+ - 38
9
+ version: 0.1.38
11
10
  platform: ruby
12
11
  authors:
13
12
  - Michael Grosser
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-07-15 00:00:00 +02:00
17
+ date: 2010-07-16 00:00:00 +02:00
19
18
  default_executable: deputy
20
19
  dependencies: []
21
20
 
@@ -46,27 +45,23 @@ rdoc_options:
46
45
  require_paths:
47
46
  - lib
48
47
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ">="
52
50
  - !ruby/object:Gem::Version
53
- hash: 3
54
51
  segments:
55
52
  - 0
56
53
  version: "0"
57
54
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
55
  requirements:
60
56
  - - ">="
61
57
  - !ruby/object:Gem::Version
62
- hash: 3
63
58
  segments:
64
59
  - 0
65
60
  version: "0"
66
61
  requirements: []
67
62
 
68
63
  rubyforge_project:
69
- rubygems_version: 1.3.7
64
+ rubygems_version: 1.3.6
70
65
  signing_key:
71
66
  specification_version: 3
72
67
  summary: Report to the sheriff