rackamole 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{aaa.txt → ...} +0 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/rackamole.rb +1 -1
- data/lib/rackamole/alert/twitt.rb +15 -4
- data/lib/rackamole/mole.rb +25 -10
- data/spec/rackamole/alert/twitt_spec.rb +22 -3
- data/spec/rackamole/mole_spec.rb +21 -12
- metadata +4 -7
- data/aa.txt +0 -10
data/{aaa.txt → ...}
RENAMED
File without changes
|
data/README.rdoc
CHANGED
@@ -21,7 +21,7 @@ interactions and leverage these findings for the next iteration of your applicat
|
|
21
21
|
* Developer: Fernand Galiana
|
22
22
|
* Blog: http://www.liquidrail.com
|
23
23
|
* Site: http://rackamole.com
|
24
|
-
* Twitter:
|
24
|
+
* Twitter: http://twitter.com/rackamole
|
25
25
|
* Forum: http://groups.google.com/group/rackamole
|
26
26
|
* Git: git://github.com/derailed/rackamole.git
|
27
27
|
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ task :default => 'spec:run'
|
|
17
17
|
PROJ.name = 'rackamole'
|
18
18
|
PROJ.authors = 'Fernand Galiana'
|
19
19
|
PROJ.email = 'fernand.galiana@gmail.com'
|
20
|
-
PROJ.url = 'http://rackamole.
|
20
|
+
PROJ.url = 'http://www.rackamole.com'
|
21
21
|
PROJ.version = Rackamole::VERSION
|
22
22
|
PROJ.spec.opts << '--color'
|
23
23
|
PROJ.ruby_opts = %w[-W0]
|
data/lib/rackamole.rb
CHANGED
@@ -35,11 +35,11 @@ module Rackamole::Alert
|
|
35
35
|
# args :: The moled info for a given feature.
|
36
36
|
#
|
37
37
|
def send_alert( args )
|
38
|
-
twitt_msg = "#{args[:app_name]}
|
38
|
+
twitt_msg = "#{args[:app_name]} on #{format_host(args[:host])} - #{args[:user_name]}\n#{display_feature(args)}"
|
39
39
|
twitt_msg = case args[:type]
|
40
|
-
when Rackamole.feature : "[Feature]
|
41
|
-
when Rackamole.perf : "[Perf]
|
42
|
-
when Rackamole.fault : "[Fault]
|
40
|
+
when Rackamole.feature : "[Feature] #{twitt_msg}"
|
41
|
+
when Rackamole.perf : "[Perf] #{twitt_msg}\n#{format_time(args[:request_time])} secs"
|
42
|
+
when Rackamole.fault : "[Fault] #{twitt_msg}\n#{args[:fault]}"
|
43
43
|
else nil
|
44
44
|
end
|
45
45
|
twitt.status( :post, truncate( twitt_msg ) ) if twitt_msg
|
@@ -63,6 +63,17 @@ module Rackamole::Alert
|
|
63
63
|
"#{args[:route_info][:controller]}##{args[:route_info][:action]}"
|
64
64
|
end
|
65
65
|
|
66
|
+
# Format host ie fred@blee.com => fred
|
67
|
+
def format_host( host )
|
68
|
+
return host.gsub( /@.+/, '' ) if host =~ /@/
|
69
|
+
host
|
70
|
+
end
|
71
|
+
|
72
|
+
# Format precision on request time
|
73
|
+
def format_time( time )
|
74
|
+
("%4.2f" % time).to_f
|
75
|
+
end
|
76
|
+
|
66
77
|
# Truncate for twitt max size
|
67
78
|
def truncate(text, length = 140, truncate_string = "...")
|
68
79
|
return "" if text.nil?
|
data/lib/rackamole/mole.rb
CHANGED
@@ -30,6 +30,7 @@ module Rack
|
|
30
30
|
# :user_key => { :session_key => :user_id, :extractor => lambda{ |id| User.find( id ).name} }
|
31
31
|
# ==
|
32
32
|
#
|
33
|
+
# :excluded_paths:: Exclude paths that you do not wish to mole by specifying an array of regular expresssions.
|
33
34
|
# :twitter_auth :: You can setup the MOle twit interesting events to a private (public if you indulge pain!) twitter account.
|
34
35
|
# Specified your twitter account information using a hash with :username and :password key
|
35
36
|
# :twitt_on :: You must configure your twitter auth and configuration using this hash. By default this option is disabled.
|
@@ -86,10 +87,11 @@ module Rack
|
|
86
87
|
# Mole default options
|
87
88
|
def default_options
|
88
89
|
{
|
90
|
+
:moleable => true,
|
89
91
|
:app_name => "Moled App",
|
92
|
+
:environment => 'test',
|
90
93
|
:excluded_paths => [/.?\.ico/, /.?\.png/],
|
91
|
-
:
|
92
|
-
:perf_threshold => 10,
|
94
|
+
:perf_threshold => 10.0,
|
93
95
|
:store => Rackamole::Store::Log.new,
|
94
96
|
:twitt_on => { :enabled => false, :features => [Rackamole.perf, Rackamole.fault] },
|
95
97
|
:mail_on => { :enabled => false, :features => [Rackamole.perf, Rackamole.fault] }
|
@@ -98,9 +100,16 @@ module Rack
|
|
98
100
|
|
99
101
|
# Validates all configured options... Throws error if invalid configuration
|
100
102
|
def validate_options
|
101
|
-
|
103
|
+
return unless options[:moleable]
|
104
|
+
|
105
|
+
%w[app_name environment perf_threshold store].each do |k|
|
102
106
|
raise "[M()le] -- Unable to locate required option key `#{k}" unless options[k.to_sym]
|
103
107
|
end
|
108
|
+
|
109
|
+
configured?( :twitter_auth, [:username, :password] )
|
110
|
+
configured?( :twitt_on , [:enabled, :features] )
|
111
|
+
configured?( :emails , [:from, :to] )
|
112
|
+
configured?( :mail_on , [:enabled, :features] )
|
104
113
|
end
|
105
114
|
|
106
115
|
# Send moled info to store and potentially send out alerts...
|
@@ -111,12 +120,12 @@ module Rack
|
|
111
120
|
options[:store].mole( attrs )
|
112
121
|
|
113
122
|
# send email alert ?
|
114
|
-
if configured?( :emails, [:from, :to] ) and alertable?(
|
123
|
+
if configured?( :emails, [:from, :to] ) and alertable?( :mail_on, attrs[:type] )
|
115
124
|
Rackamole::Alert::Emole.deliver_alert( options[:emails][:from], options[:emails][:to], attrs )
|
116
125
|
end
|
117
126
|
|
118
127
|
# send twitter alert ?
|
119
|
-
if configured?( :twitter_auth, [:username, :password] ) and alertable?(
|
128
|
+
if configured?( :twitter_auth, [:username, :password] ) and alertable?( :twitt_on, attrs[:type] )
|
120
129
|
twitt.send_alert( attrs )
|
121
130
|
end
|
122
131
|
rescue => boom
|
@@ -126,15 +135,21 @@ module Rack
|
|
126
135
|
|
127
136
|
# Check if an options is set and configured
|
128
137
|
def configured?( key, configs )
|
129
|
-
return false unless options
|
130
|
-
configs.each
|
138
|
+
return false unless options.key?(key)
|
139
|
+
configs.each do |c|
|
140
|
+
raise "Invalid value for option #{key}. Expecting a hash with symbols #{configs.join(',')}." unless options[key].respond_to? :key?
|
141
|
+
unless options[key].key?(c)
|
142
|
+
raise "Option #{key} is not properly configured missing #{c.inspect}"
|
143
|
+
end
|
144
|
+
end
|
131
145
|
true
|
132
146
|
end
|
133
147
|
|
134
148
|
# Check if feature should be send to alert clients ie email or twitter
|
135
|
-
def alertable?(
|
136
|
-
return false
|
137
|
-
|
149
|
+
def alertable?( filter, type )
|
150
|
+
return false unless configured?( filter, [:enabled,:features] )
|
151
|
+
return false unless options[filter][:enabled]
|
152
|
+
options[filter][:features].include?( type )
|
138
153
|
end
|
139
154
|
|
140
155
|
# Create or retrieve twitter client
|
@@ -36,7 +36,7 @@ describe Rackamole::Alert::Twitt do
|
|
36
36
|
# client.should_receive( :new ).exactly(1).with( 'fernand', 'blee' )
|
37
37
|
client.should_receive( :status ).once
|
38
38
|
|
39
|
-
@alert.send_alert( @args ).should == "[Feature]
|
39
|
+
@alert.send_alert( @args ).should == "[Feature] Test on Fred - Fernand\n/blee/fred"
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should twitt a perf alert correctly" do
|
@@ -48,7 +48,7 @@ describe Rackamole::Alert::Twitt do
|
|
48
48
|
@alert.should_receive( :twitt ).once.and_return( client )
|
49
49
|
client.should_receive( :status ).once
|
50
50
|
|
51
|
-
@alert.send_alert( @args ).should == "[Perf]
|
51
|
+
@alert.send_alert( @args ).should == "[Perf] Test on Fred - Fernand\n/blee/fred\n10.0 secs"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should twitt a perf alert correctly" do
|
@@ -60,9 +60,28 @@ describe Rackamole::Alert::Twitt do
|
|
60
60
|
@alert.should_receive( :twitt ).once.and_return( client )
|
61
61
|
client.should_receive( :status ).once
|
62
62
|
|
63
|
-
@alert.send_alert( @args ).should == "[Fault]
|
63
|
+
@alert.send_alert( @args ).should == "[Fault] Test on Fred - Fernand\n/blee/fred\nOh snap!"
|
64
64
|
end
|
65
|
+
end
|
65
66
|
|
67
|
+
describe "#format_time" do
|
68
|
+
it "should format a request time correctly" do
|
69
|
+
@alert.send( :format_time, 12.1234455 ).should == 12.12
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#format_host" do
|
74
|
+
it "should format a host with domain name correctly" do
|
75
|
+
@alert.send( :format_host, 'blee@acme.com' ).should == 'blee'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should deal with ip host" do
|
79
|
+
@alert.send( :format_host, '1.1.1.1' ).should == '1.1.1.1'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should deal with aliases" do
|
83
|
+
@alert.send( :format_host, 'fred' ).should == 'fred'
|
84
|
+
end
|
66
85
|
end
|
67
86
|
|
68
87
|
end
|
data/spec/rackamole/mole_spec.rb
CHANGED
@@ -113,35 +113,36 @@ describe Rack::Mole do
|
|
113
113
|
|
114
114
|
describe '#alertable?' do
|
115
115
|
before( :each ) do
|
116
|
-
@
|
117
|
-
|
116
|
+
@rack = Rack::Mole.new( nil,
|
117
|
+
:twitt_on => { :enabled => true , :features => [Rackamole.perf, Rackamole.fault] },
|
118
|
+
:mail_on => { :enabled => false, :features => [Rackamole.perf, Rackamole.fault, Rackamole.feature] } )
|
118
119
|
end
|
119
120
|
|
120
|
-
it "should
|
121
|
-
@rack.send( :alertable?,
|
121
|
+
it "should succeeed if a feature can be twitted on" do
|
122
|
+
@rack.send( :alertable?, :twitt_on, Rackamole.perf ).should == true
|
122
123
|
end
|
123
124
|
|
124
125
|
it "should fail if the type is not in range" do
|
125
|
-
@rack.send( :alertable?,
|
126
|
+
@rack.send( :alertable?, :twitt_on, 10 ).should == false
|
126
127
|
end
|
127
128
|
|
128
129
|
it "should fail if this is not an included feature" do
|
129
|
-
@rack.send( :alertable?,
|
130
|
+
@rack.send( :alertable?, :twitt_on, Rackamole.feature ).should == false
|
130
131
|
end
|
131
132
|
|
132
133
|
it "should always return false if the alert is disabled" do
|
133
|
-
@
|
134
|
-
@rack.send( :alertable?, @filter, Rackamole.perf ).should == false
|
134
|
+
@rack.send( :alertable?, :mail_on, Rackamole.perf ).should == false
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should fail if the alert is not configured" do
|
138
|
-
@rack.send( :alertable?,
|
138
|
+
@rack.send( :alertable?, :fred, Rackamole.perf ).should == false
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
142
|
describe '#configured?' do
|
143
143
|
before( :each ) do
|
144
144
|
options = {
|
145
|
+
:blee => [1,2,3],
|
145
146
|
:twitter_auth => { :username => 'Fernand', :password => "Blee" },
|
146
147
|
:twitt_on => { :enabled => true, :features => [Rackamole.perf, Rackamole.fault] }
|
147
148
|
}
|
@@ -153,12 +154,20 @@ describe Rack::Mole do
|
|
153
154
|
@rack.send( :configured?, :twitt_on, [:enabled, :features] ).should == true
|
154
155
|
end
|
155
156
|
|
156
|
-
it "should fail
|
157
|
+
it "should fail if an option is not set" do
|
157
158
|
@rack.send( :configured?, :twitter, [:username, :password] ).should == false
|
158
159
|
end
|
160
|
+
|
161
|
+
it "should fail if an option is not a hash" do
|
162
|
+
lambda {
|
163
|
+
@rack.send( :configured?, :blee, [:username, :pwd] )
|
164
|
+
}.should raise_error(RuntimeError, /Invalid value for option blee. Expecting a hash with symbols username,pwd/ )
|
165
|
+
end
|
159
166
|
|
160
|
-
it "should fail
|
161
|
-
|
167
|
+
it "should fail if an option is not correctly configured" do
|
168
|
+
lambda {
|
169
|
+
@rack.send( :configured?, :twitter_auth, [:username, :pwd] )
|
170
|
+
}.should raise_error(RuntimeError, /missing :pwd/ )
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackamole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernand Galiana
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -100,15 +100,12 @@ extensions: []
|
|
100
100
|
|
101
101
|
extra_rdoc_files:
|
102
102
|
- README.rdoc
|
103
|
-
- aa.txt
|
104
|
-
- aaa.txt
|
105
103
|
- lib/rackamole/alert/templates/rackamole/alert/emole/alert.erb
|
106
104
|
- samples/rails/moled/public/robots.txt
|
107
105
|
files:
|
106
|
+
- ...
|
108
107
|
- README.rdoc
|
109
108
|
- Rakefile
|
110
|
-
- aa.txt
|
111
|
-
- aaa.txt
|
112
109
|
- images/mole_logo.png
|
113
110
|
- images/mole_logo.psd
|
114
111
|
- images/mole_logo_small.png
|
@@ -204,7 +201,7 @@ files:
|
|
204
201
|
- tasks/zentest.rake
|
205
202
|
- z_experiments/config.rb
|
206
203
|
has_rdoc: true
|
207
|
-
homepage: http://rackamole.
|
204
|
+
homepage: http://www.rackamole.com
|
208
205
|
licenses: []
|
209
206
|
|
210
207
|
post_install_message:
|
data/aa.txt
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
:twitt_if => [Rackamole.feature, Rackamole.fault, Rackamole.perf],
|
2
|
-
:twitter => { :username => 'moled', :password => 'fernand~1' },
|
3
|
-
|
4
|
-
require 'action_mailer'
|
5
|
-
ActionMailer::Base.delivery_method = :sendmail
|
6
|
-
ActionMailer::Base.raise_delivery_errors = true
|
7
|
-
|
8
|
-
:email => { :from => 'fernand@collectiveintellect.com', :to => ['fernand@collectiveintellect.com'] },
|
9
|
-
:email_if => [Rackamole.feature, Rackamole.fault],
|
10
|
-
|