Parent

Rackamole::Alert::Twitt

Leverage twitter as a notification client. You can setup a private twitter account and have your moled app twitt exception/perf alerts...

Public Class Methods

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

Twitt an alert

    # File lib/rackamole/alert/twitt.rb, line 9
 9:     def self.deliver_alert( logger, options, attrs )
10:       @twitt ||= Twitt.new( logger, options[:twitter][:username], options[:twitter][:password] )
11:       @twitt.send_alert( attrs )
12:     end
new( logger, username, password ) click to toggle source

This class is used to send out moled twitter notification. This feature is enabled by setting the :twitter option on the Rack::Mole. When a moled feature comes around it will be twitted on your configured account. This allow your app to twitt about it’s status and issues. Currently there are no provisions to throttle the twitts, hence sending out twitt notifications of every moled features would not be a very good idea. Whereas sending twitts when your application bogs down or throws exception, might be more appropriate. Further work will take place to throttle these events... Creating a private twitter account and asking folks in your group to follow might be a nice alternative to email.

NOTE: This is just an alert mechanism. All moled events will be either logged or persisted in the db regardless.

Params:

username

The name on the twitter account

password

The password of your twitter account

logger

Instance of the rackamole logger

    # File lib/rackamole/alert/twitt.rb, line 31
31:     def initialize( logger, username, password )
32:       raise "You must specify your twitter account credentials" unless username or password
33:       @username = username
34:       @password = password
35:       @logger   = logger
36:     end

Public Instance Methods

send_alert( args ) click to toggle source

Send out a twitt notification based of the watched features. A short message will be blasted to your twitter account based on information reported by the mole. The twitt will be automatically truncated to 140 chars.

Params:

args

The moled info for a given feature.

    # File lib/rackamole/alert/twitt.rb, line 45
45:     def send_alert( args )
46:       twitt_msg = "#{args[:app_name]} on #{format_host(args[:host])} - #{args[:user_name]}\n#{display_feature(args)}"
47:       twitt_msg = case args[:type]
48:         when Rackamole.feature
49:           "[Feature] #{twitt_msg}"
50:         when Rackamole.perf 
51:           "[Perf] #{twitt_msg}\n#{format_time(args[:request_time])} secs"
52:         when Rackamole.fault
53:           "[Fault] #{twitt_msg}\n#{args[:fault]}"
54:       end
55:       if twitt_msg
56:         twitt_msg += " - #{args[:created_at].strftime( "%H:%M:%S")}"
57:         twitt.status( :post, truncate( twitt_msg ) ) 
58:       end
59:       twitt_msg
60:     rescue => boom
61:        logger.error "Rackamole twitt alert failed with error `#{boom}"
62:     end

Private Instance Methods

display_feature( args ) click to toggle source

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

    # File lib/rackamole/alert/twitt.rb, line 75
75:        def display_feature( args )
76:          return args[:path] unless args[:route_info]
77:          "#{args[:route_info][:controller]}##{args[:route_info][:action]}"
78:        end
format_host( host ) click to toggle source

Format host ie fred@blee.com => fred

    # File lib/rackamole/alert/twitt.rb, line 81
81:       def format_host( host )
82:         return host.gsub( /@.+/, '' ) if host =~ /@/
83:         host
84:       end
format_time( time ) click to toggle source

Format precision on request time

    # File lib/rackamole/alert/twitt.rb, line 87
87:       def format_time( time )
88:         ("%4.2f" % time).to_f
89:       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/twitt.rb, line 93
93:       def truncate(text, length = 140, truncate_string = "...")
94:         return "" if text.nil?
95:         l = length - truncate_string.size
96:         text.size > length ? (text[0...l] + truncate_string).to_s : text
97:       end
twitt() click to toggle source

Fetch twitter connection...

    # File lib/rackamole/alert/twitt.rb, line 70
70:        def twitt
71:          @twitt ||= ::Twitter::Client.new( :login => username, :password => password )
72:        end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.