Parent

Rackamole::Alert::Growl

Leverages growl as a notification client.

Public Class Methods

deliver_alert( logger, options, attrs ) click to toggle source

Twitt an alert

    # File lib/rackamole/alert/growl.rb, line 8
 8:     def self.deliver_alert( logger, options, attrs )
 9:       @growl ||= Growl.new( logger, options[:growl][:to] )
10:       @growl.send_alert( attrs )
11:     end
new( logger, recipients ) click to toggle source

Send a growl notification for particular moled feature. A growl will be sent based on the configuration :growl defined on Rack::Mole component This option must specify the to ip addresses and the conditions that will trigger a growl defined by alert_on for the type of moled features to track via email. The notification will be sent via UDP, so you will need to make sure it is properly configured for your domain.

NOTE: This is just a notification mechanism. All moled event will be either logged or persisted in the db regardless.

Parameters:

options

Mole options. The :growl key must contains :to addresses.

args

The gathered information from the mole.

    # File lib/rackamole/alert/growl.rb, line 26
26:     def initialize( logger, recipients )
27:       raise "You must specify your growl :to addresses" unless recipients
28:       @recipients = recipients
29:       @logger   = logger
30:       @growls   = {}
31:     end

Public Instance Methods

send_alert( args ) click to toggle source

Send out a growl notification based of the watched features. A short message will be blasted to your growl client based on information reported by the mole.

Params:

args

The moled info for a given feature.

    # File lib/rackamole/alert/growl.rb, line 37
37:     def send_alert( args )
38:       recipients.each do |recipient|
39:         buff  = "#{args[:user_name]}:#{display_feature(args)}"
40:         title = "#{args[:app_name]}(#{args[:environment]})"
41:         case args[:type]
42:           when Rackamole.feature
43:             type     = "Feature"
44:             title    = "[Feat] #{title}"
45:             msg      = buff
46:             priority = 2
47:             sticky   = false
48:           when Rackamole.perf
49:             type     = "Perf" 
50:             title    = "[Perf] #{title}"
51:             msg      = "#{buff} #{format_time(args[:request_time])} secs"
52:             priority = 2
53:             sticky   = true
54:           when Rackamole.fault
55:             type     = "Fault"
56:             title    = "[Fault] #{title}"
57:             msg      = "#{buff}\n#{args[:fault]}"
58:             priority = 2
59:             sticky   = true            
60:         end
61:         growl( recipient ).notify( type, title, msg, priority, sticky )
62:       end
63:     rescue => boom
64:        logger.error "Rackamole growl alert failed with error `#{boom}"
65:     end

Private Instance Methods

display_feature( args ) click to toggle source

Display controller/action or path depending on frmk used...

    # File lib/rackamole/alert/growl.rb, line 81
81:        def display_feature( args )
82:          return args[:path] unless args[:route_info]
83:          "#{args[:route_info][:controller]}##{args[:route_info][:action]}"
84:        end
format_host( host ) click to toggle source

Format host ie fred@blee.com => fred

    # File lib/rackamole/alert/growl.rb, line 87
87:       def format_host( host )
88:         return host.gsub( /@.+/, '' ) if host =~ /@/
89:         host
90:       end
format_time( time ) click to toggle source

Format precision on request time

    # File lib/rackamole/alert/growl.rb, line 93
93:       def format_time( time )
94:         ("%4.2f" % time).to_f
95:       end
growl( recipient ) click to toggle source

Fetch or create growl application...

    # File lib/rackamole/alert/growl.rb, line 73
73:        def growl( recipient )
74:          return @growls[recipient[:ip]] if @growls[recipient[:ip]]
75:          growl = ::Growl.new( recipient[:ip], 'rackamole', %(Feature Perf Fault), nil, recipient[:password] )
76:          @growls[recipient[:ip]] = growl
77:          growl
78:        end
truncate(text, length = 140, truncate_string = "...") click to toggle source

Truncate for twitt max size BOZO !! This will be hosed if not 1.9 for multibyte chars

     # File lib/rackamole/alert/growl.rb, line 99
 99:       def truncate(text, length = 140, truncate_string = "...")
100:         return "" if text.nil?
101:         l = length - truncate_string.size
102:         text.size > length ? (text[0...l] + truncate_string).to_s : text
103:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.