Skip to content

Commit

Permalink
Indicate the number of affected children by a particular parent
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 authored and nilmerg committed Oct 7, 2024
1 parent 3b57673 commit b8498c7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
2 changes: 2 additions & 0 deletions library/Icingadb/Common/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Icons

const HOST_DOWN = 'sitemap';

const UNREACHABLE = 'sitemap';

const IN_DOWNTIME = 'plug';

const IS_ACKNOWLEDGED = 'check';
Expand Down
7 changes: 5 additions & 2 deletions library/Icingadb/Model/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -111,7 +112,8 @@ public function getColumns()
'zone_name',
'zone_id',
'command_endpoint_name',
'command_endpoint_id'
'command_endpoint_id',
'affected_children'
];
}

Expand Down Expand Up @@ -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'),
];
}

Expand Down
3 changes: 2 additions & 1 deletion library/Icingadb/Model/HostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}

Expand Down
7 changes: 5 additions & 2 deletions library/Icingadb/Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -103,7 +104,8 @@ public function getColumns()
'zone_name',
'zone_id',
'command_endpoint_name',
'command_endpoint_id'
'command_endpoint_id',
'affected_children'
];
}

Expand Down Expand Up @@ -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')
];
}

Expand Down
3 changes: 2 additions & 1 deletion library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
}

Expand Down
7 changes: 5 additions & 2 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -98,7 +99,8 @@ public function getColumns()
'last_update',
'last_state_change',
'next_check',
'next_update'
'next_update',
'affects_children'
];
}

Expand All @@ -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([
Expand Down
18 changes: 18 additions & 0 deletions library/Icingadb/Widget/ItemList/StateListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions public/css/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit b8498c7

Please sign in to comment.