2014-09-01 15:00:20 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-01 15:00:20 +02:00
|
|
|
|
2014-11-14 11:17:22 +01:00
|
|
|
namespace Icinga\Module\Monitoring\Forms\Command;
|
2014-09-01 15:00:20 +02:00
|
|
|
|
2015-08-31 09:28:42 +02:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
2014-09-01 15:00:20 +02:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
use Icinga\Web\Request;
|
2015-08-31 09:28:42 +02:00
|
|
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
|
|
|
use Icinga\Module\Monitoring\Command\Transport\CommandTransport;
|
|
|
|
use Icinga\Module\Monitoring\Command\Transport\CommandTransportInterface;
|
2014-09-01 15:00:20 +02:00
|
|
|
|
|
|
|
/**
|
2014-09-02 09:55:38 +02:00
|
|
|
* Base class for command forms
|
2014-09-01 15:00:20 +02:00
|
|
|
*/
|
2014-09-02 09:55:38 +02:00
|
|
|
abstract class CommandForm extends Form
|
2014-09-01 15:00:20 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Monitoring backend
|
|
|
|
*
|
2015-07-28 12:20:03 +02:00
|
|
|
* @var MonitoringBackend
|
2014-09-01 15:00:20 +02:00
|
|
|
*/
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the monitoring backend
|
|
|
|
*
|
2014-11-12 00:20:37 +01:00
|
|
|
* @param MonitoringBackend $backend
|
2014-09-01 15:00:20 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
2014-11-12 00:20:37 +01:00
|
|
|
public function setBackend(MonitoringBackend $backend)
|
2014-09-01 15:00:20 +02:00
|
|
|
{
|
|
|
|
$this->backend = $backend;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the monitoring backend
|
|
|
|
*
|
2015-07-28 12:20:03 +02:00
|
|
|
* @return MonitoringBackend
|
2014-09-01 15:00:20 +02:00
|
|
|
*/
|
|
|
|
public function getBackend()
|
|
|
|
{
|
|
|
|
return $this->backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the transport used to send commands
|
|
|
|
*
|
2015-08-31 09:28:42 +02:00
|
|
|
* @param Request $request
|
|
|
|
*
|
|
|
|
* @return CommandTransportInterface
|
2014-09-01 15:00:20 +02:00
|
|
|
*
|
2015-08-31 09:28:42 +02:00
|
|
|
* @throws ConfigurationError
|
2014-09-01 15:00:20 +02:00
|
|
|
*/
|
|
|
|
public function getTransport(Request $request)
|
|
|
|
{
|
2015-08-31 09:28:42 +02:00
|
|
|
if (($transportName = $request->getParam('transport')) !== null) {
|
|
|
|
$config = CommandTransport::getConfig();
|
|
|
|
if ($config->hasSection($transportName)) {
|
|
|
|
$transport = CommandTransport::createTransport($config->getSection($transportName));
|
|
|
|
} else {
|
|
|
|
throw new ConfigurationError(sprintf(
|
|
|
|
mt('monitoring', 'Command transport "%s" not found.'),
|
|
|
|
$transportName
|
|
|
|
));
|
|
|
|
}
|
2014-09-01 15:00:20 +02:00
|
|
|
} else {
|
2015-08-31 09:28:42 +02:00
|
|
|
$transport = new CommandTransport();
|
2014-09-01 15:00:20 +02:00
|
|
|
}
|
2015-08-31 09:28:42 +02:00
|
|
|
|
2014-09-01 15:00:20 +02:00
|
|
|
return $transport;
|
|
|
|
}
|
|
|
|
}
|