Added failed Import::Job backend results to the monitoring endpoint.
This commit is contained in:
parent
57294646a9
commit
a67299d7fe
|
@ -87,6 +87,30 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX
|
||||||
actions.add(:restart_failed_jobs)
|
actions.add(:restart_failed_jobs)
|
||||||
end
|
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')
|
token = Setting.get('monitoring_token')
|
||||||
|
|
||||||
if issues.blank?
|
if issues.blank?
|
||||||
|
|
|
@ -389,6 +389,29 @@ class MonitoringControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal(false, result['healthy'])
|
assert_equal(false, result['healthy'])
|
||||||
assert_equal('Channel: Email::Notification out ;unprocessable mails: 1;scheduler not running', result['message'])
|
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
|
end
|
||||||
|
|
||||||
test '09 check restart_failed_jobs' do
|
test '09 check restart_failed_jobs' do
|
||||||
|
|
Loading…
Reference in a new issue