Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there interest in a fail2ban notifier? #205

Closed
etdsoft opened this issue Jan 2, 2014 · 3 comments
Closed

Is there interest in a fail2ban notifier? #205

etdsoft opened this issue Jan 2, 2014 · 3 comments

Comments

@etdsoft
Copy link

etdsoft commented Jan 2, 2014

I created a notifier for ExceptionNotification that just pipes a few fields into a separate log file the idea being that after too many exceptions by a single IP in a short period of time fail2ban can kick in and ban the IP for a little while.

If you are interested I can submit a pull request, code is simple:

class Fail2banNotifier
  def initialize(options)
    @default_options = options
    @default_options[:logfile] ||= Rails.root.join('log', 'fail2ban.log')

    # Roll over every 30M, keep 10 files
    @logger ||= Logger.new(@default_options[:logfile], 10, 30*1024*1024)
  end

  def call(exception, options={})
    env = options[:env]
    request = ActionDispatch::Request.new(env)

    # <ip> : <exception class> : <method> <path> -- <params>
    msg = "%s : %s : %s %s -- %s" % [
      request.remote_ip,
      exception.class,
      request.request_method,
      env["PATH_INFO"],
      request.filtered_parameters.inspect
    ]
    @logger.error(msg)
  end
end
@jweslley
Copy link
Collaborator

jweslley commented Jan 2, 2014

It's great @etdsoft . Can you send a pull request including some usage documentation (and fail2ban config, if required)?

@etdsoft
Copy link
Author

etdsoft commented Jan 2, 2014

Struggling to run the test suite at the moment:

/Users/etd/.rbenv/versions/2.0.0-p353/bin/ruby -I"lib:lib:test" -I"/Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib" "/Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/__/__test.rb"
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's default settings.

**\* Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`.

DEPRECATION WARNING: ActionController::Integration is deprecated and will be removed, use ActionDispatch::Integration instead. (called from <top (required)> at /Users/etd/Code/exception_notification/test/dummy/vendor/bundle/gems/actionpack-4.0.0/lib/action_controller/deprecated/integration_test.rb:4)
DEPRECATION WARNING: ActionController::IntegrationTest is deprecated and will be removed, use ActionDispatch::IntegrationTest instead. (called from <top (required)> at /Users/etd/Code/exception_notification/test/dummy/vendor/bundle/gems/actionpack-4.0.0/lib/action_controller/deprecated/integration_test.rb:5)
[Coveralls] Outside the Travis environment, not sending data.
/Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- helper (LoadError)
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in`block in require'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in`require'
    from /Users/etd/Code/exception_notification/test/dummy/vendor/bundle/gems/activerecord-deprecated_finders-1.0.3/test/associations_test.rb:1:in `<top (required)>'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in`require'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in`load_dependency'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in`block (2 levels) in <main>'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in`block in <main>'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/etd/Code/exception_notification/vendor/bundle/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in`<main>'
rake aborted!

@etdsoft
Copy link
Author

etdsoft commented Jan 2, 2014

submitted as:
#206

@etdsoft etdsoft closed this as completed Jan 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants