Permalink
Browse files

Bug fixes and updates

  • Loading branch information...
1 parent 26dca79 commit 15b84deafc95817818eeebd7bd6b6eb9ae67cb7d @derailed derailed committed Nov 4, 2009
View
@@ -1,137 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-bin/molify
-config/database.yml
-config/test_database.yml
-lib/mole.rb
-lib/mole/db/migrate.rb
-lib/mole/e_mole.rb
-lib/mole/e_mole_helper.rb
-lib/mole/logger.rb
-lib/mole/models/mole_feature.rb
-lib/mole/models/mole_log.rb
-lib/mole/module.rb
-lib/mole/moler.rb
-lib/mole/utils/frameworks.rb
-lib/mole/version.rb
-samples/merbapp/README
-samples/merbapp/Rakefile
-samples/merbapp/app/controllers/application.rb
-samples/merbapp/app/controllers/exceptions.rb
-samples/merbapp/app/controllers/moled.rb
-samples/merbapp/app/helpers/global_helper.rb
-samples/merbapp/app/mailers/views/layout/application.html.erb
-samples/merbapp/app/mailers/views/layout/application.text.erb
-samples/merbapp/app/parts/views/layout/application.html.erb
-samples/merbapp/app/views/exceptions/internal_server_error.html.erb
-samples/merbapp/app/views/exceptions/not_acceptable.html.erb
-samples/merbapp/app/views/exceptions/not_found.html.erb
-samples/merbapp/app/views/layout/application.html.erb
-samples/merbapp/app/views/moled/index.html.erb
-samples/merbapp/app/views/moled/result.html.erb
-samples/merbapp/config/boot.rb
-samples/merbapp/config/dependencies.rb
-samples/merbapp/config/environments/development.rb
-samples/merbapp/config/environments/production.rb
-samples/merbapp/config/environments/test.rb
-samples/merbapp/config/merb.yml
-samples/merbapp/config/merb_init.rb
-samples/merbapp/config/mole_config.rb
-samples/merbapp/config/router.rb
-samples/merbapp/config/upload.conf
-samples/merbapp/log/merb.4000.pid
-samples/merbapp/public/images/merb.jpg
-samples/merbapp/public/merb.fcgi
-samples/merbapp/public/stylesheets/master.css
-samples/merbapp/script/destroy
-samples/merbapp/script/generate
-samples/merbapp/script/stop_merb
-samples/merbapp/spec/spec_helper.rb
-samples/merbapp/test/test_helper.rb
-samples/railsapp/README
-samples/railsapp/Rakefile
-samples/railsapp/app/controllers/application.rb
-samples/railsapp/app/controllers/moled_controller.rb
-samples/railsapp/app/helpers/application_helper.rb
-samples/railsapp/app/views/moled/index.html.erb
-samples/railsapp/app/views/moled/result.html.erb
-samples/railsapp/config/boot.rb
-samples/railsapp/config/database.yml
-samples/railsapp/config/environment.rb
-samples/railsapp/config/environments/development.rb
-samples/railsapp/config/environments/production.rb
-samples/railsapp/config/environments/test.rb
-samples/railsapp/config/initializers/inflections.rb
-samples/railsapp/config/initializers/mime_types.rb
-samples/railsapp/config/initializers/mole.rb
-samples/railsapp/config/moles/mole_config.rb
-samples/railsapp/config/routes.rb
-samples/railsapp/doc/README_FOR_APP
-samples/railsapp/log/development.log
-samples/railsapp/log/production.log
-samples/railsapp/log/server.log
-samples/railsapp/log/test.log
-samples/railsapp/public/.htaccess
-samples/railsapp/public/404.html
-samples/railsapp/public/422.html
-samples/railsapp/public/500.html
-samples/railsapp/public/dispatch.cgi
-samples/railsapp/public/dispatch.fcgi
-samples/railsapp/public/dispatch.rb
-samples/railsapp/public/favicon.ico
-samples/railsapp/public/images/rails.png
-samples/railsapp/public/javascripts/application.js
-samples/railsapp/public/javascripts/controls.js
-samples/railsapp/public/javascripts/dragdrop.js
-samples/railsapp/public/javascripts/effects.js
-samples/railsapp/public/javascripts/prototype.js
-samples/railsapp/public/robots.txt
-samples/railsapp/script/about
-samples/railsapp/script/console
-samples/railsapp/script/destroy
-samples/railsapp/script/generate
-samples/railsapp/script/performance/benchmarker
-samples/railsapp/script/performance/profiler
-samples/railsapp/script/performance/request
-samples/railsapp/script/plugin
-samples/railsapp/script/process/inspector
-samples/railsapp/script/process/reaper
-samples/railsapp/script/process/spawner
-samples/railsapp/script/runner
-samples/railsapp/script/server
-samples/railsapp/test/test_helper.rb
-samples/rubyapp/README
-samples/rubyapp/bin/ruby_app
-samples/rubyapp/config/mole_conf.rb
-samples/rubyapp/lib/fred.rb
-spec/config/auto_mole_config.rb
-spec/config/mole_config.rb
-spec/config/moles/fred_config.rb
-spec/data/blee.rb
-spec/db/migrate_spec.rb
-spec/emole_spec.rb
-spec/logger_spec.rb
-spec/models/mole_feature_spec.rb
-spec/models/mole_log_spec.rb
-spec/module_spec.rb
-spec/mole_spec.rb
-spec/moler_spec.rb
-spec/spec_helper.rb
-spec/utils/framework_spec.rb
-tasks/ann.rake
-tasks/annotations.rake
-tasks/doc.rake
-tasks/gem.rake
-tasks/manifest.rake
-tasks/mole.rake
-tasks/post_load.rake
-tasks/rubyforge.rake
-tasks/setup.rb
-tasks/spec.rake
-tasks/svn.rake
-tasks/test.rake
-templates/mole/e_mole/exception_alerts.rhtml
-templates/mole/e_mole/feature_alerts.rhtml
-templates/mole/e_mole/perf_alerts.rhtml
View
@@ -9,7 +9,6 @@ require 'mole'
require 'mole/version'
task :default => 'spec:run'
-
PROJ.name = 'mole'
PROJ.authors = 'Fernand Galiana'
PROJ.email = 'fernand@liquidrail.com'
@@ -39,8 +38,10 @@ task :clean do
FileUtils.rm_rf gem_artifacts if File.exists? gem_artifacts
end
-task 'gem:package' => 'manifest:assert'
-
+task 'gem:package'
-depend_on "logging" , "= 0.9.0"
-depend_on "activerecord", "= 2.0.2"
+# Dependencies...
+
+depend_on "logging" , "~> 1.2.2"
+depend_on "activerecord", "~> 2.3.2"
+depend_on "twitter4r" , "~> 0.3.0"
View
@@ -63,6 +63,8 @@ def self.reset_configuration! #:nodoc:
# <tt>log_level</tt>:: logging level ie :info, :debug, :error, :warn...
# <tt>email_alerts_to</tt>:: log level email alert recipients.
# <tt>email_alert_level</tt>:: specifies which log level will trigger email alerts to be sent
+ # <tt>twitter_login</tt>:: Twitter login either username or email address
+ # <tt>twitter_pwd</tt>:: Twitter password
def self.initialize( opts={} )
@config = defaults.merge( opts )
@config[:email_alerts_to] = @config[:emole_recipients] if @config[:emole_recipients] and !@config[:emole_recipients].empty?
@@ -105,6 +107,11 @@ def self.emole_recipients #:nodoc:
config[:emole_recipients]
end
+ # Twitter account information return login, pwd
+ def self.twitter_credentials
+ return config[:twitter_login], config[:twitter_pwd]
+ end
+
# Fetch the MOle configuration
def self.config #:nodoc:
@config
@@ -204,7 +211,7 @@ def self.find_controller_classes( dir )
classes = []
search_me = ::File.expand_path( ::File.join(dir, '*.rb'))
# BOZO !! This kind of sucks - need to exclude application controller for rails otherwise class loading error ??
- Dir.glob(search_me).sort.each {|rb| classes << camelize( File.basename( rb, ".rb") ) unless File.basename( rb, ".rb") == "application" }
+ Dir.glob(search_me).sort.each {|rb| classes << camelize( File.basename( rb, ".rb") ) unless File.basename( rb, ".rb") == "application_controller" }
classes
end
View
@@ -12,64 +12,81 @@ def setup #:nodoc:
# Setup aspect
%w[perf exception feature].each do |asp|
- module_eval "def #{asp}_alerts_with_setup( context, user_name, opts={} ) setup; #{asp}_alerts_without_setup( context, user_name, opts) end #:nodoc:"
+ module_eval "def #{asp}_alerts_with_setup( context, feature, user_name, opts={} ) setup; #{asp}_alerts_without_setup( context, feature, user_name, opts) end #:nodoc:"
end
# send out feature alerts
- def feature_alerts( context, user_id, options={} )
+ def feature_alerts( context, feature, user_id, options={} )
Mole.logger.debug "Sending feature email from #{::Mole.emole_from} -- to #{::Mole.emole_recipients}"
subject "[FEATURE] #{options[:feature]} -- #{@host} -- #{Mole.application} -- #{user_id}"
body :application => Mole.application,
:host_name => @host,
:context => context.class.name,
- :feature => options[:feature],
+ :feature => feature.to_s,
:args => dump_args( options )
end
alias_method_chain :feature_alerts, :setup
# send out mole performance alert
- def perf_alerts( context, user_id, options={} )
+ def perf_alerts( context, feature, user_id, options={} )
Mole.logger.debug "Sending perf email from #{::Mole.emole_from} -- to #{::Mole.emole_recipients}"
subject "[PERF] #{@host} -- #{Mole.application} -- #{user_id}"
body :application => ::Mole.application,
:host_name => @host,
:context => context.class.name,
- :feature => options[:feature],
+ :feature => feature.to_s,
:elapsed_time => options[:elapsed_time] ,
:args => dump_args( options )
end
alias_method_chain :perf_alerts, :setup
# send out mole exception alerts
- def exception_alerts( context, user_id, options={} )
+ def exception_alerts( context, feature, user_id, options={} )
Mole.logger.debug "Sending perf email from #{::Mole.emole_from} -- to #{::Mole.emole_recipients}"
subject "[EXCEPTION] #{@host} -- #{Mole.application} -- #{user_id}"
body :application => Mole.application,
:host_name => @host,
:context => context.class.name,
- :feature => options[:feature],
+ :feature => feature.to_s,
:boom => options[:boom],
- :trace => dump_stack( options[:boom] ),
+ :trace => options[:trace],
:args => dump_args( options )
end
alias_method_chain :exception_alerts, :setup
-
- # dumps partial stack
- def dump_stack( boom )
- return boom if boom.is_a? String
- buff = boom.backtrace[0...3].join( "\r" )
- end
-
- # dumps arguments
- def dump_args( args )
- return "N/A" unless args
- buff = []
- args.keys.sort { |a,b| a.to_s <=> b.to_s}.each do |k|
- key = k.to_s.rjust(20)
- value = args[k].to_s.rjust(97,".")
- buff << "#{key} : #{value}"
+
+ # =========================================================================
+ private
+
+ # dumps arguments
+ def dump_args( args )
+puts "ARGS !!!", args.inspect
+ return "N/A" unless args
+ buff = []
+ args.keys.sort { |a,b| a.to_s <=> b.to_s}.each do |k|
+ key = k.to_s.rjust(20)
+ if args[k].instance_of? Hash
+ buff << dump_hash( args[k] )
+ else
+ value = args[k].to_s.rjust(97,".")
+ buff << "#{key} : #{value}"
+ end
+ end
+ buff.join( "\r" )
+ end
+
+ def dump_hash( value )
+puts "!!!!! VAL!!!", value.inspect
+ buff = []
+ value.keys.sort { |a,b| a.to_s <=> b.to_s} .each do |k|
+ key = k.to_s.rjust(20)
+ if value[k].instance_of? Hash
+ buff << dump_hash( value[k] )
+ else
+ val = value[k].to_s.rjust(97,".")
+ buff << "#{key} : #{val}"
+ end
+ end
+ buff
end
- buff.join( "\r" )
- end
end
end
View
@@ -119,15 +119,13 @@ def for( arg ) #:nodoc:
end
# mole the bastard - create an entry into MOle log file
- def log_it( context, feature, user_id, args )
- args ||= "no args"
+ def log_it( context, feature, user_id, params )
+ params ||= "no args"
user_id ||= "N/A"
ip_addr, browser_type = MoleLog.log_details( context )
- info = []
- args.keys.sort { |a,b| a.to_s <=> b.to_s }.each { |k| info << "#{k}=>#{args[k]}" }
buff = ""
buff << "[#{ip_addr}/#{browser_type}]--" if ip_addr and browser_type
- buff << "#{context.class.name}(#{feature}) --- #{user_id} -> #{info.join( ', ' ) }"
+ buff << "#{context.class.name}(#{feature}) --- #{user_id} -> #{params.to_json}"
self.info( buff )
end
end
@@ -1,13 +1,17 @@
# Feature model - Tracks the various application features in the db.
class MoleFeature < ActiveRecord::Base
has_many :mole_logs
+
+ def to_s
+ self.name
+ end
class << self
# famous constants...
def all() "ALL" ; end
def exception() "Exception" ; end
def performance() "Performance"; end
-
+
# find performance feature
def find_performance_feature( app_name )
find_or_create_feature( performance, app_name )
@@ -27,7 +31,7 @@ def find_all_feature( app_name )
def find_moled_application_names
res = find( :all,
:select => "distinct( app_name )",
- :order => "name asc" )
+ :order => "app_name" )
res.map(&:app_name)
end
@@ -38,7 +42,7 @@ def find_features( app_name )
find( :all,
:conditions => ["app_name = ?", app_name],
:select => "id, name, context",
- :order => "name asc" )
+ :order => "name, id, context" )
end
# locates an existing feature or create a new one if it does not exist.
@@ -6,23 +6,24 @@ class MoleLog < ActiveRecord::Base
class << self
# mole the bastard - create db entry into mole logs
- def log_it( context, feature, user_id, args )
+ def log_it( context, feature, user_id, params )
args ||= "no args"
user_id ||= "N/A"
ip_addr, browser_type = log_details( context )
MoleLog.create( :mole_feature => feature,
:user_id => user_id,
:host_name => `hostname`,
- :params => args.to_yaml,
+ :params => params.to_json,
:ip_address => ip_addr,
:browser_type => browser_type )
end
# extract orginating ip address and browser type
def log_details( context ) #:nodoc:
ip_addr, browser_type = nil
- if context.respond_to? :request
- ip_addr, browser_type = context.request.env['REMOTE_ADDR'], context.request.env['HTTP_USER_AGENT']
+ if context.respond_to? :request
+ client_ip = context.request.env['HTTP_X_FORWARDED_FOR'] || context.request.env['REMOTE_ADDR']
+ ip_addr, browser_type = client_ip, context.request.env['HTTP_USER_AGENT']
end
return ip_addr, browser_type
end
Oops, something went wrong.

0 comments on commit 15b84de

Please sign in to comment.