Skip to content

Commit 1ffbe35

Browse files
nilmergsukhwinder33445
authored andcommitted
Keep compatibility with Icinga DB v5
1 parent c57298e commit 1ffbe35

File tree

8 files changed

+83
-24
lines changed

8 files changed

+83
-24
lines changed

application/controllers/ServiceController.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Icinga\Exception\NotFoundError;
99
use Icinga\Module\Icingadb\Command\Object\GetObjectCommand;
1010
use Icinga\Module\Icingadb\Command\Transport\CommandTransport;
11+
use Icinga\Module\Icingadb\Common\Backend;
1112
use Icinga\Module\Icingadb\Common\CommandActions;
1213
use Icinga\Module\Icingadb\Common\Links;
1314
use Icinga\Module\Icingadb\Common\ServiceLinks;
@@ -39,7 +40,6 @@ public function init()
3940
$hostName = $this->params->getRequired('host.name');
4041

4142
$query = Service::on($this->getDb())
42-
->withColumns(['has_problematic_parent'])
4343
->with([
4444
'state',
4545
'icon_image',
@@ -54,6 +54,10 @@ public function init()
5454
Filter::equal('host.name', $hostName)
5555
));
5656

57+
if (Backend::getDbSchemaVersion() >= 6) {
58+
$query->withColumns(['has_problematic_parent']);
59+
}
60+
5761
$this->applyRestrictions($query);
5862

5963
/** @var Service $service */

library/Icingadb/Model/Host.php

+17-6
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;
@@ -74,7 +75,7 @@ public function getKeyName()
7475

7576
public function getColumns()
7677
{
77-
return [
78+
$columns = [
7879
'environment_id',
7980
'name_checksum',
8081
'properties_checksum',
@@ -112,14 +113,19 @@ public function getColumns()
112113
'zone_name',
113114
'zone_id',
114115
'command_endpoint_name',
115-
'command_endpoint_id',
116-
'affected_children'
116+
'command_endpoint_id'
117117
];
118+
119+
if (Backend::getDbSchemaVersion() >= 6) {
120+
$columns[] = 'affected_children';
121+
}
122+
123+
return $columns;
118124
}
119125

120126
public function getColumnDefinitions()
121127
{
122-
return [
128+
$columns = [
123129
'environment_id' => t('Environment Id'),
124130
'name_checksum' => t('Host Name Checksum'),
125131
'properties_checksum' => t('Host Properties Checksum'),
@@ -157,9 +163,14 @@ public function getColumnDefinitions()
157163
'zone_name' => t('Zone Name'),
158164
'zone_id' => t('Zone Id'),
159165
'command_endpoint_name' => t('Endpoint Name'),
160-
'command_endpoint_id' => t('Endpoint Id'),
161-
'affected_children' => t('Affected Children'),
166+
'command_endpoint_id' => t('Endpoint Id')
162167
];
168+
169+
if (Backend::getDbSchemaVersion() >= 6) {
170+
$columns['affected_children'] = t('Affected Children');
171+
}
172+
173+
return $columns;
163174
}
164175

165176
public function getSearchColumns()

library/Icingadb/Model/HostState.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Icinga\Module\Icingadb\Model;
66

7+
use Icinga\Module\Icingadb\Common\Backend;
78
use Icinga\Module\Icingadb\Common\HostStates;
89
use ipl\Orm\Relations;
910

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

2526
public function getColumnDefinitions()
2627
{
27-
return [
28+
$columns = [
2829
'environment_id' => t('Environment Id'),
2930
'state_type' => t('Host State Type'),
3031
'soft_state' => t('Host Soft State'),
@@ -53,9 +54,14 @@ public function getColumnDefinitions()
5354
'last_update' => t('Host Last Update'),
5455
'last_state_change' => t('Host Last State Change'),
5556
'next_check' => t('Host Next Check'),
56-
'next_update' => t('Host Next Update'),
57-
'affects_children' => t('Host Affects Children'),
57+
'next_update' => t('Host Next Update')
5858
];
59+
60+
if (Backend::getDbSchemaVersion() >= 6) {
61+
$columns['affects_children'] = t('Host Affects Children');
62+
}
63+
64+
return $columns;
5965
}
6066

6167
public function createRelations(Relations $relations)

library/Icingadb/Model/Service.php

+19-6
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;
@@ -70,7 +71,7 @@ public function getKeyName()
7071

7172
public function getColumns()
7273
{
73-
return [
74+
$columns = [
7475
'environment_id',
7576
'name_checksum',
7677
'properties_checksum',
@@ -105,14 +106,19 @@ public function getColumns()
105106
'zone_name',
106107
'zone_id',
107108
'command_endpoint_name',
108-
'command_endpoint_id',
109-
'affected_children'
109+
'command_endpoint_id'
110110
];
111+
112+
if (Backend::getDbSchemaVersion() >= 6) {
113+
$columns[] = 'affected_children';
114+
}
115+
116+
return $columns;
111117
}
112118

113119
public function getColumnDefinitions()
114120
{
115-
return [
121+
$columns = [
116122
'environment_id' => t('Environment Id'),
117123
'name_checksum' => t('Service Name Checksum'),
118124
'properties_checksum' => t('Service Properties Checksum'),
@@ -148,8 +154,13 @@ public function getColumnDefinitions()
148154
'zone_id' => t('Zone Id'),
149155
'command_endpoint_name' => t('Endpoint Name'),
150156
'command_endpoint_id' => t('Endpoint Id'),
151-
'affected_children' => t('Affected Children')
152157
];
158+
159+
if (Backend::getDbSchemaVersion() >= 6) {
160+
$columns['affected_children'] = t('Affected Children');
161+
}
162+
163+
return $columns;
153164
}
154165

155166
public function getSearchColumns()
@@ -196,7 +207,9 @@ public function createBehaviors(Behaviors $behaviors)
196207
'command_endpoint_id'
197208
]));
198209

199-
$behaviors->add(new HasProblematicParent());
210+
if (Backend::getDbSchemaVersion() >= 6) {
211+
$behaviors->add(new HasProblematicParent());
212+
}
200213
}
201214

202215
public function createDefaults(Defaults $defaults)

library/Icingadb/Model/ServiceState.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Icinga\Module\Icingadb\Model;
66

7+
use Icinga\Module\Icingadb\Common\Backend;
78
use Icinga\Module\Icingadb\Common\ServiceStates;
89
use ipl\Orm\Relations;
910

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

2728
public function getColumnDefinitions()
2829
{
29-
return [
30+
$columns = [
3031
'environment_id' => t('Environment Id'),
3132
'state_type' => t('Service State Type'),
3233
'soft_state' => t('Service Soft State'),
@@ -55,9 +56,14 @@ public function getColumnDefinitions()
5556
'last_update' => t('Service Last Update'),
5657
'last_state_change' => t('Service Last State Change'),
5758
'next_check' => t('Service Next Check'),
58-
'next_update' => t('Service Next Update'),
59-
'affects_children' => t('Service Affects Children'),
59+
'next_update' => t('Service Next Update')
6060
];
61+
62+
if (Backend::getDbSchemaVersion() >= 6) {
63+
$columns['affects_children'] = t('Service Affects Children');
64+
}
65+
66+
return $columns;
6167
}
6268

6369
public function createRelations(Relations $relations)

library/Icingadb/Model/State.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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;
@@ -68,7 +69,7 @@ abstract public function getStateTextTranslated(): string;
6869

6970
public function getColumns()
7071
{
71-
return [
72+
$columns = [
7273
'environment_id',
7374
'state_type',
7475
'soft_state',
@@ -99,9 +100,14 @@ public function getColumns()
99100
'last_update',
100101
'last_state_change',
101102
'next_check',
102-
'next_update',
103-
'affects_children'
103+
'next_update'
104104
];
105+
106+
if (Backend::getDbSchemaVersion() >= 6) {
107+
$columns[] = 'affects_children';
108+
}
109+
110+
return $columns;
105111
}
106112

107113
public function createBehaviors(Behaviors $behaviors)

library/Icingadb/Widget/Detail/ObjectDetail.php

+14-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;
@@ -43,6 +44,7 @@
4344
use ipl\Sql\Filter\Exists;
4445
use ipl\Web\Widget\CopyToClipboard;
4546
use ipl\Web\Widget\EmptyState;
47+
use ipl\Web\Widget\EmptyStateBar;
4648
use ipl\Web\Widget\HorizontalKeyValue;
4749
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
4850
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
@@ -617,6 +619,17 @@ protected function fetchCustomVars()
617619
*/
618620
protected function createRootProblems(): ?array
619621
{
622+
if (Backend::getDbSchemaVersion() < 6) {
623+
if ($this->object->state->is_reachable) {
624+
return null;
625+
}
626+
627+
return [
628+
HtmlElement::create('h2', null, Text::create(t('Root Problems'))),
629+
new EmptyStateBar(t("You're missing out! Upgrade Icinga DB and see the actual root cause here!"))
630+
];
631+
}
632+
620633
// If a dependency has failed, then the children are not reachable. Hence, the root problems should not be shown
621634
// if the object is reachable. And in case of a service, since, it may be also be unreachable because of its
622635
// host being down, only show its root problems if it's really caused by a dependency failure.
@@ -669,7 +682,7 @@ protected function createRootProblems(): ?array
669682
*/
670683
protected function createAffectedObjects(): ?array
671684
{
672-
if (! $this->object->state->affects_children) {
685+
if (! isset($this->object->state->affects_children) || ! $this->object->state->affects_children) {
673686
return null;
674687
}
675688

library/Icingadb/Widget/ItemList/StateListItem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function assembleTitle(BaseHtmlElement $title): void
9898
Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated())
9999
));
100100

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

104104
if ($total > 1000) {

0 commit comments

Comments
 (0)