From b8498c7b8317645323a0703b2426a75916a54733 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 23 Sep 2024 01:36:04 +0200 Subject: [PATCH] Indicate the number of affected children by a particular parent --- library/Icingadb/Common/Icons.php | 2 ++ library/Icingadb/Model/Host.php | 7 +++++-- library/Icingadb/Model/HostState.php | 3 ++- library/Icingadb/Model/Service.php | 7 +++++-- library/Icingadb/Model/ServiceState.php | 3 ++- library/Icingadb/Model/State.php | 7 +++++-- .../Icingadb/Widget/ItemList/StateListItem.php | 18 ++++++++++++++++++ public/css/common.less | 8 ++++++++ 8 files changed, 47 insertions(+), 8 deletions(-) diff --git a/library/Icingadb/Common/Icons.php b/library/Icingadb/Common/Icons.php index cac9f3249..c28127dfe 100644 --- a/library/Icingadb/Common/Icons.php +++ b/library/Icingadb/Common/Icons.php @@ -10,6 +10,8 @@ class Icons const HOST_DOWN = 'sitemap'; + const UNREACHABLE = 'sitemap'; + const IN_DOWNTIME = 'plug'; const IS_ACKNOWLEDGED = 'check'; diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index 1dc83be0e..05c35bc07 100644 --- a/library/Icingadb/Model/Host.php +++ b/library/Icingadb/Model/Host.php @@ -56,6 +56,7 @@ * @property ?string $zone_id * @property string $command_endpoint_name * @property ?string $command_endpoint_id + * @property ?int $affected_children */ class Host extends Model { @@ -111,7 +112,8 @@ public function getColumns() 'zone_name', 'zone_id', 'command_endpoint_name', - 'command_endpoint_id' + 'command_endpoint_id', + 'affected_children' ]; } @@ -155,7 +157,8 @@ public function getColumnDefinitions() 'zone_name' => t('Zone Name'), 'zone_id' => t('Zone Id'), 'command_endpoint_name' => t('Endpoint Name'), - 'command_endpoint_id' => t('Endpoint Id') + 'command_endpoint_id' => t('Endpoint Id'), + 'affected_children' => t('Affected Children'), ]; } diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index efa275285..c9500e5fe 100644 --- a/library/Icingadb/Model/HostState.php +++ b/library/Icingadb/Model/HostState.php @@ -53,7 +53,8 @@ public function getColumnDefinitions() 'last_update' => t('Host Last Update'), 'last_state_change' => t('Host Last State Change'), 'next_check' => t('Host Next Check'), - 'next_update' => t('Host Next Update') + 'next_update' => t('Host Next Update'), + 'affects_children' => t('Host Affects Children'), ]; } diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 5a0d52843..dea47a75d 100644 --- a/library/Icingadb/Model/Service.php +++ b/library/Icingadb/Model/Service.php @@ -51,6 +51,7 @@ * @property ?string $zone_id * @property string $command_endpoint_name * @property ?string $command_endpoint_id + * @property ?int $affected_children */ class Service extends Model { @@ -103,7 +104,8 @@ public function getColumns() 'zone_name', 'zone_id', 'command_endpoint_name', - 'command_endpoint_id' + 'command_endpoint_id', + 'affected_children' ]; } @@ -144,7 +146,8 @@ public function getColumnDefinitions() 'zone_name' => t('Zone Name'), 'zone_id' => t('Zone Id'), 'command_endpoint_name' => t('Endpoint Name'), - 'command_endpoint_id' => t('Endpoint Id') + 'command_endpoint_id' => t('Endpoint Id'), + 'affected_children' => t('Affected Children') ]; } diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 1d7dc31cd..a42a4e239 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -55,7 +55,8 @@ public function getColumnDefinitions() 'last_update' => t('Service Last Update'), 'last_state_change' => t('Service Last State Change'), 'next_check' => t('Service Next Check'), - 'next_update' => t('Service Next Update') + 'next_update' => t('Service Next Update'), + 'affects_children' => t('Service Affects Children'), ]; } diff --git a/library/Icingadb/Model/State.php b/library/Icingadb/Model/State.php index 4529c9b10..a4556c1d5 100644 --- a/library/Icingadb/Model/State.php +++ b/library/Icingadb/Model/State.php @@ -48,6 +48,7 @@ * @property DateTime $last_state_change The time when the node last got a status change * @property DateTime $next_check The time when the node will execute the next check * @property DateTime $next_update The time when the next check of the node is expected to end + * @property bool $affects_children Whether any of the children is affected if there is a problem */ abstract class State extends Model { @@ -98,7 +99,8 @@ public function getColumns() 'last_update', 'last_state_change', 'next_check', - 'next_update' + 'next_update', + 'affects_children' ]; } @@ -111,7 +113,8 @@ public function createBehaviors(Behaviors $behaviors) 'is_flapping', 'is_overdue', 'is_acknowledged', - 'in_downtime' + 'in_downtime', + 'affects_children' ])); $behaviors->add(new MillisecondTimestamp([ diff --git a/library/Icingadb/Widget/ItemList/StateListItem.php b/library/Icingadb/Widget/ItemList/StateListItem.php index cd8ff163e..adb68e586 100644 --- a/library/Icingadb/Widget/ItemList/StateListItem.php +++ b/library/Icingadb/Widget/ItemList/StateListItem.php @@ -13,6 +13,7 @@ use ipl\Html\HtmlElement; use ipl\Web\Common\BaseListItem; use ipl\Web\Widget\EmptyState; +use ipl\Web\Widget\StateBadge; use ipl\Web\Widget\TimeSince; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; @@ -93,6 +94,23 @@ protected function assembleTitle(BaseHtmlElement $title): void $this->createSubject(), Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated()) )); + + if ($this->state->affects_children) { + $total = $this->item->affected_children; + + if ((int) $total > 1000) { + $total = '1000+'; + } + + $icon = new Icon(Icons::UNREACHABLE); + + $title->addHtml((new StateBadge([$icon, Text::create($total)], '')) + ->addAttributes([ + 'class' => 'affected-objects', + 'title' => sprintf(t('Up to %s affected objects'), $total) + ]) + ); + } } protected function assembleVisual(BaseHtmlElement $visual): void diff --git a/public/css/common.less b/public/css/common.less index 333df94b8..1fcda57ed 100644 --- a/public/css/common.less +++ b/public/css/common.less @@ -403,3 +403,11 @@ div.show-more { form[name="form_confirm_removal"] { text-align: center; } + +.affected-objects { + display: inline-flex; + align-items: baseline; + background-color: @state-critical; + color: @text-color-inverted; + padding: 0 0.25em; +}