lib/scout/server.rb in scout-1.1.8 vs lib/scout/server.rb in scout-2.0.4

- old
+ new

@@ -12,11 +12,12 @@ # The default URLS are used to communicate with the Scout Server. URLS = { :plan => "/clients/CLIENT_KEY/plugins.scout?version=CLIENT_VERSION", :report => "/clients/CLIENT_KEY/plugins/PLUGIN_ID/reports.scout?version=CLIENT_VERSION", :error => "/clients/CLIENT_KEY/plugins/PLUGIN_ID/errors.scout?version=CLIENT_VERSION", - :alert => "/clients/CLIENT_KEY/plugins/PLUGIN_ID/alerts.scout?version=CLIENT_VERSION" } + :alert => "/clients/CLIENT_KEY/plugins/PLUGIN_ID/alerts.scout?version=CLIENT_VERSION", + :clone => "/clients/CLIENT_KEY/clone_from?version=CLIENT_VERSION" } # # A plugin cannot take more than PLUGIN_TIMEOUT seconds to execute, # otherwise, a timeout error is generated. # @@ -94,10 +95,11 @@ debug "Compiling plugin..." begin eval(plugin[:code], TOPLEVEL_BINDING, plugin[:path] || plugin[:name]) info "Plugin compiled." rescue Exception + raise if $!.is_a? SystemExit error "Plugin would not compile: #{$!.message}" return end debug "Loading plugin..." if job = Plugin.last_defined.load( last_run, (memory || Hash.new), @@ -111,10 +113,11 @@ end rescue Timeout::Error error "Plugin took too long to run." return rescue Exception + raise if $!.is_a? SystemExit error "Plugin failed to run: #{$!.backtrace}" end info "Plugin completed its run." # handle single report or array of reports @@ -149,10 +152,11 @@ begin Object.send(:remove_const, Plugin.last_defined.to_s.split("::").first) Plugin.last_defined = nil info "Plugin Removed." rescue + raise if $!.is_a? SystemExit error "Unable to remove plugin." end end info "Plugin #{plugin[:name]} processing complete." end @@ -221,15 +225,32 @@ "Unable to log error on server.", :error => data.merge(:plugin_id => plugin_id) info "Error sent." end + def clone_client(new_name, success_output) + url = urlify(:clone) + debug "Sending clone request to #{url}..." + post( url, + "Unable to send clone request to server.", + "client[name]" => new_name ) do |response| + case server_reply = response.body + when /\AError:/i + fatal "Clone error." + abort server_reply + else + info "Client cloned." + puts success_output.gsub(/\bCLIENT_KEY\b/, server_reply.strip) + end + end + end + private def urlify(url_name, options = Hash.new) return unless @server - options.merge!(:client_version => Scout::VERSION) + options.merge!(:client_version => Scout::VERSION::STRING) URI.join( @server, URLS[url_name]. gsub(/\bCLIENT_KEY\b/, @client_key). gsub(/\b[A-Z_]+\b/) { |k| options[k.downcase.to_sym] || k } ) end @@ -276,9 +297,10 @@ end rescue Timeout::Error fatal "Request timed out." exit rescue Exception + raise if $!.is_a? SystemExit fatal "An HTTP error occurred: #{$!.message}" exit end def no_warnings