Sha256: 6391032d45a6b071d693fb38b6762af9dc7c71b5f42854f0579398ee5d5c4ff0

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'city_watch/util/alerts'
require 'city_watch/util/rules'
require 'city_watch/util/flags'

module Watchman
	
	def data
		{}
	end
	
	module ClassMethods
		
		def process(dat,rcv,host)
			@host = host
			@rcv_time = rcv
			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_rules(dat)
			send_alerts!
			return 0, sum || nil
		end
		
		def host
			@host || nil
		end
		
		def rcv_time
			@rcv_time || Time.now.to_i
		end
		
		def set_default(k,val)
			opts[k] = val
		end
		
		def opts
			@options ||= {}
		end
		
		def options(*args)
			if args.count > 1
				return args.map {|k| opts[k]}
			else
				return opts[args.first]
			end
			return nil
		end
		alias_method :option, :options
		
	end
	
	def self.included(base)
		base.extend(Alerts::ClassMethods)
		base.extend(Rules::ClassMethods)
		base.extend(Flags::ClassMethods)
		base.extend(ClassMethods)
		Watchmen.register(base)
	end
	
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
city-watch-0.5.4 lib/city_watch/util/watchman.rb