Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep compatibility with Icinga DB v5 #1114

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 17 additions & 6 deletions library/Icingadb/Model/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
use ipl\Orm\Behavior\Binary;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function getKeyName()

public function getColumns()
{
return [
$columns = [
'environment_id',
'name_checksum',
'properties_checksum',
Expand Down Expand Up @@ -112,14 +113,19 @@ public function getColumns()
'zone_name',
'zone_id',
'command_endpoint_name',
'command_endpoint_id',
'affected_children'
'command_endpoint_id'
];

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

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 @@ -157,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
25 changes: 19 additions & 6 deletions library/Icingadb/Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Icingadb\Model;

use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent;
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function getKeyName()

public function getColumns()
{
return [
$columns = [
'environment_id',
'name_checksum',
'properties_checksum',
Expand Down Expand Up @@ -105,14 +106,19 @@ public function getColumns()
'zone_name',
'zone_id',
'command_endpoint_name',
'command_endpoint_id',
'affected_children'
'command_endpoint_id'
];

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

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 @@ -148,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 Expand Up @@ -196,7 +207,9 @@ public function createBehaviors(Behaviors $behaviors)
'command_endpoint_id'
]));

$behaviors->add(new HasProblematicParent());
if (Backend::getDbSchemaVersion() >= 6) {
$behaviors->add(new HasProblematicParent());
}
}

public function createDefaults(Defaults $defaults)
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
12 changes: 9 additions & 3 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Icingadb\Model;

use DateTime;
use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Common\Icons;
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
use ipl\Orm\Behavior\Binary;
Expand Down Expand Up @@ -68,7 +69,7 @@ abstract public function getStateTextTranslated(): string;

public function getColumns()
{
return [
$columns = [
'environment_id',
'state_type',
'soft_state',
Expand Down Expand Up @@ -99,9 +100,14 @@ public function getColumns()
'last_update',
'last_state_change',
'next_check',
'next_update',
'affects_children'
'next_update'
];

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

return $columns;
}

public function createBehaviors(Behaviors $behaviors)
Expand Down
15 changes: 14 additions & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Icinga\Date\DateFormatter;
use Icinga\Exception\IcingaException;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Backend;
use Icinga\Module\Icingadb\Common\Database;
use Icinga\Module\Icingadb\Common\HostLinks;
use Icinga\Module\Icingadb\Common\Icons;
Expand Down Expand Up @@ -43,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 @@ -617,6 +619,17 @@ protected function fetchCustomVars()
*/
protected function createRootProblems(): ?array
{
if (Backend::getDbSchemaVersion() < 6) {
if ($this->object->state->is_reachable) {
return null;
}

return [
HtmlElement::create('h2', null, Text::create(t('Root Problems'))),
new EmptyStateBar(t("You're missing out! Upgrade Icinga DB and see the actual root cause here!"))
];
}

// 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.
Expand Down Expand Up @@ -669,7 +682,7 @@ protected function createRootProblems(): ?array
*/
protected function createAffectedObjects(): ?array
{
if (! $this->object->state->affects_children) {
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
Loading