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 committed Oct 4, 2024
1 parent 3b57673 commit 37efb30
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
12 changes: 11 additions & 1 deletion library/Icingadb/Common/IcingaRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Generator;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use ipl\Sql\Expression;
use Predis\Client as Redis;

class IcingaRedis
Expand Down Expand Up @@ -163,7 +164,16 @@ protected static function fetchState(string $key, array $ids, array $columns): G
foreach ($results as $i => $json) {
if ($json !== null) {
$data = json_decode($json, true);
$keyMap = array_fill_keys($columns, null);
$keyMap = [];

foreach ($columns as $alias => $column) {
if ($column instanceof Expression) {
$column = $alias;
}

$keyMap[] = $column;
}

unset($keyMap['is_overdue']); // Is calculated by Icinga DB, not Icinga 2, hence it's never in redis

// TODO: Remove once https://github.com/Icinga/icinga2/issues/9427 is fixed
Expand Down
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
8 changes: 6 additions & 2 deletions library/Icingadb/Model/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* Host model.
Expand Down Expand Up @@ -56,6 +57,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 +113,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 +158,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
8 changes: 6 additions & 2 deletions library/Icingadb/Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* @property string $id
Expand Down Expand Up @@ -51,6 +52,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 +105,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 +147,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
8 changes: 6 additions & 2 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Sql\Expression;
use ipl\Web\Widget\Icon;

/**
Expand Down Expand Up @@ -48,6 +49,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 +100,8 @@ public function getColumns()
'last_update',
'last_state_change',
'next_check',
'next_update'
'next_update',
'affects_children'
];
}

Expand All @@ -111,7 +114,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: @default-text-color-inverted;
padding: 0 0.25em;
}

0 comments on commit 37efb30

Please sign in to comment.