From c9c5e6ef3c19e0023d60ccde709e16467f13abed Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Tue, 6 Aug 2013 09:23:00 +0200 Subject: [PATCH] Send commands: Review fixes refs #4441 --- .../Protocol/Commandpipe/Acknowledgement.php | 12 +++---- .../Protocol/Commandpipe/CommandPipe.php | 6 ++-- .../Icinga/Protocol/Commandpipe/Downtime.php | 12 ++++--- .../Commandpipe/Transport/LocalPipe.php | 30 ++++++++++++++-- .../Commandpipe/Transport/SecureShell.php | 35 +++++++++++++++++-- .../Commandpipe/Transport/Transport.php | 28 ++++++++++++++- .../forms/Command/ScheduleDowntimeForm.php | 2 +- 7 files changed, 106 insertions(+), 19 deletions(-) diff --git a/library/Icinga/Protocol/Commandpipe/Acknowledgement.php b/library/Icinga/Protocol/Commandpipe/Acknowledgement.php index 087f430dd..9001997fe 100644 --- a/library/Icinga/Protocol/Commandpipe/Acknowledgement.php +++ b/library/Icinga/Protocol/Commandpipe/Acknowledgement.php @@ -33,7 +33,6 @@ use \Icinga\Protocol\Commandpipe\Comment; /** * Container for a host/service Acknowledgement - * */ class Acknowledgement implements IComment { @@ -54,9 +53,9 @@ class Acknowledgement implements IComment /** * The comment text of this acknowledgment * - * @var Comment|null + * @var Comment */ - private $comment = null; + private $comment; /** * true if this is a sticky acknowledgment @@ -90,7 +89,7 @@ class Acknowledgement implements IComment * * @param Comment $comment The comment to use for the acknowledgement * @param bool $notify Whether to set the notify flag - * @param $expire The expire time or -1 of not expiring + * @param int $expire The expire time or -1 of not expiring * @param bool $sticky Whether to set the sticky flag */ public function __construct(Comment $comment, $notify = false, $expire = -1, $sticky = false) @@ -104,8 +103,9 @@ class Acknowledgement implements IComment /** * Return the ACKNOWLEDGE_?_PROBLEM string to be used for submitting an external icinga command * - * @param $type Either CommandPipe::TYPE_HOST or CommandPipe:: TYPE_SERVICE - * @return string The command string to be submitted to the command pipe + * @param string $type Either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE + * @return string The command string to be submitted to the command pipe + * @throws InvalidCommandException */ public function getFormatString($type) { diff --git a/library/Icinga/Protocol/Commandpipe/CommandPipe.php b/library/Icinga/Protocol/Commandpipe/CommandPipe.php index 8096469b2..2c4392294 100644 --- a/library/Icinga/Protocol/Commandpipe/CommandPipe.php +++ b/library/Icinga/Protocol/Commandpipe/CommandPipe.php @@ -194,7 +194,9 @@ class CommandPipe } foreach ($objects as $object) { if (isset($object->service_description)) { - $this->send("PROCESS_SERVICE_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output"); + $this->send( + "PROCESS_SERVICE_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output" + ); } else { $this->send("PROCESS_HOST_CHECK_RESULT;$object->host_name;$state;$output"); } @@ -799,7 +801,7 @@ class CommandPipe } /** - * Rest modified attributes for all provided objects + * Reset modified attributes for all provided objects * * @param array $objects An array of hosts and services */ diff --git a/library/Icinga/Protocol/Commandpipe/Downtime.php b/library/Icinga/Protocol/Commandpipe/Downtime.php index 319fd3bf7..3e5f7a3d7 100644 --- a/library/Icinga/Protocol/Commandpipe/Downtime.php +++ b/library/Icinga/Protocol/Commandpipe/Downtime.php @@ -42,7 +42,7 @@ class Downtime /** * Propagate this downtime for all child objects as triggered downtime */ - const TYPE_WITH_CHILDREN_TRIGERRED = 'AND_PROPAGATE_TRIGGERED_'; + const TYPE_WITH_CHILDREN_TRIGGERED = 'AND_PROPAGATE_TRIGGERED_'; /** * Schedule downtime for the services of the given hos @@ -92,7 +92,9 @@ class Downtime public $trigger_id = 0; /** - * Internal information for the exact type of the downtime (with children, with children and triggered, services etc.) + * Internal information for the exact type of the downtime + * + * E.g. with children, with children and triggered, services etc. * * @var string */ @@ -104,8 +106,10 @@ class Downtime * @param int $start A timestamp that defines the downtime's start time * @param int $end A timestamp that defines the downtime's end time * @param Comment $comment A comment that will be used when scheduling the downtime - * @param int $duration The duration of this downtime in seconds. Duration > 0 will make this a flexible downtime - * @param int $trigger_id An id of the downtime that triggers this downtime. 0 means this is not a triggered downtime + * @param int $duration The duration of this downtime in seconds. + * Duration > 0 will make this a flexible downtime + * @param int $trigger_id An id of the downtime that triggers this downtime. + * 0 means this is not a triggered downtime */ public function __construct($start, $end, Comment $comment, $duration = 0, $trigger_id = 0) { diff --git a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php index b3e3582cb..79b297f11 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php @@ -1,11 +1,37 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Protocol\Commandpipe\Transport; + use Icinga\Application\Logger; /** * CommandPipe Transport class that writes to a file accessible by the filesystem - * */ class LocalPipe implements Transport { @@ -55,4 +81,4 @@ class LocalPipe implements Transport { $this->openMode = $mode; } -} \ No newline at end of file +} diff --git a/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php b/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php index 12000ddb5..272b4b34d 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php @@ -1,4 +1,30 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Protocol\Commandpipe\Transport; @@ -69,7 +95,8 @@ class SecureShell implements Transport ); $hostConnector = $this->user ? $this->user . "@" . $this->host : $this->host; exec( - 'ssh -o BatchMode=yes -o KbdInteractiveAuthentication=no'.$hostConnector.' -p'.$this->port.' "echo \'['. time() .'] ' + 'ssh -o BatchMode=yes -o KbdInteractiveAuthentication=no' + . $hostConnector.' -p'.$this->port.' "echo \'['. time() .'] ' . escapeshellcmd( $command ) @@ -87,9 +114,11 @@ class SecureShell implements Transport Logger::debug("Return code %s: %s ", $retCode, $output); if ($retCode != 0) { - $msg = 'Could not send command to remote icinga host: '. implode("\n",$output). " (returncode $retCode)"; + $msg = 'Could not send command to remote icinga host: ' + . implode(PHP_EOL, $output) + . " (returncode $retCode)"; Logger::error($msg); throw new \RuntimeException($msg); } } -} \ No newline at end of file +} diff --git a/library/Icinga/Protocol/Commandpipe/Transport/Transport.php b/library/Icinga/Protocol/Commandpipe/Transport/Transport.php index 46f628015..d249c86e0 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/Transport.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/Transport.php @@ -1,4 +1,30 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} namespace Icinga\Protocol\Commandpipe\Transport; @@ -21,4 +47,4 @@ interface Transport * @param string $message The command to send, without the timestamp (this will be added here) */ public function send($message); -} \ No newline at end of file +} diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php index 526c50a8f..cab8fae0e 100644 --- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php +++ b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php @@ -305,7 +305,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm if (! $this->getWithChildren()) { switch ($this->getValue('childobjects')) { case 1: - $downtime->setType(Downtime::TYPE_WITH_CHILDREN_TRIGERRED); + $downtime->setType(Downtime::TYPE_WITH_CHILDREN_TRIGGERED); break; case 2: $downtime->setType(Downtime::TYPE_WITH_CHILDREN);