mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-05-28 04:34:08 -04:00
CheckCommand: code cleanup, remove legacy code
This commit is contained in:
parent
85f566ee67
commit
de1ba2aa7c
1 changed files with 32 additions and 60 deletions
|
|
@ -3,85 +3,57 @@
|
|||
namespace Icinga\Module\Businessprocess\Clicommands;
|
||||
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Module\Businessprocess\BusinessProcess;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
||||
class CheckCommand extends Command
|
||||
{
|
||||
protected $config;
|
||||
protected $bpconf;
|
||||
protected $bpname;
|
||||
protected $views;
|
||||
protected $filename;
|
||||
protected $backend;
|
||||
protected $storage;
|
||||
|
||||
public function init()
|
||||
{
|
||||
// WTF? I do not want to have to take care about this!!
|
||||
$this->app->setupZendAutoloader();
|
||||
|
||||
$this->app->getModuleManager()->loadModule('monitoring');
|
||||
$this->config = $this->Config();
|
||||
$this->readConfig();
|
||||
$this->prepareBackend();
|
||||
$this->storage = new LegacyStorage($this->Config()->getSection('global'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a specific process
|
||||
*
|
||||
* Blabla
|
||||
* USAGE
|
||||
*
|
||||
* icingacli businessprocess check process [--config <name>] <process>
|
||||
*/
|
||||
public function processAction()
|
||||
{
|
||||
$bp = BusinessProcess::parse($this->filename);
|
||||
$node = $bp->getNode($this->params->shift());
|
||||
if ($this->params->get('soft-states')) {
|
||||
$bp->useSoftStates();
|
||||
{
|
||||
$name = $this->params->get('config');
|
||||
if ($name === null) {
|
||||
$name = $this->getFirstProcessName();
|
||||
}
|
||||
$bp->retrieveStatesFromBackend($this->backend);
|
||||
|
||||
$bp = $this->storage->loadProcess($name);
|
||||
|
||||
if (null !== ($stateType = $this->params->get('state-type'))) {
|
||||
if ($stateType === 'soft') {
|
||||
$bp->useSoftStates();
|
||||
}
|
||||
if ($stateType === 'hard') {
|
||||
$bp->useHardStates();
|
||||
}
|
||||
}
|
||||
|
||||
$bp->retrieveStatesFromBackend();
|
||||
|
||||
$node = $bp->getNode($this->params->shift());
|
||||
$bp->retrieveStatesFromBackend();
|
||||
printf("Business Process %s: %s\n", $node->getStateName(), $node->getAlias());
|
||||
exit($node->getState());
|
||||
|
||||
}
|
||||
|
||||
// TODO: Remove this
|
||||
protected function prepareBackend()
|
||||
protected function getFirstProcessName()
|
||||
{
|
||||
if ($this->backend === null) {
|
||||
$name = $this->config->{'global'}->get('default_backend');
|
||||
if (isset($this->bpconf->backend)) {
|
||||
$name = $this->bpconf->backend;
|
||||
}
|
||||
$this->backend = Backend::createBackend($name);
|
||||
}
|
||||
return $this->backend;
|
||||
}
|
||||
|
||||
// TODO: Remove this
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
$bpname = $this->params->get('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->bpname = $bpname;
|
||||
|
||||
$this->filename = $this->config->global->bp_config_dir
|
||||
. '/' . $this->bpconf->file . '.conf';
|
||||
$list = $this->storage->listProcesses();
|
||||
return key($list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue