Skip to content

Commit

Permalink
Keep compatibility with Icinga DB v5
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Dec 17, 2024
1 parent c57298e commit e43e81c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
11 changes: 10 additions & 1 deletion library/Icingadb/Common/IcingaRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,19 @@ protected function fetchState(string $key, array $ids, array $columns): Generato
return;
}

$desiredProperties = [];
foreach ($columns as $alias => $column) {
if (is_int($alias)) {
$desiredProperties[] = $column;
} else {
$desiredProperties[] = $alias;
}
}

foreach ($results as $i => $json) {
if ($json !== null) {
$data = json_decode($json, true);
$keyMap = array_fill_keys($columns, null);
$keyMap = array_fill_keys($desiredProperties, null);
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
14 changes: 11 additions & 3 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 All @@ -13,6 +14,7 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* Host model.
Expand Down Expand Up @@ -74,7 +76,7 @@ public function getKeyName()

public function getColumns()
{
return [
$columns = [
'environment_id',
'name_checksum',
'properties_checksum',
Expand Down Expand Up @@ -112,9 +114,15 @@ 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';
} else {
$columns['affected_children'] = new Expression('0');
}

return $columns;
}

public function getColumnDefinitions()
Expand Down
19 changes: 15 additions & 4 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 All @@ -14,6 +15,7 @@
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Orm\ResultSet;
use ipl\Sql\Expression;

/**
* @property string $id
Expand Down Expand Up @@ -70,7 +72,7 @@ public function getKeyName()

public function getColumns()
{
return [
$columns = [
'environment_id',
'name_checksum',
'properties_checksum',
Expand Down Expand Up @@ -105,9 +107,16 @@ 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';
} else {
$columns['has_problematic_parent'] = new Expression('0');
$columns['affected_children'] = new Expression('0');
}

return $columns;
}

public function getColumnDefinitions()
Expand Down Expand Up @@ -196,7 +205,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
14 changes: 11 additions & 3 deletions library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
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;
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 @@ -68,7 +70,7 @@ abstract public function getStateTextTranslated(): string;

public function getColumns()
{
return [
$columns = [
'environment_id',
'state_type',
'soft_state',
Expand Down Expand Up @@ -99,9 +101,15 @@ public function getColumns()
'last_update',
'last_state_change',
'next_check',
'next_update',
'affects_children'
'next_update'
];
if (Backend::getDbSchemaVersion() >= 6) {
$columns[] = 'affects_children';
} else {
$columns['affects_children'] = new Expression("'n'");
}

return $columns;
}

public function createBehaviors(Behaviors $behaviors)
Expand Down
4 changes: 3 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 @@ -622,6 +623,7 @@ protected function createRootProblems(): ?array
// 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)
) {
return null;
Expand Down Expand Up @@ -669,7 +671,7 @@ protected function createRootProblems(): ?array
*/
protected function createAffectedObjects(): ?array
{
if (! $this->object->state->affects_children) {
if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) {
return null;
}

Expand Down

0 comments on commit e43e81c

Please sign in to comment.