[icinga-checkins] icinga.org: icingaweb2/master: Show useful error message if a command transport failed

git at icinga.org git at icinga.org
Thu Feb 25 10:36:38 CET 2016


Module: icingaweb2
Branch: master
Commit: c834e66b9a19a165e42cd8ec8e62b82709f9cb34
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=c834e66b9a19a165e42cd8ec8e62b82709f9cb34

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Thu Feb 25 10:36:10 2016 +0100

Show useful error message if a command transport failed

fixes #10173

---

 .../Command/Transport/CommandTransport.php           |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
index 179b9e5..81fb549 100644
--- a/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
+++ b/modules/monitoring/library/Monitoring/Command/Transport/CommandTransport.php
@@ -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(



More information about the icinga-checkins mailing list