Show useful error message if a command transport failed

fixes #10173
This commit is contained in:
Eric Lippmann 2016-02-25 10:36:10 +01:00
parent 102ed40378
commit c834e66b9a
1 changed files with 6 additions and 12 deletions

View File

@ -111,16 +111,16 @@ class CommandTransport implements CommandTransportInterface
*/
public function send(IcingaCommand $command, $now = null)
{
$tries = 0;
foreach (static::getConfig() as $transportConfig) {
$transport = static::createTransport($transportConfig);
$errors = array();
foreach (static::getConfig() as $name => $transportConfig) {
$transport = static::createTransport($transportConfig);
if ($this->transferPossible($command, $transport)) {
try {
$transport->send($command, $now);
} catch (CommandTransportException $e) {
Logger::error($e);
$tries += 1;
$errors[] = sprintf('%s: %s.', $name, rtrim($e->getMessage(), '.'));
continue; // Try the next transport
}
@ -128,14 +128,8 @@ class CommandTransport implements CommandTransportInterface
}
}
if ($tries > 0) {
throw new CommandTransportException(
mt(
'monitoring',
'Failed to send external Icinga command. None of the configured transports'
. ' was able to transfer the command. Please see the log for more details.'
)
);
if (! empty($errors)) {
throw new CommandTransportException(implode("\n", $errors));
}
throw new CommandTransportException(