From cf1a907de293c787865e35abeebc075991678e56 Mon Sep 17 00:00:00 2001 From: Lane Seppala Date: Thu, 8 Mar 2018 17:13:18 -0700 Subject: [PATCH] user app logger in legacy validation --- Conch/lib/Conch/Controller/DeviceReport.pm | 2 +- .../lib/Conch/Legacy/Control/Device/Validation.pm | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Conch/lib/Conch/Controller/DeviceReport.pm b/Conch/lib/Conch/Controller/DeviceReport.pm index 7bf379a62..0c2e89a5a 100644 --- a/Conch/lib/Conch/Controller/DeviceReport.pm +++ b/Conch/lib/Conch/Controller/DeviceReport.pm @@ -79,7 +79,7 @@ sub process ($c) { my ( $device, $report_id ) = record_device_report( $schema, $device_report ); my $validation_result = - validate_device( $schema, $device, $device_report, $report_id ); + validate_device( $schema, $device, $device_report, $report_id, $c->app->log ); $c->status( 200, $validation_result ); } diff --git a/Conch/lib/Conch/Legacy/Control/Device/Validation.pm b/Conch/lib/Conch/Legacy/Control/Device/Validation.pm index 141b36f78..cd9f7a075 100644 --- a/Conch/lib/Conch/Legacy/Control/Device/Validation.pm +++ b/Conch/lib/Conch/Legacy/Control/Device/Validation.pm @@ -18,7 +18,7 @@ use Conch::Legacy::Control::Device::Environment; use Conch::Legacy::Control::Device::Inventory; use Conch::Legacy::Control::Device::Network; -use Mojo::Exception; +use Mojo::JSON qw(encode_json); use Exporter 'import'; our @EXPORT = qw( validate_device ); @@ -30,7 +30,7 @@ Run device validations with a device report. =cut sub validate_device { - my ( $schema, $device, $device_report, $report_id ) = @_; + my ( $schema, $device, $device_report, $report_id, $logger ) = @_; my @validations = $device_report->validations; try { @@ -55,7 +55,7 @@ sub validate_device { $schema->resultset('DeviceValidate')->create( { - device_id => $device_id, + device_id => $device->id, report_id => $report_id, validation => encode_json( { @@ -68,20 +68,20 @@ sub validate_device { } ); - Mojo::Exception->throw( + $logger->error( $device->id . ": Marking FAIL because exception occurred: $message" ); + return { health => "FAIL", errors => [$message] }; } my $validation_errors = $@ if $@; if ( $validation_errors && $validation_errors->exceptions > 0 ) { my @errors = $validation_errors->exceptions; - map { trace $_; } @errors; - warning( $device->id . ": Marking FAIL" ); + $logger->warn( $device->id . ": Marking FAIL" ); $device->update( { health => "FAIL" } ); return { health => "FAIL", errors => \@errors }; } else { - info( $device->id . ": Marking PASS" ); + $logger->info( $device->id . ": Marking PASS" ); $device->update( { health => "PASS" } ); return { health => "PASS" }; }