
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
A simple way to configure a healthcheck route in Rails applications
Add this line to your application's Gemfile:
gem 'rails-healthcheck'
and run the command bellow to create the initializer:
rails generate healthcheck:install
You can set the settings in the initializer file (config/initializers/healthcheck.rb):
# frozen_string_literal: true
Healthcheck.configure do |config|
config.success = 200
config.error = 503
config.verbose = false
config.route = '/healthcheck'
config.method = :get
# -- Custom Response --
# config.custom = lambda { |controller, checker|
# return controller.render(plain: 'Everything is awesome!') unless checker.errored?
# controller.verbose? ? controller.verbose_error(checker) : controller.head_error
# }
# -- Checks --
# config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
# config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! }
# config.add_check :cache, -> { Rails.cache.read('some_key') }
# config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
end
You can override the configs success
, error
and verbose
and write your custom behaviour for the healthcheck api using the field custom
in the initializer:
Healthcheck.configure do |config|
# ...
# -- Custom Response --
config.custom = lambda { |controller, checker|
controller.render json: { field_name: 'my custom field value' } unless checker.errored?
...
}
# ...
end
Pass a lambda
or proc
receiving the params controller
and checker
to use it correctly. To use checker, you can see the avialable methods here and how it is implemented on HealthcheckController.
You can enable verbose responses setting config.verbose = true
.
{
"code": 200,
"status": {
"migrations": "OK",
"environments": "OK"
}
}
{
"code": 503,
"errors": [
{
"name": "migrations",
"exception": "ActiveRecord::PendingMigrationError",
"message": "Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=production"
},
{
"name": "environments",
"exception": "Dotenv::MissingKeys",
"message": "Missing required configuration key: [\"RAILS_ENV\"]"
}
]
}
If you want to ignore Healthcheck request logs, you can use these options:
# config/environments/production.rb
Rails.application.configure do
config.lograge.enabled = true
config.lograge.ignore_actions = [Healthcheck::CONTROLLER_ACTION]
end
# config/environments/production.rb
filter = Datadog::Pipeline::SpanFilter.new do |span|
span.name == 'rack.request' && span.get_tag('http.url') == Healthcheck.configuration.route
end
Datadog::Pipeline.before_flush(filter)
curl -i localhost:3000/healthcheck
HTTP/1.1 200 OK
curl -i localhost:3000/healthcheck
HTTP/1.1 503 Service Unavailable
curl -i localhost:3000/healthcheck
HTTP/1.1 503 Service Unavailable
{"code":503,"errors":[{"name":"zero_division","exception":"ZeroDivisionError","message":"divided by 0"}]}
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Rails::Healthcheck project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that rails-healthcheck demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.