2014-11-30 06:22:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Forms;
|
2014-11-30 06:22:11 -05:00
|
|
|
|
|
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
use Icinga\Web\Request;
|
|
|
|
|
use Icinga\Web\Notification;
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2014-11-30 06:22:11 -05:00
|
|
|
|
|
|
|
|
class SimulationForm extends Form
|
|
|
|
|
{
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
|
|
protected $process;
|
|
|
|
|
|
|
|
|
|
protected $node;
|
|
|
|
|
|
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
|
|
public function __construct($options = null)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($options);
|
|
|
|
|
$this->setup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
|
|
|
|
$this->addElement('select', 'state', array(
|
|
|
|
|
'label' => $this->translate('State'),
|
|
|
|
|
'multiOptions' => array(
|
|
|
|
|
'' => $this->translate('Use current state'),
|
|
|
|
|
'0' => $this->translate('OK'),
|
|
|
|
|
'1' => $this->translate('WARNING'),
|
|
|
|
|
'2' => $this->translate('CRITICAL'),
|
|
|
|
|
'3' => $this->translate('UNKNOWN'),
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->addElement('text', 'output', array(
|
|
|
|
|
'label' => $this->translate('Plugin output'),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->addElement('checkbox', 'acknowledged', array(
|
|
|
|
|
'label' => $this->translate('Acknowledged'),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->addElement('checkbox', 'in_downtime', array(
|
|
|
|
|
'label' => $this->translate('In downtime'),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$this->addElement('submit', $this->translate('Apply'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setBackend($backend)
|
|
|
|
|
{
|
|
|
|
|
$this->backend = $backend;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setProcess($process)
|
|
|
|
|
{
|
|
|
|
|
$this->process = $process;
|
2015-02-06 19:25:37 -05:00
|
|
|
$this->setBackend($process->getBackend());
|
2014-11-30 06:22:11 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setNode($node)
|
|
|
|
|
{
|
|
|
|
|
$this->node = $node;
|
|
|
|
|
$this->setDefaults(array(
|
|
|
|
|
// TODO: extend descr 'state' => (string) $node->getState(),
|
|
|
|
|
'acknowledged' => $node->isAcknowledged(),
|
|
|
|
|
'in_downtime' => $node->isInDowntime(),
|
|
|
|
|
));
|
|
|
|
|
return $this->checkNodeSession();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setSession($session)
|
|
|
|
|
{
|
|
|
|
|
$this->session = $session;
|
|
|
|
|
return $this->checkNodeSession();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function checkNodeSession()
|
|
|
|
|
{
|
|
|
|
|
if ($this->node === null || $this->session === null) {
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$simulations = $this->session->get('simulations', array());
|
|
|
|
|
$node = (string) $this->node;
|
|
|
|
|
if (array_key_exists($node, $simulations)) {
|
|
|
|
|
$this->setDefaults(array(
|
|
|
|
|
'simulate' => true,
|
|
|
|
|
'state' => $simulations[$node]->state,
|
|
|
|
|
'in_downtime' => $simulations[$node]->in_downtime,
|
|
|
|
|
'acknowledged' => $simulations[$node]->acknowledged,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function onSuccess()
|
|
|
|
|
{
|
|
|
|
|
$node = (string) $this->node;
|
|
|
|
|
$simulations = $this->session->get('simulations', array());
|
|
|
|
|
|
|
|
|
|
if ($this->getValue('state') === '') {
|
|
|
|
|
if (array_key_exists($node, $simulations)) {
|
|
|
|
|
Notification::success($this->translate('Simulation has been removed'));
|
|
|
|
|
unset($simulations[$node]);
|
|
|
|
|
$this->session->set('simulations', $simulations);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$simulations[$node] = (object) array(
|
|
|
|
|
'state' => $this->getValue('state'),
|
|
|
|
|
'acknowledged' => $this->getValue('acknowledged'),
|
|
|
|
|
'in_downtime' => $this->getValue('in_downtime'),
|
|
|
|
|
);
|
|
|
|
|
$this->session->set('simulations', $simulations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|