Sha256: 4d40915248760f7663b39b7d74c00c18d29b381a3bbd61c6e6d3610e35a4af0b

Contents?: true

Size: 1.1 KB

Versions: 21

Compression:

Stored size: 1.1 KB

Contents

require 'mail'
require 'socket'

module OpenSSL
  module SSL
    remove_const :VERIFY_PEER
  end
end
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

module Alerts
	
	def send_alert(message,dat=nil)
		CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time})
		if eml = CityWatch.config[:alert_by_email]
			mail = Mail.new {
				from "citywatch@#{Socket.gethostbyname(Socket.gethostname).first}"
				to eml
				subject "CityWatch: ALERT #{message}"
				body "Alert data: #{data.inspect}"
			}
			mail.delivery_method :sendmail
			mail.deliver!
		end
	end

	def alerts
		@alerts ||= []
		if block_given?
			@alerts.each do |a|
				yield a
			end
		else
			@alerts
		end
		nil
	end

	def get_alerts(host=host,num=5)
		CityWatch.redis.zrevrange("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1).map {|dat| Yajl::Parser.new(:symbolize_keys => true).parse(dat) }
	end

	def send_alerts!(*args)
		get_alerts.map do |alert|
			puts "Alert: #{alert.inspect}" if CityWatch.debug?
		end
	end
	
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
city-watch-0.7.9 lib/city_watch/util/alerts.rb
city-watch-0.7.8 lib/city_watch/util/alerts.rb
city-watch-0.7.7 lib/city_watch/util/alerts.rb
city-watch-0.7.6 lib/city_watch/util/alerts.rb
city-watch-0.7.5 lib/city_watch/util/alerts.rb
city-watch-0.7.4 lib/city_watch/util/alerts.rb
city-watch-0.7.3 lib/city_watch/util/alerts.rb
city-watch-0.7.2 lib/city_watch/util/alerts.rb
city-watch-0.7.1 lib/city_watch/util/alerts.rb
city-watch-0.7.0 lib/city_watch/util/alerts.rb
city-watch-0.6.9 lib/city_watch/util/alerts.rb
city-watch-0.6.8 lib/city_watch/util/alerts.rb
city-watch-0.6.7 lib/city_watch/util/alerts.rb
city-watch-0.6.6 lib/city_watch/util/alerts.rb
city-watch-0.6.5 lib/city_watch/util/alerts.rb
city-watch-0.6.4 lib/city_watch/util/alerts.rb
city-watch-0.6.3 lib/city_watch/util/alerts.rb
city-watch-0.6.2 lib/city_watch/util/alerts.rb
city-watch-0.6.1 lib/city_watch/util/alerts.rb
city-watch-0.6.0 lib/city_watch/util/alerts.rb