Do not break sidebar if processes cannot be loaded

fixes #466
This commit is contained in:
Johannes Meyer 2025-06-30 10:04:19 +02:00
parent ccf2ba4c66
commit a6033491f4
2 changed files with 41 additions and 25 deletions

View file

@ -3,8 +3,10 @@
namespace Icinga\Module\Businessprocess\Web\Navigation\Renderer;
use Icinga\Module\Businessprocess\Node;
use Icinga\Application\Logger;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
use Throwable;
class ProcessProblemsBadge extends BadgeNavigationItemRenderer
{
@ -20,22 +22,29 @@ class ProcessProblemsBadge extends BadgeNavigationItemRenderer
public function getCount()
{
$count = 0;
if ($this->count === null) {
$storage = LegacyStorage::getInstance();
$bp = $storage->loadProcess($this->getBpConfigName());
foreach ($bp->getRootNodes() as $rootNode) {
if (! $rootNode->isEmpty() &&
! in_array($rootNode->getState(), [Node::ICINGA_OK, Node::ICINGA_PENDING], true)) {
$count++;
$count = 0;
try {
$storage = LegacyStorage::getInstance();
// State is not applied here, because it's already done in ProcessesProblemsBadge.
// It runs earlier as it is part of the parent menu entry. Do we rely on an implementation detail here?
// Probably, but it is how it is for a very long time. So it is unlikely to change. (Finger crossed.)
$bp = $storage->loadProcess($this->getBpConfigName());
foreach ($bp->getRootNodes() as $rootNode) {
if (! $rootNode->isEmpty() &&
! in_array($rootNode->getState(), [Node::ICINGA_OK, Node::ICINGA_PENDING], true)) {
$count++;
}
}
} catch (Throwable $e) {
Logger::error('Failed to load business process "%s": %s', $this->getBpConfigName(), $e);
}
$this->count = $count;
$this->setState(self::STATE_CRITICAL);
}
if ($count) {
$this->setState(self::STATE_CRITICAL);
$this->setTitle(sprintf(
tp('One unhandled root node critical', '%d unhandled root nodes critical', $count),
$count

View file

@ -2,6 +2,7 @@
namespace Icinga\Module\Businessprocess\Web\Navigation\Renderer;
use Icinga\Application\Logger;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
@ -9,6 +10,7 @@ use Icinga\Module\Businessprocess\State\IcingaDbState;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
use Throwable;
class ProcessesProblemsBadge extends BadgeNavigationItemRenderer
{
@ -22,26 +24,31 @@ class ProcessesProblemsBadge extends BadgeNavigationItemRenderer
public function getCount()
{
if ($this->count === null) {
$storage = LegacyStorage::getInstance();
$count = 0;
foreach ($storage->listProcessNames() as $processName) {
$bp = $storage->loadProcess($processName);
if (Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {
MonitoringState::apply($bp);
}
try {
$storage = LegacyStorage::getInstance();
foreach ($bp->getRootNodes() as $rootNode) {
if (! $rootNode->isEmpty() &&
! in_array($rootNode->getState(), [Node::ICINGA_OK, Node::ICINGA_PENDING], true)) {
$count++;
break;
foreach ($storage->listProcessNames() as $processName) {
$bp = $storage->loadProcess($processName);
if (Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {
MonitoringState::apply($bp);
}
foreach ($bp->getRootNodes() as $rootNode) {
if (! $rootNode->isEmpty() &&
! in_array($rootNode->getState(), [Node::ICINGA_OK, Node::ICINGA_PENDING], true)) {
$count++;
break;
}
}
}
} catch (Throwable $e) {
Logger::error('Failed to load business processes: %s', $e);
}
$this->count = $count;