Skip to content

Commit fd1208e

Browse files
committed
agents: cleanup error output
1 parent db464a0 commit fd1208e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

plugins/plugins-available/agents/lib/Thruk/Agents/SNClient.pm

+5
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ sub get_config_objects {
198198
}
199199
$chk->{'svc_conf'}->{'check_command'} .= " ".$args if $args;
200200
}
201+
202+
# escape exclamation marks in check command
203+
$chk->{'svc_conf'}->{'check_command'} =s/\\\!/!/gmx;
204+
$chk->{'svc_conf'}->{'check_command'} =s/\!/\\!/gmx;
205+
201206
$svc->{'comments'} = ["# autogenerated check: ".$svc->{'conf'}->{'service_description'} ];
202207

203208
# set extra service options

plugins/plugins-available/agents/lib/Thruk/Utils/CLI/Agents.pm

+13-2
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,19 @@ sub _check_inventory {
584584
}
585585

586586
my $t1 = [gettimeofday];
587+
my($checks, $checks_num, $hst, $hostobj);
587588

588-
my($checks, $checks_num, $hst, $hostobj) = _get_checks($c, $hostname, $opt, 1);
589+
eval {
590+
($checks, $checks_num, $hst, $hostobj) = _get_checks($c, $hostname, $opt, 1);
591+
};
592+
my $err = $@;
593+
if($err) {
594+
_debug("inventory failed: %s", $err);
595+
$err =~ s/^UNKNOWN\ \-\ //gmx;
596+
$err =~ s/\s+at\s+.*?\.pm\s+line\s+\d+\.//gmx;
597+
$err =~ s/("https?:\/\/.*?)\/[^"]*"/$1\/..."/gmx;
598+
return(sprintf("UNKNOWN - %s", $err), 3);
599+
}
589600
return(sprintf("UNKNOWN - no host found with enabled agent and name: %s\n", $hostname), 3) unless $hst;
590601
return(sprintf("UNKNOWN - no host found by name: %s\n", $hostname), 3) unless $hostobj;
591602

@@ -720,7 +731,7 @@ sub _get_checks {
720731
my($inv, $err) = Thruk::Utils::Agents::update_inventory($c, $hostname, $hostobj, $data);
721732
die($err) if $err;
722733
} else {
723-
my $err = Thruk::Utils::Agents::scan_agent($c, $data);
734+
my $err = Thruk::Utils::Agents::scan_agent($c, $data);
724735
die($err) if $err;
725736
}
726737
}

0 commit comments

Comments
 (0)