Restructure dispatch process of commands

refs #4580
This commit is contained in:
Johannes Meyer 2013-09-03 14:49:36 +02:00 committed by Jannis Moßhammer
parent 95d7a8a553
commit 79eb6588c5
3 changed files with 161 additions and 2 deletions

View File

@ -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();
}

View File

@ -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
*

View File

@ -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;
}
}