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

View File

@ -111,16 +111,16 @@ class CommandTransport implements CommandTransportInterface
*/ */
public function send(IcingaCommand $command, $now = null) public function send(IcingaCommand $command, $now = null)
{ {
$tries = 0; $errors = array();
foreach (static::getConfig() as $transportConfig) {
$transport = static::createTransport($transportConfig);
foreach (static::getConfig() as $name => $transportConfig) {
$transport = static::createTransport($transportConfig);
if ($this->transferPossible($command, $transport)) { if ($this->transferPossible($command, $transport)) {
try { try {
$transport->send($command, $now); $transport->send($command, $now);
} catch (CommandTransportException $e) { } catch (CommandTransportException $e) {
Logger::error($e); Logger::error($e);
$tries += 1; $errors[] = sprintf('%s: %s.', $name, rtrim($e->getMessage(), '.'));
continue; // Try the next transport continue; // Try the next transport
} }
@ -128,14 +128,8 @@ class CommandTransport implements CommandTransportInterface
} }
} }
if ($tries > 0) { if (! empty($errors)) {
throw new CommandTransportException( throw new CommandTransportException(implode("\n", $errors));
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.'
)
);
} }
throw new CommandTransportException( throw new CommandTransportException(