Module: Watchman::ClassMethods

Defined in:
lib/city_watch/util/watchman.rb

Instance Method Summary collapse

Instance Method Details

#add_post_processor(meth = nil, &block) ⇒ Object



62
63
64
65
# File 'lib/city_watch/util/watchman.rb', line 62

def add_post_processor(meth=nil,&block)
	@post_processors ||= []
	@post_processors << (block_given? ? block : meth)
end

#get_watchman_optionsObject



67
68
69
# File 'lib/city_watch/util/watchman.rb', line 67

def get_watchman_options
	CityWatch.config[:watchmen] && CityWatch.config[:watchmen].is_a?(Hash) && CityWatch.config[:watchmen][self.name.to_sym] && CityWatch.config[:watchmen][self.name.to_sym].is_a?(Hash) ? CityWatch.config[:watchmen][self.name.to_sym] : {}
end

#hostObject



30
31
32
# File 'lib/city_watch/util/watchman.rb', line 30

def host
	@host || nil
end

#options(*args) ⇒ Object Also known as: option



46
47
48
49
50
51
52
53
# File 'lib/city_watch/util/watchman.rb', line 46

def options(*args)
	if args.count > 1
		return args.map {|k| opts[k] }
	else
		return opts[args.first]
	end
	return nil
end

#optsObject



42
43
44
# File 'lib/city_watch/util/watchman.rb', line 42

def opts
	@options ||= get_watchman_options
end

#process(dat, rcv, host) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/city_watch/util/watchman.rb', line 16

def process(dat,rcv,host)
	return unless dat
	@host = host
	@rcv_time = rcv
	CityWatch.redis.sadd "#{CityWatch.config[:prefix]}::#{host}::watchmen", self.name
	CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}", rcv_time, Yajl::Encoder.encode(dat.merge({:received_at => dat[:received_at]}))
	if dat[:summary]
		sum = dat[:summary].is_a?(Array) ? dat[:summary].inject({}) {|acc,k| acc[k.to_sym] = dat[k.to_sym]; acc} : dat[:summary]
		CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::summary", rcv_time, Yajl::Encoder.encode(sum)
	end
	run_post_processors!(dat,rcv,host)
	return 0, sum || nil
end

#rcv_timeObject



34
35
36
# File 'lib/city_watch/util/watchman.rb', line 34

def rcv_time
	@rcv_time || Time.now.to_i
end

#run_post_processors!(dat, rcv, host) ⇒ Object



56
57
58
59
60
# File 'lib/city_watch/util/watchman.rb', line 56

def run_post_processors!(dat,rcv,host)
	@post_processors.each do |proc|
		proc.call(dat,rcv,host)
	end if @post_processors
end

#set_default(k, val) ⇒ Object



38
39
40
# File 'lib/city_watch/util/watchman.rb', line 38

def set_default(k,val)
	opts[k] = val
end