Class: MobyUtil::Stats

Inherits:
Object show all
Defined in:
lib/tdriver/util/statistics/statistics.rb

Class Method Summary collapse

Class Method Details

.report(action, message) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tdriver/util/statistics/statistics.rb', line 42

def self.report( action, message )

	return nil if defined?( $_TDRIVER_DISABLE_STATS_REPORTING )

    require 'rubygems'
    require 'uri'
    require 'socket'
    require 'net/http'
    require 'date'

	report_thread = Thread.new{

		begin
			# TODO: override possibility for the url using parameters?
			url = URI.parse('http://127.0.0.1/tdriver/stats/create/new_stat')
			
			resp, data = Net::HTTP.new( url.host, url.port ).post( 
				url.path, 
				"stat[action]=#{ action }" <<
				"&stat[host]=#{ Socket.gethostname }" <<
				"&stat[time_stamp]=#{ DateTime.now.strftime( "%Y%m%d%H%M%S" ) }" <<
				"&stat[message]=#{ message }" <<
				"&stat[user]=#{ 'NO' }" << 
				"&stat[ip]=#{ 'NO' }" << 
				"&stat[mac]=#{ 'NO' }" << 
				"&stat[platform]=#{ RUBY_PLATFORM.to_s }" <<
				"&stat[version]=#{ ENV['TDRIVER_VERSION'] }" <<
				"&commit=#{ 'Create' }",
				{ 'Content-Type' => 'application/x-www-form-urlencoded' }
			)

		rescue Exception => e

			#puts "Exception:#{e.message} trace:#{e.backtrace.inspect}"             

		end

	}

	report_thread

end