class Statsman::ReporterJob
Public Instance Methods
perform(config, data_type, key, value, meta)
click to toggle source
# File lib/statsman/reporter_job.rb, line 10 def perform(config, data_type, key, value, meta) Statsman::Agent.log("ReporterJob sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}") body = { data_type: data_type, key: key, value: value, meta: meta, time: Time.now.to_i # Add timestamp to body to avoid replay attacks } url = "#{config.url}/stats" resp = HTTParty.post( "#{config.url}/stats", headers: { "authorization" => request_auth_header(config, "/stats", body)}, body: body ) Statsman::Agent.log("sent data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}, response: [#{resp.code}] #{resp.headers.inspect}") rescue => e Statsman::Agent.log("Exception sending data_type: #{data_type}, key: #{key}, value: #{value}, meta: #{meta}: #{e.message}\n#{e.backtrace.join("\n")}") end
request_auth_header(config, path, body)
click to toggle source
# File lib/statsman/reporter_job.rb, line 35 def request_auth_header(config, path, body) signature = request_signature(config, path, body) "#{config.api_key}:#{signature}" end
request_signature(config, path, body)
click to toggle source
# File lib/statsman/reporter_job.rb, line 40 def request_signature(config, path, body) str = HTTParty::HashConversions.to_params(body) to_sign = path + str OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), config.api_secret, to_sign) end