Method: Perus::Pinger::Pinger#send_response

Defined in:
lib/perus/pinger/pinger.rb

#send_responseObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/perus/pinger/pinger.rb', line 211

def send_response
    # prepare the response and replace file results with a reference
    # to the uploaded file. files are sent as top level parameters in
    # the payload, while metric and action results are sent as a json
    # object with a reference to these files.
    payload = {}
    add_to_payload(payload, 'metrics', @metric_results)
    add_to_payload(payload, 'actions', @action_results)

    # metric_errors is created with a key for each metric type. most
    # metrics should run without any errors, so remove these entries
    # before adding errors to the payload.
    @metric_errors.reject! {|metric, errors| errors.empty?}
    add_to_payload(payload, 'metric_errors', @metric_errors)

    pinger_path = URI("systems/#{@system_id}/ping")
    pinger_url = (@server_uri + pinger_path).to_s

    begin
        RestClient.post(pinger_url, payload)
    rescue => e
        puts 'Ping failed with exception'
        puts format_exception(e)
    end
end