2014-10-20 10:26:06 -04:00
|
|
|
<?php
|
|
|
|
|
|
2014-11-30 09:56:58 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Clicommands;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
use Icinga\Cli\Command;
|
2015-02-06 19:27:39 -05:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
class CheckCommand extends Command
|
|
|
|
|
{
|
2015-02-06 19:27:39 -05:00
|
|
|
protected $storage;
|
2014-10-20 10:26:06 -04:00
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
2015-02-06 19:27:39 -05:00
|
|
|
// WTF? I do not want to have to take care about this!!
|
|
|
|
|
$this->app->setupZendAutoloader();
|
|
|
|
|
|
2014-10-20 10:26:06 -04:00
|
|
|
$this->app->getModuleManager()->loadModule('monitoring');
|
2015-02-06 19:27:39 -05:00
|
|
|
$this->storage = new LegacyStorage($this->Config()->getSection('global'));
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check a specific process
|
|
|
|
|
*
|
2015-02-06 19:27:39 -05:00
|
|
|
* USAGE
|
|
|
|
|
*
|
|
|
|
|
* icingacli businessprocess check process [--config <name>] <process>
|
2014-10-20 10:26:06 -04:00
|
|
|
*/
|
|
|
|
|
public function processAction()
|
2015-02-06 19:27:39 -05:00
|
|
|
{
|
|
|
|
|
$name = $this->params->get('config');
|
|
|
|
|
if ($name === null) {
|
|
|
|
|
$name = $this->getFirstProcessName();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-06 19:27:39 -05:00
|
|
|
$bp = $this->storage->loadProcess($name);
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-02-06 19:27:39 -05:00
|
|
|
if (null !== ($stateType = $this->params->get('state-type'))) {
|
|
|
|
|
if ($stateType === 'soft') {
|
|
|
|
|
$bp->useSoftStates();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
2015-02-06 19:27:39 -05:00
|
|
|
if ($stateType === 'hard') {
|
|
|
|
|
$bp->useHardStates();
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-06 19:27:39 -05:00
|
|
|
$node = $bp->getNode($this->params->shift());
|
|
|
|
|
$bp->retrieveStatesFromBackend();
|
|
|
|
|
printf("Business Process %s: %s\n", $node->getStateName(), $node->getAlias());
|
|
|
|
|
exit($node->getState());
|
|
|
|
|
}
|
2014-10-20 10:26:06 -04:00
|
|
|
|
2015-02-06 19:27:39 -05:00
|
|
|
protected function getFirstProcessName()
|
|
|
|
|
{
|
|
|
|
|
$list = $this->storage->listProcesses();
|
|
|
|
|
return key($list);
|
2014-10-20 10:26:06 -04:00
|
|
|
}
|
|
|
|
|
}
|