Class: HealthCheck::HealthCheckController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/health_check/health_check_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/health_check/health_check_controller.rb', line 9

def index
  checks = params[:checks] || 'standard'
  begin
    errors = HealthCheck::Utils.process_checks(checks)
  rescue Exception => e
    errors = e.message
  end     
  if errors.blank?
    obj = { :healthy => true, :message => HealthCheck.success }
    respond_to do |format|
      format.html { render :text => HealthCheck.success, :content_type => 'text/plain' }
      format.json { render :xml => obj.to_json }
      format.xml { render :xml => obj.to_xml }
      format.any { render :text => HealthCheck.success, :content_type => 'text/plain' }
    end
  else
    msg = "health_check failed: #{errors}"
    obj = { :healthy => false, :message => msg }
    respond_to do |format|
      format.html { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain'  }
      format.json { render :xml => obj.to_json, :status => HealthCheck.http_status_for_error_object}
      format.xml { render :xml => obj.to_xml, :status => HealthCheck.http_status_for_error_object }
      format.any { render :text => msg, :status => HealthCheck.http_status_for_error_text, :content_type => 'text/plain'  }
    end
    # Log a single line as some uptime checkers only record that it failed, not the text returned
    if logger
      silence_level, logger.level = logger.level, @old_logger_level if @old_logger_level
      logger.info msg
      logger.level = silence_level if @old_logger_level
    end
  end
end