From 0bd4227c3d2e39b09fdc80a2b9810d6a562a5430 Mon Sep 17 00:00:00 2001 From: David Zuckerman Date: Wed, 28 Jan 2026 13:50:24 -0800 Subject: [PATCH 1/3] custom health check to verify mail password is set added test for new mail password healthcheck removed stubbing for gpg key --- config/initializers/okcomputer.rb | 13 +++++++++++++ spec/request/okcomputer_spec.rb | 1 + 2 files changed, 14 insertions(+) diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb index b61c407a..e7e7e949 100644 --- a/config/initializers/okcomputer.rb +++ b/config/initializers/okcomputer.rb @@ -18,6 +18,18 @@ def check end end +class CustomMailerCheck < OkComputer::Check + # Check that the mail password is set + def check + if ENV['MAIL_PASSWORD'].present? + mark_message 'Environment variable MAIL_PASSWORD is set.' + else + mark_failure + mark_message 'Environment variable MAIL_PASSWORD is not set!' + end + end +end + # Ensure Alma API is working. OkComputer::Registry.register 'alma-patron-lookup', AlmaPatronCheck.new @@ -25,4 +37,5 @@ def check OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new # Ensure connectivity to the mail system. +OkComputer::Registry.register 'custom-mailer', CustomMailerCheck.new OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new diff --git a/spec/request/okcomputer_spec.rb b/spec/request/okcomputer_spec.rb index fbf8d418..57690834 100644 --- a/spec/request/okcomputer_spec.rb +++ b/spec/request/okcomputer_spec.rb @@ -12,6 +12,7 @@ get '/health' expect(response.parsed_body.keys).to match_array %w[ action-mailer + custom-mailer alma-patron-lookup default database From 68a3fcd2ae455ced61448e84f6cf2d0ea8d211ad Mon Sep 17 00:00:00 2001 From: David Zuckerman Date: Thu, 29 Jan 2026 18:59:16 -0800 Subject: [PATCH 2/3] added connection checks for smtp in okcomputer --- config/initializers/okcomputer.rb | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb index e7e7e949..2fa6e3fb 100644 --- a/config/initializers/okcomputer.rb +++ b/config/initializers/okcomputer.rb @@ -18,17 +18,39 @@ def check end end +# rubocop:disable Metrics/MethodLength, Metrics/AbcSize class CustomMailerCheck < OkComputer::Check + require 'net/smtp' # Check that the mail password is set def check - if ENV['MAIL_PASSWORD'].present? - mark_message 'Environment variable MAIL_PASSWORD is set.' - else + settings = ActionMailer::Base.smtp_settings + begin + Net::SMTP.start( + settings[:address], + settings[:port], + settings[:domain], + settings[:user_name], + settings[:password], + settings[:authentication], + tls: true + ) { mark_message 'Connection for smtp successful' } + rescue Net::SMTPAuthenticationError => e mark_failure - mark_message 'Environment variable MAIL_PASSWORD is not set!' + mark_message "Authentication error: #{e.message}" + rescue Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e + mark_failure + mark_message "SMTP error: #{e.message}" + rescue IOError, Net::ReadTimeout => e + mark_failure + mark_message "Connection error: #{e.message}" + rescue StandardError => e + # Catch any other unexpected errors + mark_failure + mark_message "An unexpected error occurred: #{e.message}" end end end +# rubocop:enable Metrics/MethodLength, Metrics/AbcSize # Ensure Alma API is working. OkComputer::Registry.register 'alma-patron-lookup', AlmaPatronCheck.new From 865247bcbbb339820d8829c2289e141f23437281 Mon Sep 17 00:00:00 2001 From: David Zuckerman Date: Fri, 30 Jan 2026 13:35:27 -0800 Subject: [PATCH 3/3] renamed mail-connectivity check, generalized public errors --- config/initializers/okcomputer.rb | 25 ++++++++++++++----------- spec/request/okcomputer_spec.rb | 3 +-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config/initializers/okcomputer.rb b/config/initializers/okcomputer.rb index 2fa6e3fb..c13ca077 100644 --- a/config/initializers/okcomputer.rb +++ b/config/initializers/okcomputer.rb @@ -1,3 +1,5 @@ +require 'net/smtp' + # frozen_string_literal: true # Health check configuration @@ -6,7 +8,7 @@ OkComputer.check_in_parallel = true class AlmaPatronCheck < OkComputer::Check - TEST_PATRON_ID = '000311@lbl.gov' + TEST_PATRON_ID = '000311@lbl.gov'.freeze def check Alma::User.find(TEST_PATRON_ID) @@ -19,8 +21,9 @@ def check end # rubocop:disable Metrics/MethodLength, Metrics/AbcSize -class CustomMailerCheck < OkComputer::Check - require 'net/smtp' +class MailConnectivityCheck < OkComputer::Check + OkComputer::Registry.register 'mail-connectivity', MailConnectivityCheck.new if ActionMailer::Base.delivery_method == :smtp + # Check that the mail password is set def check settings = ActionMailer::Base.smtp_settings @@ -36,17 +39,21 @@ def check ) { mark_message 'Connection for smtp successful' } rescue Net::SMTPAuthenticationError => e mark_failure - mark_message "Authentication error: #{e.message}" + Rails.logger.warn "SMTP authentication error: #{e}" + mark_message 'SMTP Error: Authentication failed. Check logs for more details' rescue Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e mark_failure - mark_message "SMTP error: #{e.message}" + Rails.logger.warn "SMTP Error: #{e}" + mark_message 'SMTP error. Check logs for more details' rescue IOError, Net::ReadTimeout => e mark_failure - mark_message "Connection error: #{e.message}" + Rails.logger.warn "SMTP Timeout: #{e}" + mark_message 'SMTP Connection error: Timeout. Check logs for more details' rescue StandardError => e # Catch any other unexpected errors mark_failure - mark_message "An unexpected error occurred: #{e.message}" + Rails.logger.warn "SMTP standard error: #{e}" + mark_message 'SMTP ERROR: Could not connect. Check logs for more details' end end end @@ -57,7 +64,3 @@ def check # Ensure database migrations have been run. OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new - -# Ensure connectivity to the mail system. -OkComputer::Registry.register 'custom-mailer', CustomMailerCheck.new -OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new diff --git a/spec/request/okcomputer_spec.rb b/spec/request/okcomputer_spec.rb index 57690834..e4978636 100644 --- a/spec/request/okcomputer_spec.rb +++ b/spec/request/okcomputer_spec.rb @@ -11,8 +11,7 @@ it 'returns all checks to /health' do get '/health' expect(response.parsed_body.keys).to match_array %w[ - action-mailer - custom-mailer + mailer-connectivity alma-patron-lookup default database