diff --git a/lib/Thruk/Controller/cmd.pm b/lib/Thruk/Controller/cmd.pm index 9e69bfdb9..8ce2bc5ed 100644 --- a/lib/Thruk/Controller/cmd.pm +++ b/lib/Thruk/Controller/cmd.pm @@ -873,7 +873,7 @@ sub _bulk_send_backend { }; my $err = $@; if($err) { - $err =~ s/(\ at\ .*?\.pm\ line\ \d+).*$//gsmx; + $err = _strip_line($err); $c->stash->{'last_command_error'} = $err; Thruk::Utils::set_message($c, 'fail_message', "sending command failed: ".$err); return; diff --git a/lib/Thruk/Controller/extinfo.pm b/lib/Thruk/Controller/extinfo.pm index 75e55b55b..f668c2bcb 100644 --- a/lib/Thruk/Controller/extinfo.pm +++ b/lib/Thruk/Controller/extinfo.pm @@ -8,6 +8,7 @@ use Thruk::Backend::Manager (); use Thruk::UserAgent (); use Thruk::Utils::Auth (); use Thruk::Utils::External (); +use Thruk::Utils::Log qw/:all/; use Thruk::Utils::Status (); =head1 NAME @@ -875,8 +876,7 @@ sub _process_perf_info_page { $c->stash->{'has_logcache'} = 1; }; if($@) { - $c->stash->{'logcache_error'} = $@; - $c->stash->{'logcache_error'} =~ s/\ at\ .*?\ line\ \d+\.//gmx; + $c->stash->{'logcache_error'} = _strip_line($@); } } diff --git a/lib/Thruk/Controller/status.pm b/lib/Thruk/Controller/status.pm index a94f2c4fc..fe5cc3be9 100644 --- a/lib/Thruk/Controller/status.pm +++ b/lib/Thruk/Controller/status.pm @@ -7,6 +7,7 @@ use Cpanel::JSON::XS qw/decode_json/; use Thruk::Action::AddDefaults (); use Thruk::Backend::Manager (); use Thruk::Utils::Auth (); +use Thruk::Utils::Log qw/:all/; use Thruk::Utils::Status (); =head1 NAME @@ -1493,9 +1494,7 @@ sub _process_verify_time { $verified = 1; } if($@) { - $error = $@; - chomp($error); - $error =~ s/\ at .*?\.pm\ line\ \d+//gmx; + $error = _strip_line($@); } } @@ -1509,9 +1508,7 @@ sub _process_verify_time { $verified = 1; } if($@) { - $error = $@; - chomp($error); - $error =~ s/\ at .*?\.pm\ line\ \d+//gmx; + $error = _strip_line($@); } } diff --git a/lib/Thruk/Utils/Log.pm b/lib/Thruk/Utils/Log.pm index f6c410961..a8593128e 100644 --- a/lib/Thruk/Utils/Log.pm +++ b/lib/Thruk/Utils/Log.pm @@ -24,7 +24,7 @@ use Thruk::Utils::Encode (); use base 'Exporter'; our @EXPORT_OK = qw(_fatal _error _cronerror _warn _info _infos _infoc _debug _debug2 _debugs _debugc _trace _audit_log - _debug_http_response + _debug_http_response _strip_line ); our %EXPORT_TAGS = ( all => \@EXPORT_OK ); @@ -139,6 +139,14 @@ sub _debug_http_response { return; } +############################################## +sub _strip_line { + my($error) = @_; + chomp($error); + $error =~ s/\ at\ [a-zA-Z\/\.]+?\ line\ \d+\.$//gmx; + return($error); +} + ############################################## sub _log { my($lvl, $data, $options) = @_; diff --git a/lib/Thruk/Utils/Status.pm b/lib/Thruk/Utils/Status.pm index 8bb90e60c..199483f8c 100644 --- a/lib/Thruk/Utils/Status.pm +++ b/lib/Thruk/Utils/Status.pm @@ -382,8 +382,7 @@ sub do_filter { my $err = $@; if($err) { _debug("lex filter failed: %s", $err); - $err =~ s/\ at\ [a-zA-Z\/\.]+?\ line\ \d+\.$//gmx; - Thruk::Utils::set_message($c, 'fail_message', $err); + Thruk::Utils::set_message($c, 'fail_message', _strip_line($err)); $c->stash->{'has_error'} = 1; } if(!$c->stash->{'has_error'} && (!$c->stash->{'minimal'} || $c->stash->{'play_sounds'}) && ( $prefix eq 'dfl_' or $prefix eq 'ovr_' or $prefix eq 'grd_' or $prefix eq '')) { diff --git a/plugins/plugins-available/node-control/lib/Thruk/Utils/CLI/Nodecontrol.pm b/plugins/plugins-available/node-control/lib/Thruk/Utils/CLI/Nodecontrol.pm index d3f948a89..dccd2bf5b 100644 --- a/plugins/plugins-available/node-control/lib/Thruk/Utils/CLI/Nodecontrol.pm +++ b/plugins/plugins-available/node-control/lib/Thruk/Utils/CLI/Nodecontrol.pm @@ -187,7 +187,7 @@ sub _action_facts { } if(!$facts || $facts->{'last_error'}) { my $err = sprintf("%s updating %s failed: %s\n", $peer->{'name'}, $mode, ($facts->{'last_error'}//'unknown error')); - _cronerror($err); # don't fill the log with errors from cronjobs + _cronerror(_strip_line($err)); # don't fill the log with errors from cronjobs } else { _info("%s updated %s sucessfully: OK\n", $peer->{'name'}, $mode); } diff --git a/t/022-Thruk-Utils-Log.t b/t/022-Thruk-Utils-Log.t index de48ffcbe..96fd6057b 100644 --- a/t/022-Thruk-Utils-Log.t +++ b/t/022-Thruk-Utils-Log.t @@ -28,7 +28,7 @@ sub check_logger { return if $content =~ m/\Quse Thruk::Utils::Log\E/gmx; $content =~ s|::make_info\(||gmx; # reduce false positive $content =~ s|::http_response_error\(||gmx; # reduce false positive - if($content =~ m/^(.*(_debug|_error|_warn|_info|_audit_log)\(.*)/gmx) { + if($content =~ m/^(.*(_debug|_error|_warn|_info|_audit_log|_strip_line|_cronerror)\(.*)/gmx) { my $line = $1; unless($content =~ m/\Quse Thruk::Utils::Log\E/gmx) { fail($file." uses logger but misses 'use Thruk::Utils::Log'");