2013-10-08 14:19:14 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
2013-10-23 15:10:33 +02:00
|
|
|
* This file is part of Icinga Web 2.
|
2013-10-08 14:19:14 +02:00
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
2013-10-08 14:19:14 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2013-10-23 15:10:33 +02:00
|
|
|
* @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>
|
|
|
|
*
|
2013-10-08 14:19:14 +02:00
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring\Form\Command;
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
use Zend_Controller_Request_Abstract;
|
2013-10-08 14:19:14 +02:00
|
|
|
use \Zend_Form_Element_Hidden;
|
|
|
|
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
|
|
|
use Icinga\Module\Monitoring\Command\SingleArgumentCommand;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sending commands to core which only have one value
|
|
|
|
*/
|
|
|
|
class SingleArgumentCommandForm extends CommandForm
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Name of host command
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $hostCommand;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of service command
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $serviceCommand;
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
/**
|
|
|
|
* Name of global command
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $globalCommands = array();
|
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
/**
|
|
|
|
* Name of the parameter used as value
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $parameterName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value of used parameter
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
private $parameterValue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag to ignore object name
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $ignoreObject = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set command names
|
|
|
|
*
|
|
|
|
* @param string $hostCommand Name of host command
|
|
|
|
* @param string $serviceCommand Name of service command
|
|
|
|
*/
|
|
|
|
public function setCommand($hostCommand, $serviceCommand = null)
|
|
|
|
{
|
|
|
|
$this->hostCommand = $hostCommand;
|
2013-10-19 13:24:36 +02:00
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
if ($serviceCommand !== null) {
|
|
|
|
$this->serviceCommand = $serviceCommand;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
/**
|
|
|
|
* Setter for global commands
|
|
|
|
*
|
|
|
|
* @param string $hostOrGenericGlobalCommand Generic command or one for host
|
|
|
|
* @param string $serviceGlobalCommand If any (leave blank if you need a global global)
|
|
|
|
*/
|
|
|
|
public function setGlobalCommands($hostOrGenericGlobalCommand, $serviceGlobalCommand = null)
|
|
|
|
{
|
|
|
|
$this->globalCommands[] = $hostOrGenericGlobalCommand;
|
|
|
|
|
|
|
|
if ($serviceGlobalCommand !== null) {
|
|
|
|
$this->globalCommands[] = $serviceGlobalCommand;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
/**
|
|
|
|
* Use an explicit value to send with command
|
|
|
|
*
|
|
|
|
* @param mixed $parameterValue
|
|
|
|
*/
|
|
|
|
public function setParameterValue($parameterValue)
|
|
|
|
{
|
|
|
|
$this->parameterValue = $parameterValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use a form field to take the value from
|
|
|
|
*
|
|
|
|
* @param string $parameterName
|
|
|
|
*/
|
|
|
|
public function setParameterName($parameterName)
|
|
|
|
{
|
|
|
|
$this->parameterName = $parameterName;
|
|
|
|
}
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
/**
|
|
|
|
* Flag to ignore every objects
|
|
|
|
*
|
|
|
|
* @param bool $flag
|
|
|
|
*/
|
2013-10-08 14:19:14 +02:00
|
|
|
public function setObjectIgnoreFlag($flag = true)
|
|
|
|
{
|
|
|
|
$this->ignoreObject = (bool) $flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function create()
|
|
|
|
{
|
|
|
|
if ($this->parameterName) {
|
|
|
|
$field = new Zend_Form_Element_Hidden($this->parameterName);
|
|
|
|
$value = $this->getRequest()->getParam($field->getName());
|
|
|
|
$field->setValue($value);
|
|
|
|
$this->addElement($field);
|
|
|
|
}
|
|
|
|
parent::create();
|
|
|
|
}
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
public function setRequest(Zend_Controller_Request_Abstract $request)
|
|
|
|
{
|
|
|
|
parent::setRequest($request);
|
|
|
|
|
|
|
|
if ($this->globalCommand === true) {
|
|
|
|
$this->setParameterName('global');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create command object for CommandPipe protocol
|
|
|
|
*
|
|
|
|
* @return SingleArgumentCommand
|
|
|
|
*/
|
|
|
|
public function createCommand()
|
|
|
|
{
|
|
|
|
$command = new SingleArgumentCommand();
|
|
|
|
|
|
|
|
if ($this->parameterValue !== null) {
|
|
|
|
$command->setValue($this->parameterValue);
|
|
|
|
} else {
|
|
|
|
$command->setValue($this->getValue($this->parameterName));
|
|
|
|
}
|
|
|
|
|
2013-10-19 13:24:36 +02:00
|
|
|
if ($this->provideGlobalCommand() == true) {
|
|
|
|
$command->setGlobalCommands($this->globalCommands);
|
|
|
|
$this->ignoreObject = true;
|
|
|
|
} else {
|
|
|
|
$command->setCommand($this->hostCommand, $this->serviceCommand);
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:19:14 +02:00
|
|
|
$command->setObjectIgnoreFlag($this->ignoreObject);
|
|
|
|
|
|
|
|
return $command;
|
|
|
|
}
|
|
|
|
}
|