app/controllers/easymon/checks_controller.rb in easymon-1.2.4 vs app/controllers/easymon/checks_controller.rb in easymon-1.2.5

- old
+ new

@@ -3,12 +3,12 @@ module Easymon class ChecksController < ApplicationController rescue_from Easymon::NoSuchCheck do |e| respond_to do |format| - format.any(:text, :html) { render :text => e.message, :status => :not_found } - format.json { render :json => e.message, :status => :not_found } + format.any(:text, :html) { render_result e.message, :not_found } + format.json { render :json => e.message, :status => :not_found } end end def index checklist = Easymon::Repository.all @@ -30,11 +30,11 @@ message = add_prefix(checklist.success?, message) end end respond_to do |format| - format.any(:text, :html) { render :text => message, :status => response_status } + format.any(:text, :html) { render_result message, response_status } format.json { render :json => checklist, :status => response_status } end end def show @@ -53,18 +53,16 @@ check = Easymon::Repository.fetch(params[:check]) timing = Benchmark.realtime { check_result = check[:check].check } result = Easymon::Result.new(check_result, timing, check[:critical]) end - - respond_to do |format| format.any(:text, :html) do if is_critical - render :text => add_prefix(checklist.success?, checklist), :status => checklist.response_status + render_result add_prefix(checklist.success?, checklist), checklist.response_status else - render :text => result, :status => result.response_status + render_result result, result.response_status end end format.json do if is_critical render :json => checklist, :status => checklist.response_status @@ -74,9 +72,14 @@ end end end private + def render_result(message, status) + symbol_for_plain = Easymon.has_render_plain? ? :plain : :text + render symbol_for_plain => message, :status => status + end + def add_prefix(result, message) result ? "OK #{message}" : "DOWN #{message}" end end end