class DockerApi
Public Class Methods
new(uri = nil)
click to toggle source
# File lib/sensu-plugins-docker/client_helpers.rb, line 5 def initialize(uri = nil) @client = nil @docker_uri = uri || ENV['DOCKER_URL'] || ENV['DOCKER_HOST'] || '/var/run/docker.sock' if @docker_uri.sub!(%r{^(unix://)?/}, '') @docker_uri = 'unix:///' + @docker_uri @client = NetX::HTTPUnix.new(@docker_uri) else protocol = %r{^(https?|tcp)://}.match(@docker_uri) || 'http://' @docker_uri.sub!(protocol.to_s, '') split_host = @docker_uri.split ':' @client = if split_host.length == 2 NetX::HTTPUnix.new("#{protocol}#{split_host[0]}", split_host[1]) else NetX::HTTPUnix.new("#{protocol}#{@docker_uri}", 2375) end end @client.start end
Public Instance Methods
call(path, halt = true, limit = 10)
click to toggle source
# File lib/sensu-plugins-docker/client_helpers.rb, line 28 def call(path, halt = true, limit = 10) raise ArgumentError, "HTTP redirect too deep. Last url called : #{path}" if limit.zero? if %r{^unix:///} =~ @docker_uri request = Net::HTTP::Get.new path.to_s else uri = URI("#{@docker_uri}#{path}") request = Net::HTTP::Get.new uri.request_uri end response = @client.request(request) case response when Net::HTTPSuccess then response when Net::HTTPRedirection then call(response['location'], true, limit - 1) else return response.error! unless halt == false return response end end
parse(path, halt = true, limit = 10)
click to toggle source
# File lib/sensu-plugins-docker/client_helpers.rb, line 46 def parse(path, halt = true, limit = 10) parsed = parse_json(call(path, halt, limit)) parsed end
uri()
click to toggle source
# File lib/sensu-plugins-docker/client_helpers.rb, line 24 def uri @docker_uri end