lib/sensu/client/http_socket.rb
# This method is called to process HTTP requests
This method is called to process HTTP requests
This method is called to process HTTP requests
def process_http_request
        @logger.debug("http socket processing", {
          :http_request_method => @http_request_method,
          :http_request_uri => @http_request_uri
        })
        @response = EM::DelegatedHttpResponse.new(self)
        @response.content_type "application/json"
        endpoint = @endpoints[@http_request_uri]
        if endpoint
          @logger.debug("http socket endpoint found", {
            :http_request_uri => @http_request_uri,
            :accepted_methods => endpoint["methods"].keys
          })
          method_name = @http_request_method.upcase
          method_handler = endpoint["methods"][method_name]
          if method_handler
            @logger.debug("http socket executing handler", {
              :method_name => method_name,
              :http_request_uri => @http_request_uri
            })
            method_handler.call
          else
            @logger.debug("http socket method is not allowed for endpoint", {
              :method_name => method_name,
              :http_request_uri => @http_request_uri
            })
            send_response(405, "Method Not Allowed", {
              :response => "Valid methods for this endpoint: #{endpoint['methods'].keys}"
            })
          end
        else
          @logger.warn("http socket unknown endpoint requested", :http_request_uri => @http_request_uri)
          help_response = {
            :endpoints => {}
          }
          @endpoints.each do |key, value|
            help_response[:endpoints][key] ||= Hash.new
            help_response[:endpoints][key]["help"] = value["help"]
            help_response[:endpoints][key]["methods"] = value["methods"].keys
          end
          send_response(404, "Not Found", help_response)
        end
      end
def process_http_request @logger . debug ( "http socket processing" , { :http_request_method => @http_request_method , :http_request_uri => @http_request_uri } ) @response = EM :: DelegatedHttpResponse . new ( self ) @response . content_type "application/json" endpoint = @endpoints [ @http_request_uri ] if endpoint @logger . debug ( "http socket endpoint found" , { :http_request_uri => @http_request_uri , :accepted_methods => endpoint [ "methods" ] . keys } ) method_name = @http_request_method . upcase method_handler = endpoint [ "methods" ] [ method_name ] if method_handler @logger . debug ( "http socket executing handler" , { :method_name => method_name , :http_request_uri => @http_request_uri } ) method_handler . call else @logger . debug ( "http socket method is not allowed for endpoint" , { :method_name => method_name , :http_request_uri => @http_request_uri } ) send_response ( 405 , "Method Not Allowed" , { :response => "Valid methods for this endpoint: #{endpoint['methods'].keys}" } ) end else @logger . warn ( "http socket unknown endpoint requested" , :http_request_uri => @http_request_uri ) help_response = { :endpoints => { } } @endpoints . each do | key , value | help_response [ :endpoints ] [ key ] ||= Hash . new help_response [ :endpoints ] [ key ] [ "help" ] = value [ "help" ] help_response [ :endpoints ] [ key ] [ "methods" ] = value [ "methods" ] . keys end send_response ( 404 , "Not Found" , help_response ) end end
This method is called to process HTTP requests
This method is called to process HTTP requests