Skip to content

Is there interest in a fail2ban notifier? #205

@etdsoft

Description

@etdsoft

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions