diff --git a/library/Icinga/Protocol/Commandpipe/Command.php b/library/Icinga/Protocol/Commandpipe/Command.php new file mode 100644 index 000000000..a5651b617 --- /dev/null +++ b/library/Icinga/Protocol/Commandpipe/Command.php @@ -0,0 +1,58 @@ +<?php +// {{{ICINGA_LICENSE_HEADER}}} +/** + * This file is part of Icinga 2 Web. + * + * Icinga 2 Web - Head for multiple monitoring backends. + * Copyright (C) 2013 Icinga Development Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @copyright 2013 Icinga Development Team <info@icinga.org> + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team <info@icinga.org> + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Protocol\Commandpipe; + +/** + * Interface definition for command objects processed by the CommandPipe + */ +interface Command +{ + /** + * Set the hostname for this command + * + * @param string $hostname + * @return self + */ + public function setHost($hostname); + + /** + * Set the service description for this command + * + * @param string $service_description + * @return self + */ + public function setService($service_description); + + /** + * Return a string representation of this command + * + * @return string + */ + public function __toString(); +} \ No newline at end of file diff --git a/library/Icinga/Protocol/Commandpipe/CommandPipe.php b/library/Icinga/Protocol/Commandpipe/CommandPipe.php index c20c18a46..89b06b540 100644 --- a/library/Icinga/Protocol/Commandpipe/CommandPipe.php +++ b/library/Icinga/Protocol/Commandpipe/CommandPipe.php @@ -28,8 +28,6 @@ namespace Icinga\Protocol\Commandpipe; -use Icinga\Application\Logger as IcingaLogger; - use Icinga\Protocol\Commandpipe\Transport\Transport; use Icinga\Protocol\Commandpipe\Transport\LocalPipe; use Icinga\Protocol\Commandpipe\Transport\SecureShell; @@ -138,6 +136,23 @@ class CommandPipe $this->transport->send($command); } + /** + * Send a command to the icinga pipe + * + * @param \Icinga\Protocol\Commandpipe\Command $command + * @param array $objects + */ + public function sendCommand(Command $command, array $objects) + { + foreach ($objects as $object) { + if (isset($object->service_description)) { + $command->setService($object->service_description); + } + $command->setHost($object->host_name); + $this->transport->send((string) $command); + } + } + /** * Acknowledge a set of monitoring objects * diff --git a/modules/monitoring/library/Monitoring/Command/MonitoringCommand.php b/modules/monitoring/library/Monitoring/Command/MonitoringCommand.php new file mode 100644 index 000000000..d2cd90d16 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Command/MonitoringCommand.php @@ -0,0 +1,86 @@ +<?php +// {{{ICINGA_LICENSE_HEADER}}} +/** + * This file is part of Icinga 2 Web. + * + * Icinga 2 Web - Head for multiple monitoring backends. + * Copyright (C) 2013 Icinga Development Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @copyright 2013 Icinga Development Team <info@icinga.org> + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team <info@icinga.org> + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Monitoring\Command; + +use \Icinga\Protocol\Commandpipe\Command; +use \Icinga\Protocol\Commandpipe\Comment; + +abstract class MonitoringCommand implements Command +{ + /** + * The hostname for this command + * + * @var string + */ + protected $hostname; + + /** + * The service description for this command + * + * @var string + */ + protected $service_description; + + /** + * The comment associated to this command + * + * @var Comment + */ + protected $comment; + + /** + * @see Command::setHost() + */ + public function setHost($hostname) + { + $this->hostname = $hostname; + return $this; + } + + /** + * @see Command::setService() + */ + public function setService($service_description) + { + $this->service_description = $service_description; + return $this; + } + + /** + * Set the comment for this command + * + * @param Comment $comment + * @return self + */ + public function setComment(Comment $comment) + { + $this->comment = $comment; + return $this; + } +} \ No newline at end of file