Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Dec 18, 2024
1 parent e43e81c commit 04b19fe
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
6 changes: 5 additions & 1 deletion application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Icinga\Exception\NotFoundError;
use Icinga\Module\Icingadb\Command\Object\GetObjectCommand;
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Common\CommandActions;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Common\ServiceLinks;
Expand Down Expand Up @@ -39,7 +40,6 @@ public function init()
$hostName = $this->params->getRequired('host.name');

$query = Service::on($this->getDb())
->withColumns(['has_problematic_parent'])
->with([
'state',
'icon_image',
Expand All @@ -54,6 +54,10 @@ public function init()
Filter::equal('host.name', $hostName)
));

if (Backend::getDbSchemaVersion() >= 6) {
$query->withColumns(['has_problematic_parent']);
}

$this->applyRestrictions($query);

/** @var Service $service */
Expand Down
15 changes: 9 additions & 6 deletions library/Icingadb/Model/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* Host model.
Expand Down Expand Up @@ -116,18 +115,17 @@ public function getColumns()
'command_endpoint_name',
'command_endpoint_id'
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns[] = 'affected_children';
} else {
$columns['affected_children'] = new Expression('0');
}

return $columns;
}

public function getColumnDefinitions()
{
return [
$columns = [
'environment_id' => t('Environment Id'),
'name_checksum' => t('Host Name Checksum'),
'properties_checksum' => t('Host Properties Checksum'),
Expand Down Expand Up @@ -165,9 +163,14 @@ 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'),
'affected_children' => t('Affected Children'),
'command_endpoint_id' => t('Endpoint Id')
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns['affected_children'] = t('Affected Children');
}

return $columns;
}

public function getSearchColumns()
Expand Down
12 changes: 9 additions & 3 deletions library/Icingadb/Model/HostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Common\HostStates;
use ipl\Orm\Relations;

Expand All @@ -24,7 +25,7 @@ public function getKeyName()

public function getColumnDefinitions()
{
return [
$columns = [
'environment_id' => t('Environment Id'),
'state_type' => t('Host State Type'),
'soft_state' => t('Host Soft State'),
Expand Down Expand Up @@ -53,9 +54,14 @@ 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'),
'affects_children' => t('Host Affects Children'),
'next_update' => t('Host Next Update')
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns['affects_children'] = t('Host Affects Children');
}

return $columns;
}

public function createRelations(Relations $relations)
Expand Down
14 changes: 8 additions & 6 deletions library/Icingadb/Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* @property string $id
Expand Down Expand Up @@ -109,19 +108,17 @@ public function getColumns()
'command_endpoint_name',
'command_endpoint_id'
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns[] = 'affected_children';
} else {
$columns['has_problematic_parent'] = new Expression('0');
$columns['affected_children'] = new Expression('0');
}

return $columns;
}

public function getColumnDefinitions()
{
return [
$columns = [
'environment_id' => t('Environment Id'),
'name_checksum' => t('Service Name Checksum'),
'properties_checksum' => t('Service Properties Checksum'),
Expand Down Expand Up @@ -157,8 +154,13 @@ public function getColumnDefinitions()
'zone_id' => t('Zone Id'),
'command_endpoint_name' => t('Endpoint Name'),
'command_endpoint_id' => t('Endpoint Id'),
'affected_children' => t('Affected Children')
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns['affected_children'] = t('Affected Children');
}

return $columns;
}

public function getSearchColumns()
Expand Down
12 changes: 9 additions & 3 deletions library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Common\ServiceStates;
use ipl\Orm\Relations;

Expand All @@ -26,7 +27,7 @@ public function getKeyName()

public function getColumnDefinitions()
{
return [
$columns = [
'environment_id' => t('Environment Id'),
'state_type' => t('Service State Type'),
'soft_state' => t('Service Soft State'),
Expand Down Expand Up @@ -55,9 +56,14 @@ 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'),
'affects_children' => t('Service Affects Children'),
'next_update' => t('Service Next Update')
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns['affects_children'] = t('Service Affects Children');
}

return $columns;
}

public function createRelations(Relations $relations)
Expand Down
10 changes: 6 additions & 4 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ public function getColumns()
'next_check',
'next_update'
];

if (Backend::getDbSchemaVersion() >= 6) {
$columns[] = 'affects_children';
} else {
$columns['affects_children'] = new Expression("'n'");
}

return $columns;
Expand All @@ -121,10 +120,13 @@ public function createBehaviors(Behaviors $behaviors)
'is_flapping',
'is_overdue',
'is_acknowledged',
'in_downtime',
'affects_children'
'in_downtime'
]));

if (Backend::getDbSchemaVersion() >= 6) {
$behaviors->add(new BoolCast(['affects_children']));
}

$behaviors->add(new MillisecondTimestamp([
'last_update',
'last_state_change',
Expand Down
18 changes: 15 additions & 3 deletions library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use ipl\Sql\Filter\Exists;
use ipl\Web\Widget\CopyToClipboard;
use ipl\Web\Widget\EmptyState;
use ipl\Web\Widget\EmptyStateBar;
use ipl\Web\Widget\HorizontalKeyValue;
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
Expand Down Expand Up @@ -618,13 +619,24 @@ protected function fetchCustomVars()
*/
protected function createRootProblems(): ?array
{
if (Backend::getDbSchemaVersion() < 6
&& ! $this->object->state->is_reachable
&& ! $this->object instanceof Service
) {
return [
HtmlElement::create('h2', null, Text::create(t('Root Problems'))),
new EmptyStateBar(t('Please update Icinga DB Web module to view root problems.'))
];
}

// If a dependency has failed, then the children are not reachable. Hence, the root problems should not be shown
// if the object is reachable. And in case of a service, since, it may be also be unreachable because of its
// host being down, only show its root problems if it's really caused by a dependency failure.
if (
$this->object->state->is_reachable
|| Backend::getDbSchemaVersion() < 6
|| ($this->object instanceof Service && ! $this->object->has_problematic_parent)
|| ($this->object instanceof Service
&& (! isset($this->object->has_problematic_parent) || ! $this->object->has_problematic_parent)
)
) {
return null;
}
Expand Down Expand Up @@ -671,7 +683,7 @@ protected function createRootProblems(): ?array
*/
protected function createAffectedObjects(): ?array
{
if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) {
if (! isset($this->object->state->affects_children) || ! $this->object->state->affects_children) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/ItemList/StateListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function assembleTitle(BaseHtmlElement $title): void
Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated())
));

if ($this->state->affects_children) {
if (isset($this->state->affects_children) && $this->state->affects_children) {
$total = (int) $this->item->affected_children;

if ($total > 1000) {
Expand Down

0 comments on commit 04b19fe

Please sign in to comment.