Skip to content

Commit e43e81c

Browse files
committed
Keep compatibility with Icinga DB v5
1 parent c57298e commit e43e81c

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

library/Icingadb/Common/IcingaRedis.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,19 @@ protected function fetchState(string $key, array $ids, array $columns): Generato
152152
return;
153153
}
154154

155+
$desiredProperties = [];
156+
foreach ($columns as $alias => $column) {
157+
if (is_int($alias)) {
158+
$desiredProperties[] = $column;
159+
} else {
160+
$desiredProperties[] = $alias;
161+
}
162+
}
163+
155164
foreach ($results as $i => $json) {
156165
if ($json !== null) {
157166
$data = json_decode($json, true);
158-
$keyMap = array_fill_keys($columns, null);
167+
$keyMap = array_fill_keys($desiredProperties, null);
159168
unset($keyMap['is_overdue']); // Is calculated by Icinga DB, not Icinga 2, hence it's never in redis
160169

161170
// TODO: Remove once https://github.com/Icinga/icinga2/issues/9427 is fixed

library/Icingadb/Model/Host.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Icinga\Module\Icingadb\Model;
66

77
use Icinga\Module\Icingadb\Common\Auth;
8+
use Icinga\Module\Icingadb\Common\Backend;
89
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
910
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
1011
use ipl\Orm\Behavior\Binary;
@@ -13,6 +14,7 @@
1314
use ipl\Orm\Model;
1415
use ipl\Orm\Relations;
1516
use ipl\Orm\ResultSet;
17+
use ipl\Sql\Expression;
1618

1719
/**
1820
* Host model.
@@ -74,7 +76,7 @@ public function getKeyName()
7476

7577
public function getColumns()
7678
{
77-
return [
79+
$columns = [
7880
'environment_id',
7981
'name_checksum',
8082
'properties_checksum',
@@ -112,9 +114,15 @@ public function getColumns()
112114
'zone_name',
113115
'zone_id',
114116
'command_endpoint_name',
115-
'command_endpoint_id',
116-
'affected_children'
117+
'command_endpoint_id'
117118
];
119+
if (Backend::getDbSchemaVersion() >= 6) {
120+
$columns[] = 'affected_children';
121+
} else {
122+
$columns['affected_children'] = new Expression('0');
123+
}
124+
125+
return $columns;
118126
}
119127

120128
public function getColumnDefinitions()

library/Icingadb/Model/Service.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Icinga\Module\Icingadb\Model;
66

77
use Icinga\Module\Icingadb\Common\Auth;
8+
use Icinga\Module\Icingadb\Common\Backend;
89
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
910
use Icinga\Module\Icingadb\Model\Behavior\HasProblematicParent;
1011
use Icinga\Module\Icingadb\Model\Behavior\ReRoute;
@@ -14,6 +15,7 @@
1415
use ipl\Orm\Model;
1516
use ipl\Orm\Relations;
1617
use ipl\Orm\ResultSet;
18+
use ipl\Sql\Expression;
1719

1820
/**
1921
* @property string $id
@@ -70,7 +72,7 @@ public function getKeyName()
7072

7173
public function getColumns()
7274
{
73-
return [
75+
$columns = [
7476
'environment_id',
7577
'name_checksum',
7678
'properties_checksum',
@@ -105,9 +107,16 @@ public function getColumns()
105107
'zone_name',
106108
'zone_id',
107109
'command_endpoint_name',
108-
'command_endpoint_id',
109-
'affected_children'
110+
'command_endpoint_id'
110111
];
112+
if (Backend::getDbSchemaVersion() >= 6) {
113+
$columns[] = 'affected_children';
114+
} else {
115+
$columns['has_problematic_parent'] = new Expression('0');
116+
$columns['affected_children'] = new Expression('0');
117+
}
118+
119+
return $columns;
111120
}
112121

113122
public function getColumnDefinitions()
@@ -196,7 +205,9 @@ public function createBehaviors(Behaviors $behaviors)
196205
'command_endpoint_id'
197206
]));
198207

199-
$behaviors->add(new HasProblematicParent());
208+
if (Backend::getDbSchemaVersion() >= 6) {
209+
$behaviors->add(new HasProblematicParent());
210+
}
200211
}
201212

202213
public function createDefaults(Defaults $defaults)

library/Icingadb/Model/State.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace Icinga\Module\Icingadb\Model;
66

77
use DateTime;
8+
use Icinga\Module\Icingadb\Common\Backend;
89
use Icinga\Module\Icingadb\Common\Icons;
910
use Icinga\Module\Icingadb\Model\Behavior\BoolCast;
1011
use ipl\Orm\Behavior\Binary;
1112
use ipl\Orm\Behavior\MillisecondTimestamp;
1213
use ipl\Orm\Behaviors;
1314
use ipl\Orm\Model;
15+
use ipl\Sql\Expression;
1416
use ipl\Web\Widget\Icon;
1517

1618
/**
@@ -68,7 +70,7 @@ abstract public function getStateTextTranslated(): string;
6870

6971
public function getColumns()
7072
{
71-
return [
73+
$columns = [
7274
'environment_id',
7375
'state_type',
7476
'soft_state',
@@ -99,9 +101,15 @@ public function getColumns()
99101
'last_update',
100102
'last_state_change',
101103
'next_check',
102-
'next_update',
103-
'affects_children'
104+
'next_update'
104105
];
106+
if (Backend::getDbSchemaVersion() >= 6) {
107+
$columns[] = 'affects_children';
108+
} else {
109+
$columns['affects_children'] = new Expression("'n'");
110+
}
111+
112+
return $columns;
105113
}
106114

107115
public function createBehaviors(Behaviors $behaviors)

library/Icingadb/Widget/Detail/ObjectDetail.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Icinga\Date\DateFormatter;
1515
use Icinga\Exception\IcingaException;
1616
use Icinga\Module\Icingadb\Common\Auth;
17+
use Icinga\Module\Icingadb\Common\Backend;
1718
use Icinga\Module\Icingadb\Common\Database;
1819
use Icinga\Module\Icingadb\Common\HostLinks;
1920
use Icinga\Module\Icingadb\Common\Icons;
@@ -622,6 +623,7 @@ protected function createRootProblems(): ?array
622623
// host being down, only show its root problems if it's really caused by a dependency failure.
623624
if (
624625
$this->object->state->is_reachable
626+
|| Backend::getDbSchemaVersion() < 6
625627
|| ($this->object instanceof Service && ! $this->object->has_problematic_parent)
626628
) {
627629
return null;
@@ -669,7 +671,7 @@ protected function createRootProblems(): ?array
669671
*/
670672
protected function createAffectedObjects(): ?array
671673
{
672-
if (! $this->object->state->affects_children) {
674+
if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) {
673675
return null;
674676
}
675677

0 commit comments

Comments
 (0)