diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index 2d30de077..63188bad3 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -87,6 +87,30 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX actions.add(:restart_failed_jobs) end + Setting.get('import_backends')&.each do |backend| + + if !ImportJob.backend_valid?(backend) + logger.error "Invalid import backend '#{backend}'" + next + end + + # skip deactivated backends + next if !backend.constantize.active? + + job = ImportJob.where( + name: backend, + dry_run: false, + ).where('finished_at >= ?', 5.minutes.ago).limit(1).first + + next if job.blank? + next if !job.result.is_a?(Hash) + + error_message = job.result[:error] + next if error_message.blank? + + issues.push "Failed to run import backend '#{backend}'. Cause: #{error_message}" + end + token = Setting.get('monitoring_token') if issues.blank? diff --git a/test/controllers/monitoring_controller_test.rb b/test/controllers/monitoring_controller_test.rb index b9c6d7bdc..3c656db2f 100644 --- a/test/controllers/monitoring_controller_test.rb +++ b/test/controllers/monitoring_controller_test.rb @@ -389,6 +389,29 @@ class MonitoringControllerTest < ActionDispatch::IntegrationTest assert_equal(false, result['healthy']) assert_equal('Channel: Email::Notification out ;unprocessable mails: 1;scheduler not running', result['message']) + Setting.set('ldap_integration', true) + + ImportJob.create( + name: 'Import::Ldap', + started_at: Time.zone.now, + finished_at: Time.zone.now, + result: { + error: 'Some bad error' + } + ) + + # health_check + get "/api/v1/monitoring/health_check?token=#{@token}", params: {}, headers: @headers + assert_response(200) + + result = JSON.parse(@response.body) + assert_equal(Hash, result.class) + assert(result['message']) + assert(result['issues']) + assert_equal(false, result['healthy']) + assert_equal("Channel: Email::Notification out ;unprocessable mails: 1;scheduler not running;Failed to run import backend 'Import::Ldap'. Cause: Some bad error", result['message']) + + Setting.set('ldap_integration', false) end test '09 check restart_failed_jobs' do