Module: Alerts
- Defined in:
- lib/city_watch/util/alerts.rb
Instance Method Summary collapse
- #alerts ⇒ Object
- #get_alerts(host = host, num = 5) ⇒ Object
- #send_alert(message, dat = nil) ⇒ Object
- #send_alerts!(*args) ⇒ Object
Instance Method Details
#alerts ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/city_watch/util/alerts.rb', line 27 def alerts @alerts ||= [] if block_given? @alerts.each do |a| yield a end else @alerts end nil end |
#get_alerts(host = host, num = 5) ⇒ Object
39 40 41 |
# File 'lib/city_watch/util/alerts.rb', line 39 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 |
#send_alert(message, dat = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/city_watch/util/alerts.rb', line 13 def send_alert(,dat=nil) CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({: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 #{}" body "Alert data: #{data.inspect}" } mail.delivery_method :sendmail mail.deliver! end end |