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-03-16 04:08:00 -04:00
|
|
|
use Exception;
|
2015-01-21 03:22:25 -05:00
|
|
|
use Icinga\Application\Icinga;
|
2014-11-30 09:56:58 -05:00
|
|
|
use Icinga\Module\Businessprocess\BusinessProcess;
|
|
|
|
|
use Icinga\Module\Businessprocess\Form\ProcessForm;
|
|
|
|
|
use Icinga\Module\Businessprocess\Form\SimulationForm;
|
2015-03-16 04:08:00 -04:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
|
|
|
|
use Icinga\Module\Monitoring\Backend;
|
|
|
|
|
use Icinga\Web\Controller as ModuleController;
|
|
|
|
|
use Icinga\Web\Notification;
|
2015-10-06 16:35:44 -04:00
|
|
|
use Icinga\Module\Director\Web\Form\FormLoader;
|
2014-11-30 05:54:46 -05:00
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
use Icinga\Web\Widget;
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
class Controller extends ModuleController
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
|
|
protected $backend;
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
private $storage;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
private $url;
|
2014-11-30 05:54:46 -05:00
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->errors = array();
|
2015-01-21 03:22:25 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->compact = $this->params->get('view') === 'compact';
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function url()
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
if ($this->url === null) {
|
|
|
|
|
$this->url = clone $this->getRequest()->getUrl();
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
return $this->url;
|
|
|
|
|
}
|
2015-02-12 19:53:28 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function tabs()
|
|
|
|
|
{
|
|
|
|
|
if ($this->view->tabs === null) {
|
|
|
|
|
$this->view->tabs = Widget::create('tabs');
|
|
|
|
|
}
|
|
|
|
|
return $this->view->tabs;
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function session()
|
|
|
|
|
{
|
2014-11-30 09:56:58 -05:00
|
|
|
return $this->Window()->getSessionNamespace('businessprocess');
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function setTitle($title)
|
2014-11-30 05:54:46 -05:00
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
$args = func_get_args();
|
|
|
|
|
array_shift($args);
|
|
|
|
|
$this->view->title = vsprintf($title, $args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function loadModifiedBpConfig()
|
|
|
|
|
{
|
|
|
|
|
$bp = $this->loadBpConfig();
|
|
|
|
|
$changes = ProcessChanges::construct($bp, $this->session());
|
|
|
|
|
if ($this->params->get('dismissChanges')) {
|
|
|
|
|
Notification::success(
|
|
|
|
|
sprintf(
|
|
|
|
|
$this->translate('%d pending change(s) have been dropped'),
|
|
|
|
|
$changes->count()
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$changes->clear();
|
|
|
|
|
$this->redirectNow($this->url()->without('dismissChanges')->without('unlocked'));
|
|
|
|
|
}
|
|
|
|
|
$bp->applyChanges($changes);
|
|
|
|
|
return $bp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function loadBpConfig()
|
|
|
|
|
{
|
|
|
|
|
$storage = $this->storage();
|
2014-11-30 05:54:46 -05:00
|
|
|
$this->view->processList = $storage->listProcesses();
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
// No process found? Go to welcome page
|
|
|
|
|
if (empty($this->view->processList)) {
|
|
|
|
|
$this->redirectNow('businessprocess');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$name = $this->params->get(
|
|
|
|
|
'config',
|
|
|
|
|
key($this->view->processList)
|
|
|
|
|
);
|
2014-11-30 05:54:46 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$modifications = $this->session()->get('modifications', array());
|
|
|
|
|
if (array_key_exists($name, $modifications)) {
|
|
|
|
|
$bp = $storage->loadFromString($name, $modifications[$name]);
|
|
|
|
|
} else {
|
|
|
|
|
$bp = $storage->loadProcess($name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allow URL parameter to override configured state type
|
2015-02-06 18:36:01 -05:00
|
|
|
if (null !== ($stateType = $this->params->get('state_type'))) {
|
|
|
|
|
if ($stateType === 'soft') {
|
|
|
|
|
$bp->useSoftStates();
|
|
|
|
|
}
|
2015-02-06 19:28:06 -05:00
|
|
|
if ($stateType === 'hard') {
|
2015-02-06 18:36:01 -05:00
|
|
|
$bp->useHardStates();
|
|
|
|
|
}
|
2014-11-30 05:54:46 -05:00
|
|
|
}
|
2015-02-06 18:36:01 -05:00
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
$this->view->bpconfig = $bp;
|
|
|
|
|
$this->view->configName = $bp->getName();
|
|
|
|
|
|
2014-11-30 05:54:46 -05:00
|
|
|
return $bp;
|
|
|
|
|
}
|
2015-02-06 18:36:01 -05:00
|
|
|
|
2015-10-06 16:35:44 -04:00
|
|
|
public function loadForm($name)
|
|
|
|
|
{
|
|
|
|
|
return FormLoader::load($name, $this->Module());
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-16 04:08:00 -04:00
|
|
|
protected function storage()
|
|
|
|
|
{
|
|
|
|
|
if ($this->storage === null) {
|
|
|
|
|
$this->storage = new LegacyStorage(
|
|
|
|
|
$this->Config()->getSection('global')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->storage;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 05:54:46 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|