Sha256: 98fcae433d8a6206bfe4aeba57b40ea70cc7ee82bb01bcdc1cddeb1bad8a1e1d

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

module Collector
	
	def self.send!(addr,dat)
		require "yajl"
		require 'net/http'
		require 'net/https'
		puts "Sending message to: http#{CityWatch.config[:secure] ? "s" : ""}://#{addr}/receive" if CityWatch.debug?
		uri = URI.parse("http#{CityWatch.config[:secure] ? "s" : ""}://#{addr}/receive")
		http = Net::HTTP.new(uri.host, uri.port)
		if CityWatch.config[:secure]
			http.use_ssl = true
			http.ssl_version = :SSLv3
			http.verify_mode = OpenSSL::SSL::VERIFY_PEER
			if File.exists?('/etc/ssl/certs') # Ubuntu
				http.ca_path = '/etc/ssl/certs'
			end
		end
		req = Net::HTTP::Post.new(uri.path)
		req.body = Yajl::Encoder.encode(dat)
		req["Content-Type"] = 'application/json'
		case http.request(req)
			when Net::HTTPSuccess
				puts "Successfully sent to collector." if CityWatch.debug?
			else
				raise Exception
		end
	end
	
	def self.process(data)
		rcv_time = Time.now.to_i
		host = data[:hostname]
		CityWatch.redis.sadd "#{CityWatch.config[:prefix]}::known_hosts", host
		CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::raw_stats", rcv_time, Yajl::Encoder.encode(data)
		
		summary = {}
		
		data[:watchmen].each do |watchman,dat|
			if watch_obj = Watchmen.get(watchman)
				status, sum = watch_obj.process(dat,rcv_time,host)
				summary[watchman] = sum if sum
			end
		end
		
		CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::summary", rcv_time, Yajl::Encoder.encode(summary.merge({:received_at => data[:received_at]}))
	end
	
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
city-watch-0.5.8 lib/city_watch/util/collector.rb
city-watch-0.5.7 lib/city_watch/util/collector.rb
city-watch-0.5.6 lib/city_watch/util/collector.rb
city-watch-0.5.5 lib/city_watch/util/collector.rb
city-watch-0.5.4 lib/city_watch/util/collector.rb