2014-10-20 10:26:06 -04:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\Controller;
|
|
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
2015-03-03 04:50:19 -05:00
|
|
|
use Exception;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
class Businessprocess_ProcessController extends Controller
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2014-11-30 06:04:18 -05:00
|
|
|
public function showAction()
|
2014-10-20 10:26:06 -04:00
|
|
|
{
|
2014-11-30 06:04:18 -05:00
|
|
|
if ($this->getRequest()->isPost()) {
|
|
|
|
|
$this->redirectNow($this->getRequest()->getUrl()->with('processName', $this->getRequest()->getPost('processName')));
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-02-12 19:52:17 -05:00
|
|
|
$this->view->compact = $this->params->get('view') === 'compact';
|
2014-11-30 06:04:18 -05:00
|
|
|
$storage = new LegacyStorage($this->Config()->getSection('global'));
|
|
|
|
|
$this->view->processList = $storage->listProcesses();
|
|
|
|
|
$process = $this->params->get('processName', key($this->view->processList));
|
|
|
|
|
$this->view->processName = $process;
|
|
|
|
|
|
|
|
|
|
$this->view->tabs = $this->tabs()->activate('show');
|
|
|
|
|
$this->view->title = 'Business Processes';
|
2015-03-03 04:50:19 -05:00
|
|
|
|
|
|
|
|
$bp = $this->loadBp();
|
|
|
|
|
try {
|
|
|
|
|
$bp->retrieveStatesFromBackend();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$this->view->errors = array(
|
|
|
|
|
'Could not retrieve process state: ' . $e->getMessage()
|
|
|
|
|
);
|
|
|
|
|
}
|
2014-11-30 06:04:18 -05:00
|
|
|
if ($process = $this->params->get('process')) {
|
|
|
|
|
$this->view->bp = $bp->getNode($process);
|
|
|
|
|
} else {
|
|
|
|
|
$this->view->bp = $bp;
|
|
|
|
|
if ($bp->hasWarnings()) {
|
2015-01-28 13:50:52 -05:00
|
|
|
$this->view->warnings = $bp->getWarnings();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-11-30 06:04:18 -05:00
|
|
|
$this->setAutorefreshInterval(10);
|
2014-11-30 06:11:46 -05:00
|
|
|
|
2015-02-06 18:38:04 -05:00
|
|
|
if ($this->params->get('showSource')) {
|
|
|
|
|
$this->view->source = $bp->toLegacyConfigString();
|
|
|
|
|
$this->render('source');
|
|
|
|
|
}
|
2014-11-30 06:11:46 -05:00
|
|
|
if ($this->params->get('simulation')) {
|
|
|
|
|
$bp->setSimulationMode();
|
|
|
|
|
$this->addSimulation($bp);
|
|
|
|
|
}
|
2014-11-30 06:14:11 -05:00
|
|
|
|
|
|
|
|
if ($this->params->get('edit')) {
|
|
|
|
|
$bp->setEditMode();
|
|
|
|
|
}
|
2014-11-30 06:20:39 -05:00
|
|
|
|
2015-03-02 12:23:19 -05:00
|
|
|
if ($this->params->get('store')) {
|
|
|
|
|
$storage->storeProcess($bp);
|
|
|
|
|
$this->redirectNow($this->getRequest()->getUrl()->without('store'));
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 06:20:39 -05:00
|
|
|
if ($this->params->get('mode') === 'toplevel') {
|
|
|
|
|
$this->render('toplevel');
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 06:18:04 -05:00
|
|
|
}
|
2014-11-30 06:14:11 -05:00
|
|
|
|
2014-11-30 06:18:04 -05:00
|
|
|
protected function addSimulation($bp)
|
|
|
|
|
{
|
|
|
|
|
$simulations = $this->session()->get('simulations', array());
|
|
|
|
|
foreach ($simulations as $node => $s) {
|
|
|
|
|
$bp->getNode($node)
|
|
|
|
|
->setState($s->state)
|
|
|
|
|
->setAck($s->acknowledged)
|
|
|
|
|
->setDowntime($s->in_downtime);
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-01-28 13:50:52 -05:00
|
|
|
}
|