diff --git a/library/Icingadb/Model/RedundancyGroupState.php b/library/Icingadb/Model/RedundancyGroupState.php index df30f581e..e37327939 100644 --- a/library/Icingadb/Model/RedundancyGroupState.php +++ b/library/Icingadb/Model/RedundancyGroupState.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Icingadb\Model; use DateTime; +use Icinga\Module\Icingadb\Common\Icons; use ipl\Orm\Behavior\Binary; use ipl\Orm\Behavior\BoolCast; use ipl\Orm\Behavior\MillisecondTimestamp; @@ -12,6 +13,7 @@ use ipl\Orm\Model; use ipl\Orm\Query; use ipl\Orm\Relations; +use ipl\Web\Widget\Icon; /** * Redundancy group state model. @@ -19,6 +21,7 @@ * @property string $id * @property string $redundancy_group_id * @property bool $failed + * @property bool $is_reachable * @property DateTime $last_state_change * * @property RedundancyGroup|Query $redundancy_group @@ -40,6 +43,7 @@ public function getColumns(): array return [ 'redundancy_group_id', 'failed', + 'is_reachable', 'last_state_change' ]; } @@ -51,7 +55,8 @@ public function createBehaviors(Behaviors $behaviors): void 'redundancy_group_id' ])); $behaviors->add(new BoolCast([ - 'failed' + 'failed', + 'is_reachable' ])); $behaviors->add(new MillisecondTimestamp([ 'last_state_change' @@ -63,9 +68,29 @@ public function createRelations(Relations $relations): void $relations->belongsTo('redundancy_group', RedundancyGroup::class); } + /** + * Get the state text for the redundancy group state + * + * Do not use this method to label the state of a redundancy group. + * + * @return string + */ public function getStateText(): string { - // The method should only be called to fake state balls and not to show the group's state - return $this->failed ? 'unreachable' : 'reachable'; + return $this->failed ? 'critical' : 'ok'; + } + + /** + * Get the state icon + * + * @return ?Icon + */ + public function getIcon(): ?Icon + { + if (! $this->is_reachable) { + return new Icon(Icons::UNREACHABLE); + } + + return null; } } diff --git a/library/Icingadb/Model/UnreachableParent.php b/library/Icingadb/Model/UnreachableParent.php index c984fddd4..49062ed84 100644 --- a/library/Icingadb/Model/UnreachableParent.php +++ b/library/Icingadb/Model/UnreachableParent.php @@ -92,10 +92,23 @@ public static function on(Connection $db, Model $root = null): Query self::selectNodes($db, $root), 'unreachable_parent', true - )->where([ - 'unreachable_parent.level > ?' => 0, - 'unreachable_parent.is_group_member = ?' => 0 - ]); + ); + + $query->filter(Filter::all( + Filter::greaterThan('level', 0), + Filter::equal('is_group_member', 0), + Filter::any( + Filter::equal('service.state.affects_children', 'y'), + Filter::all( + Filter::unlike('service_id', '*'), + Filter::equal('host.state.affects_children', 'y') + ), + Filter::all( + Filter::equal('redundancy_group.state.failed', 'y'), + Filter::equal('redundancy_group.state.is_reachable', 'y') + ) + ) + )); return $query; } diff --git a/library/Icingadb/Widget/Detail/RedundancyGroupDetail.php b/library/Icingadb/Widget/Detail/RedundancyGroupDetail.php index 1c07e4c13..8e7f4f593 100644 --- a/library/Icingadb/Widget/Detail/RedundancyGroupDetail.php +++ b/library/Icingadb/Widget/Detail/RedundancyGroupDetail.php @@ -63,7 +63,7 @@ protected function createExtensions(): array */ protected function createRootProblems(): ?array { - if (! $this->group->state->failed) { + if ($this->group->state->is_reachable) { return null; } diff --git a/library/Icingadb/Widget/Detail/RedundancyGroupHeader.php b/library/Icingadb/Widget/Detail/RedundancyGroupHeader.php index 12154c348..d98c7b0f5 100644 --- a/library/Icingadb/Widget/Detail/RedundancyGroupHeader.php +++ b/library/Icingadb/Widget/Detail/RedundancyGroupHeader.php @@ -29,7 +29,10 @@ public function __construct(RedundancyGroup $object, RedundancyGroupSummary $sum protected function assembleVisual(BaseHtmlElement $visual): void { - $visual->addHtml(new StateBall($this->object->state->getStateText(), $this->getStateBallSize())); + $stateBall = new StateBall($this->object->state->getStateText(), $this->getStateBallSize()); + $stateBall->add($this->object->state->getIcon()); + + $visual->addHtml($stateBall); } protected function assembleTitle(BaseHtmlElement $title): void diff --git a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php index eca3c9271..7b56f5cac 100644 --- a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php +++ b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php @@ -62,7 +62,10 @@ protected function createSubject(): Link protected function assembleVisual(BaseHtmlElement $visual): void { - $visual->addHtml(new StateBall($this->state->getStateText(), $this->getStateBallSize())); + $stateBall = new StateBall($this->state->getStateText(), $this->getStateBallSize()); + $stateBall->add($this->state->getIcon()); + + $visual->addHtml($stateBall); } protected function assembleCaption(BaseHtmlElement $caption): void diff --git a/public/css/common.less b/public/css/common.less index 3a28d03b0..8d314741a 100644 --- a/public/css/common.less +++ b/public/css/common.less @@ -412,13 +412,3 @@ form[name="form_confirm_removal"] { padding: 0 0.25em; .rounded-corners(); } - -.state-ball { - &.state-unreachable { - background-color: @color-critical; - } - - &.state-reachable { - background-color: @color-ok; - } -}