mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
CLI: Add options --blame and --root-cause
This commit is contained in:
parent
8ee87ec1f6
commit
1414e76d94
2 changed files with 44 additions and 0 deletions
|
|
@ -75,6 +75,12 @@ class ProcessCommand extends Command
|
|||
* --state-type <type> Define which state type to look at. Could be
|
||||
* either soft or hard, overrides an eventually
|
||||
* configured default
|
||||
* --blame Show problem details as a tree reduced to the
|
||||
* nodes which have the same state as the business
|
||||
* process
|
||||
* --root-cause Used in combination with --blame. Only shows
|
||||
* the path of the nodes which are responsible for
|
||||
* the state of the business process
|
||||
*/
|
||||
public function checkAction()
|
||||
{
|
||||
|
|
@ -110,6 +116,12 @@ class ProcessCommand extends Command
|
|||
if ($this->params->shift('details')) {
|
||||
echo $this->renderProblemTree($node->getProblemTree(), $this->params->shift('colors'));
|
||||
}
|
||||
if ($this->params->shift('blame')) {
|
||||
echo $this->renderProblemTree(
|
||||
$node->getProblemTreeBlame($this->params->shift('root-cause')),
|
||||
$this->params->shift('colors')
|
||||
);
|
||||
}
|
||||
|
||||
exit($node->getState());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,38 @@ class BpNode extends Node
|
|||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the problem nodes as tree reduced to the nodes which have the same state as the business process
|
||||
*
|
||||
* @param bool $rootCause Reduce nodes to the nodes which are responsible for the state of the business process
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProblemTreeBlame($rootCause = false)
|
||||
{
|
||||
$tree = [];
|
||||
$nodeState = $this->getState();
|
||||
|
||||
if ($nodeState !== 0) {
|
||||
foreach ($this->getChildren() as $child) {
|
||||
$childState = $rootCause ? $child->getSortingState() : $child->getState();
|
||||
if (($rootCause ? $this->getSortingState() : $nodeState) === $childState) {
|
||||
$name = $child->getName();
|
||||
$tree[$name] = [
|
||||
'children' => [],
|
||||
'node' => $child
|
||||
];
|
||||
if ($child instanceof BpNode) {
|
||||
$tree[$name]['children'] = $child->getProblemTreeBlame($rootCause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
public function isMissing()
|
||||
{
|
||||
if ($this->missing === null) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue