lib/deputy.rb in deputy-0.1.37 vs lib/deputy.rb in deputy-0.1.38
- old
+ new
@@ -1,8 +1,9 @@
require 'yaml'
require 'open-uri'
require 'cgi'
+require "socket"
def eval_and_fetch_constants(x)
old = Module.constants.map{|c| c.to_s}
eval(x)
new = (Module.constants.map{|c| c.to_s} - old)
@@ -115,20 +116,16 @@
raise e
end
def self.send_report(group, value)
raise "separate #{group} with a ." unless group.split('.',2).size == 2
- get "/notify?group=#{CGI.escape group}&value=#{CGI.escape value.to_s}"
+ get "/notify?group=#{CGI.escape group}&value=#{CGI.escape value.to_s}&hostname=#{Socket.gethostname}"
end
def self.get(path, options = {})
-
url = "#{sheriff_url}#{path}"
- url = url.sub(%r{//(.*?):(.*?)@}, '//')
- auth = [$1, $2].compact
- options[:http_basic_authentication] = auth if auth.size == 2
- options['REMOTE_HOST'] = hostname
+ options[:http_basic_authentication] = extract_auth_from_url!(url)
Timeout.timeout(config['timeout']||10) do
open(url, options).read
end
rescue => e
@@ -146,14 +143,10 @@
return YAML.load(File.read(file)) if File.exist?(file)
end
raise "No deputy.yml found in /etc or #{home}"
end
- def self.hostname
- File.read('/etc/hostname') rescue "hostname_unknown"
- end
-
# stolen from klarlack -- http://github.com/schoefmax/klarlack
# to get an reliable timeout that wont fail on other platforms
# or if sytem_timer is missing
Timeout = begin
# Try to use the SystemTimer gem instead of Ruby's timeout library
@@ -170,7 +163,13 @@
end
rescue LoadError => e
$stderr.puts "Could not load SystemTimer gem, falling back to Ruby's slower/unsafe timeout library: #{e.message}"
require 'timeout'
Timeout
+ end
+
+ def self.extract_auth_from_url!(url)
+ url.sub!(%r{//(.*?):(.*?)@}, '//')
+ auth = [$1, $2].compact
+ auth.empty? ? nil : auth
end
end
\ No newline at end of file