mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-01-03 04:09:35 -05:00
ProcessController: get rid of legacy logic
This commit is contained in:
parent
1bbaf99938
commit
0e710f9d4d
1 changed files with 21 additions and 116 deletions
|
|
@ -1,88 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Web\Controller\ModuleActionController;
|
||||
use Icinga\Module\Bpapp\BusinessProcess;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Web\Widget;
|
||||
use Icinga\Module\Bpapp\Controller;
|
||||
use Icinga\Module\Bpapp\Storage\LegacyStorage;
|
||||
|
||||
class Bpapp_ProcessController extends ModuleActionController
|
||||
class Bpapp_ProcessController extends Controller
|
||||
{
|
||||
protected $backend;
|
||||
protected $views;
|
||||
protected $aliases;
|
||||
protected $bpname;
|
||||
protected $bpconf;
|
||||
protected $filename;
|
||||
|
||||
public function init()
|
||||
public function showAction()
|
||||
{
|
||||
// $this->requireJs('bpaddon.js');
|
||||
$this->config = Config::module('bpapp');
|
||||
$this->readConfig();
|
||||
$this->prepareBackend();
|
||||
$this->view->showMenu = $this->_getParam('menu', 'enabled') === 'enabled';
|
||||
$this->view->tabs = $this->createTabs();
|
||||
}
|
||||
|
||||
protected function prepareBackend()
|
||||
{
|
||||
if ($this->backend === null) {
|
||||
$name = $this->config->{'global'}->default_backend;
|
||||
if (isset($this->bpconf->backend)) {
|
||||
$name = $this->bpconf->backend;
|
||||
}
|
||||
$this->view->backend = $name;
|
||||
$this->backend = Backend::createBackend($name);
|
||||
if ($this->getRequest()->isPost()) {
|
||||
$this->redirectNow($this->getRequest()->getUrl()->with('processName', $this->getRequest()->getPost('processName')));
|
||||
}
|
||||
return $this->backend;
|
||||
}
|
||||
$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;
|
||||
|
||||
protected function createTabs()
|
||||
{
|
||||
// $tabs = $this->widget('tabs');
|
||||
$tabs = Widget::create('tabs');
|
||||
$action = $this->_request->getActionName();
|
||||
foreach ($this->views as $bpname => $bpconf) {
|
||||
$tabs->add($bpname, array(
|
||||
'url' => 'bpapp/process/' . $action,
|
||||
'urlParams' => array('bp' => $bpname),
|
||||
'title' => $bpconf->title,
|
||||
));
|
||||
}
|
||||
$tabs->activate($this->bpname);
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
protected function readConfig()
|
||||
{
|
||||
$this->views = array();
|
||||
$this->aliases = array();
|
||||
foreach ($this->config as $key => $val) {
|
||||
if (! preg_match('~^view-(.+)$~', $key, $match)) continue;
|
||||
$this->views[$match[1]] = (object) $val->toArray();
|
||||
$this->aliases[(string) $val->title] = $match[1];
|
||||
if ($val->aliases) {
|
||||
foreach (preg_split('~\s*,\s*~', $val->aliases, -1, PREG_SPLIT_NO_EMPTY) as $alias) {
|
||||
$this->aliases[$alias] = $match[1];
|
||||
}
|
||||
$this->view->tabs = $this->tabs()->activate('show');
|
||||
$this->view->title = 'Business Processes';
|
||||
$bp = $this->loadBp();
|
||||
if ($process = $this->params->get('process')) {
|
||||
$this->view->bp = $bp->getNode($process);
|
||||
} else {
|
||||
$this->view->bp = $bp;
|
||||
if ($bp->hasWarnings()) {
|
||||
$this->view->warnings = $bp->getWarings();
|
||||
}
|
||||
}
|
||||
$this->view->views = $this->views;
|
||||
$bpname = $this->_getParam('bp', key($this->views));
|
||||
|
||||
if (array_key_exists($bpname, $this->aliases)) {
|
||||
$bpname = $this->aliases[$bpname];
|
||||
}
|
||||
if (! array_key_exists($bpname, $this->views)) {
|
||||
throw new Exception('Got invalid bp name: ' . $bpname);
|
||||
}
|
||||
$this->bpconf = $this->views[$bpname];
|
||||
$this->view->bpname = $bpname;
|
||||
$this->bpname = $bpname;
|
||||
|
||||
$this->filename = $this->config->global->bp_config_dir
|
||||
. '/' . $this->bpconf->file . '.conf';
|
||||
$this->setAutorefreshInterval(10);
|
||||
}
|
||||
|
||||
public function sourceAction()
|
||||
|
|
@ -98,43 +42,4 @@ class Bpapp_ProcessController extends ModuleActionController
|
|||
echo '<pre>' . print_r($bp, 1) . '</pre>';
|
||||
exit;
|
||||
}
|
||||
|
||||
public function showAction()
|
||||
{
|
||||
$this->setAutoRefreshInterval(10);
|
||||
|
||||
$this->view->opened = $this->_getParam('opened');
|
||||
$this->view->compact = $this->_getParam('view') === 'compact';
|
||||
$bpconf = $this->bpconf;
|
||||
$this->view->title = 'Process: ' . $bpconf->title;
|
||||
|
||||
$bp = BusinessProcess::parse($this->filename);
|
||||
if ($this->_getParam('state_type') === 'soft'
|
||||
|| (isset($bpconf->states) && $bpconf->states === 'soft')) {
|
||||
$bp->useSoftStates();
|
||||
}
|
||||
$bp->retrieveStatesFromBackend($this->backend);
|
||||
$this->view->bp = $bp;
|
||||
|
||||
if (isset($bpconf->slahosts)) {
|
||||
$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);
|
||||
}
|
||||
$this->view->slas = $this->backend
|
||||
->module('BpAddon')
|
||||
->getBpSlaValues($sla_hosts, $start, $end);
|
||||
} else {
|
||||
$this->view->slas = array();
|
||||
}
|
||||
|
||||
$this->view->available_bps = $this->views;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue