2013-09-04 10:50:00 +02:00
|
|
|
<?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}}}
|
|
|
|
|
2013-09-16 14:39:14 +02:00
|
|
|
namespace Icinga\Protocol\Commandpipe;
|
2013-09-04 10:50:00 +02:00
|
|
|
|
2013-09-16 14:39:14 +02:00
|
|
|
use Icinga\Exception\ProgrammingError;
|
2013-09-04 10:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for any concrete command implementation
|
|
|
|
*/
|
2013-09-16 14:44:59 +02:00
|
|
|
abstract class Command
|
2013-09-04 10:50:00 +02:00
|
|
|
{
|
2013-09-05 16:02:09 +02:00
|
|
|
/**
|
|
|
|
* Whether hosts are ignored in case of a host- or servicegroup
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $withoutHosts = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether services are ignored in case of a host- or servicegroup
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $withoutServices = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether child hosts are going to be included in case of a host command
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $withChildren = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether only services are going to be included in case of a host command
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $onlyServices = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this command should only affect the services of a host- or servicegroup
|
|
|
|
*
|
|
|
|
* @param bool $state
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function excludeHosts($state = true)
|
|
|
|
{
|
|
|
|
$this->withoutHosts = (bool) $state;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this command should only affect the hosts of a host- or servicegroup
|
|
|
|
*
|
|
|
|
* @param bool $state
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function excludeServices($state = true)
|
|
|
|
{
|
|
|
|
$this->withoutServices = (bool) $state;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this command should also affect all children hosts of a host
|
|
|
|
*
|
|
|
|
* @param bool $state
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function includeChildren($state = true)
|
|
|
|
{
|
|
|
|
$this->withChildren = (bool) $state;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this command only affects those services beyond a host
|
|
|
|
*
|
|
|
|
* @param bool $state
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function excludeHost($state = true)
|
|
|
|
{
|
|
|
|
$this->onlyServices = (bool) $state;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-04 10:50:00 +02:00
|
|
|
/**
|
2013-09-16 14:39:14 +02:00
|
|
|
* Return this command's arguments in the order expected by the actual command definition
|
2013-09-04 10:50:00 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2013-09-16 14:39:14 +02:00
|
|
|
abstract public function getParameters();
|
2013-09-04 10:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the command as a string with the given host being inserted
|
|
|
|
*
|
|
|
|
* @param string $hostname The name of the host to insert
|
2013-09-05 10:54:48 +02:00
|
|
|
*
|
2013-09-04 10:50:00 +02:00
|
|
|
* @return string The string representation of the command
|
|
|
|
*/
|
2013-09-16 14:39:14 +02:00
|
|
|
abstract public function getHostCommand($hostname);
|
2013-09-04 10:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the command as a string with the given host and service being inserted
|
|
|
|
*
|
|
|
|
* @param string $hostname The name of the host to insert
|
|
|
|
* @param string $servicename The name of the service to insert
|
2013-09-05 10:54:48 +02:00
|
|
|
*
|
2013-09-04 10:50:00 +02:00
|
|
|
* @return string The string representation of the command
|
|
|
|
*/
|
2013-09-16 14:39:14 +02:00
|
|
|
abstract public function getServiceCommand($hostname, $servicename);
|
2013-09-04 10:50:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the command as a string with the given hostgroup being inserted
|
|
|
|
*
|
|
|
|
* @param string $hostgroup The name of the hostgroup to insert
|
2013-09-05 10:54:48 +02:00
|
|
|
*
|
2013-09-04 10:50:00 +02:00
|
|
|
* @return string The string representation of the command
|
|
|
|
*/
|
|
|
|
public function getHostgroupCommand($hostgroup)
|
|
|
|
{
|
2013-09-16 14:39:14 +02:00
|
|
|
throw new ProgrammingError(get_class($this) . ' does not provide a hostgroup command');
|
2013-09-04 10:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the command as a string with the given servicegroup being inserted
|
|
|
|
*
|
|
|
|
* @param string $servicegroup The name of the servicegroup to insert
|
2013-09-05 10:54:48 +02:00
|
|
|
*
|
2013-09-04 10:50:00 +02:00
|
|
|
* @return string The string representation of the command
|
|
|
|
*/
|
|
|
|
public function getServicegroupCommand($servicegroup)
|
|
|
|
{
|
2013-09-16 14:39:14 +02:00
|
|
|
throw new ProgrammingError(get_class($this) . ' does not provide a servicegroup command');
|
2013-09-04 10:50:00 +02:00
|
|
|
}
|
2013-09-04 18:07:24 +02:00
|
|
|
}
|