2014-11-30 05:54:46 -05:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
namespace Icinga\Module\Businessprocess;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2015-01-21 03:22:25 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2014-11-30 05:54:46 -05:00
|
|
|
use Icinga\Web\Controller\ModuleActionController;
|
|
|
|
|
use Icinga\Module\Monitoring\Backend;
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
|
|
|
|
use Icinga\Module\Businessprocess\BusinessProcess;
|
|
|
|
|
use Icinga\Module\Businessprocess\Form\ProcessForm;
|
|
|
|
|
use Icinga\Module\Businessprocess\Form\SimulationForm;
|
2014-11-30 05:54:46 -05:00
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
use Icinga\Web\Widget;
|
2014-12-03 04:19:37 -05:00
|
|
|
use Exception;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
|
|
|
|
class Controller extends ModuleActionController
|
|
|
|
|
{
|
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
|
|
protected $views;
|
|
|
|
|
|
|
|
|
|
protected $aliases;
|
|
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
2015-01-21 03:22:25 -05:00
|
|
|
$m = Icinga::app()->getModuleManager();
|
|
|
|
|
if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) {
|
|
|
|
|
$m->loadModule('monitoring');
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:54:46 -05:00
|
|
|
$this->config = $this->Config();
|
|
|
|
|
$this->prepareBackend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tabs()
|
|
|
|
|
{
|
|
|
|
|
$url = Url::fromRequest();
|
|
|
|
|
$tabs = Widget::create('tabs')->add('show', array(
|
|
|
|
|
'title' => $this->translate('Show'),
|
2014-11-30 09:56:58 -05:00
|
|
|
'url' => 'businessprocess/process/show',
|
2014-11-30 05:54:46 -05:00
|
|
|
));
|
|
|
|
|
if ($process = $this->params->get('process')) {
|
|
|
|
|
foreach ($tabs->getTabs() as $tab) {
|
|
|
|
|
$tab->setUrlParams(array('process' => $process));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $tabs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function session()
|
|
|
|
|
{
|
2014-11-30 09:56:58 -05:00
|
|
|
return $this->Window()->getSessionNamespace('businessprocess');
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function loadBp()
|
|
|
|
|
{
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
|
|
$bp = $storage->loadProcess($process);
|
|
|
|
|
|
|
|
|
|
if ($this->_getParam('state_type') === 'soft'
|
|
|
|
|
|| (isset($bpconf->states) && $bpconf->states === 'soft')) {
|
|
|
|
|
$bp->useSoftStates();
|
|
|
|
|
}
|
2014-12-02 05:34:34 -05:00
|
|
|
$bp->retrieveStatesFromBackend($this->backend);
|
2014-11-30 05:54:46 -05:00
|
|
|
return $bp;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
protected function loadSlas()
|
|
|
|
|
{
|
|
|
|
|
$bpconf = $this->bpconf;
|
|
|
|
|
|
|
|
|
|
if (! isset($bpconf->slahosts)) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: This doesn't work right now
|
|
|
|
|
$sla_hosts = preg_split('~\s*,s*~', $bpconf->slahosts, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
|
|
|
|
|
|
if (isset($bpconf->sla_year)) {
|
|
|
|
|
$start = mktime(0, 0, 0, 1, 1, $bpconf->sla_year);
|
|
|
|
|
$end = mktime(23, 59, 59, 1, 0, $bpconf->sla_year + 1);
|
|
|
|
|
} else {
|
|
|
|
|
$start = mktime(0, 0, 0, 1, 1, (int) date('Y'));
|
|
|
|
|
$end = null;
|
|
|
|
|
// Bis zum Jahresende hochrechnen:
|
|
|
|
|
// $end = mktime(23, 59, 59, 1, 0, (int) date('Y') + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->backend
|
|
|
|
|
->module('BpAddon')
|
|
|
|
|
->getBpSlaValues($sla_hosts, $start, $end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function prepareBackend()
|
|
|
|
|
{
|
|
|
|
|
if ($this->backend === null) {
|
|
|
|
|
$name = $this->config->get('global', 'default_backend');
|
|
|
|
|
if (isset($this->bpconf->backend)) {
|
|
|
|
|
$name = $this->bpconf->backend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->backend = Backend::createBackend($name);
|
|
|
|
|
}
|
|
|
|
|
return $this->backend;
|
|
|
|
|
}
|
|
|
|
|
}
|