Skip to content

Commit 7d6b136

Browse files
WIP
1 parent e43e81c commit 7d6b136

File tree

9 files changed

+57
-37
lines changed

9 files changed

+57
-37
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/Common/IcingaRedis.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,10 @@ 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-
164155
foreach ($results as $i => $json) {
165156
if ($json !== null) {
166157
$data = json_decode($json, true);
167-
$keyMap = array_fill_keys($desiredProperties, null);
158+
$keyMap = array_fill_keys($columns, null);
168159
unset($keyMap['is_overdue']); // Is calculated by Icinga DB, not Icinga 2, hence it's never in redis
169160

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

library/Icingadb/Model/Host.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use ipl\Orm\Model;
1515
use ipl\Orm\Relations;
1616
use ipl\Orm\ResultSet;
17-
use ipl\Sql\Expression;
1817

1918
/**
2019
* Host model.
@@ -116,18 +115,17 @@ public function getColumns()
116115
'command_endpoint_name',
117116
'command_endpoint_id'
118117
];
118+
119119
if (Backend::getDbSchemaVersion() >= 6) {
120120
$columns[] = 'affected_children';
121-
} else {
122-
$columns['affected_children'] = new Expression('0');
123121
}
124122

125123
return $columns;
126124
}
127125

128126
public function getColumnDefinitions()
129127
{
130-
return [
128+
$columns = [
131129
'environment_id' => t('Environment Id'),
132130
'name_checksum' => t('Host Name Checksum'),
133131
'properties_checksum' => t('Host Properties Checksum'),
@@ -165,9 +163,14 @@ public function getColumnDefinitions()
165163
'zone_name' => t('Zone Name'),
166164
'zone_id' => t('Zone Id'),
167165
'command_endpoint_name' => t('Endpoint Name'),
168-
'command_endpoint_id' => t('Endpoint Id'),
169-
'affected_children' => t('Affected Children'),
166+
'command_endpoint_id' => t('Endpoint Id')
170167
];
168+
169+
if (Backend::getDbSchemaVersion() >= 6) {
170+
$columns['affected_children'] = t('Affected Children');
171+
}
172+
173+
return $columns;
171174
}
172175

173176
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

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use ipl\Orm\Model;
1616
use ipl\Orm\Relations;
1717
use ipl\Orm\ResultSet;
18-
use ipl\Sql\Expression;
1918

2019
/**
2120
* @property string $id
@@ -109,19 +108,17 @@ public function getColumns()
109108
'command_endpoint_name',
110109
'command_endpoint_id'
111110
];
111+
112112
if (Backend::getDbSchemaVersion() >= 6) {
113113
$columns[] = 'affected_children';
114-
} else {
115-
$columns['has_problematic_parent'] = new Expression('0');
116-
$columns['affected_children'] = new Expression('0');
117114
}
118115

119116
return $columns;
120117
}
121118

122119
public function getColumnDefinitions()
123120
{
124-
return [
121+
$columns = [
125122
'environment_id' => t('Environment Id'),
126123
'name_checksum' => t('Service Name Checksum'),
127124
'properties_checksum' => t('Service Properties Checksum'),
@@ -157,8 +154,13 @@ public function getColumnDefinitions()
157154
'zone_id' => t('Zone Id'),
158155
'command_endpoint_name' => t('Endpoint Name'),
159156
'command_endpoint_id' => t('Endpoint Id'),
160-
'affected_children' => t('Affected Children')
161157
];
158+
159+
if (Backend::getDbSchemaVersion() >= 6) {
160+
$columns['affected_children'] = t('Affected Children');
161+
}
162+
163+
return $columns;
162164
}
163165

164166
public function getSearchColumns()

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use ipl\Orm\Behavior\MillisecondTimestamp;
1313
use ipl\Orm\Behaviors;
1414
use ipl\Orm\Model;
15-
use ipl\Sql\Expression;
1615
use ipl\Web\Widget\Icon;
1716

1817
/**
@@ -103,10 +102,9 @@ public function getColumns()
103102
'next_check',
104103
'next_update'
105104
];
105+
106106
if (Backend::getDbSchemaVersion() >= 6) {
107107
$columns[] = 'affects_children';
108-
} else {
109-
$columns['affects_children'] = new Expression("'n'");
110108
}
111109

112110
return $columns;
@@ -121,10 +119,13 @@ public function createBehaviors(Behaviors $behaviors)
121119
'is_flapping',
122120
'is_overdue',
123121
'is_acknowledged',
124-
'in_downtime',
125-
'affects_children'
122+
'in_downtime'
126123
]));
127124

125+
if (Backend::getDbSchemaVersion() >= 6) {
126+
$behaviors->add(new BoolCast(['affects_children']));
127+
}
128+
128129
$behaviors->add(new MillisecondTimestamp([
129130
'last_update',
130131
'last_state_change',

library/Icingadb/Widget/Detail/ObjectDetail.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use ipl\Sql\Filter\Exists;
4545
use ipl\Web\Widget\CopyToClipboard;
4646
use ipl\Web\Widget\EmptyState;
47+
use ipl\Web\Widget\EmptyStateBar;
4748
use ipl\Web\Widget\HorizontalKeyValue;
4849
use Icinga\Module\Icingadb\Widget\ItemList\CommentList;
4950
use Icinga\Module\Icingadb\Widget\PluginOutputContainer;
@@ -618,12 +619,18 @@ protected function fetchCustomVars()
618619
*/
619620
protected function createRootProblems(): ?array
620621
{
622+
if (Backend::getDbSchemaVersion() < 6 && ! $this->object->state->is_reachable) {
623+
return [
624+
HtmlElement::create('h2', null, Text::create(t('Root Problems'))),
625+
new EmptyStateBar(t('Please update Icinga DB to view root problems.'))
626+
];
627+
}
628+
621629
// If a dependency has failed, then the children are not reachable. Hence, the root problems should not be shown
622630
// if the object is reachable. And in case of a service, since, it may be also be unreachable because of its
623631
// host being down, only show its root problems if it's really caused by a dependency failure.
624632
if (
625633
$this->object->state->is_reachable
626-
|| Backend::getDbSchemaVersion() < 6
627634
|| ($this->object instanceof Service && ! $this->object->has_problematic_parent)
628635
) {
629636
return null;
@@ -671,7 +678,7 @@ protected function createRootProblems(): ?array
671678
*/
672679
protected function createAffectedObjects(): ?array
673680
{
674-
if (! $this->object->state->affects_children || Backend::getDbSchemaVersion() < 6) {
681+
if (! isset($this->object->state->affects_children) || ! $this->object->state->affects_children) {
675682
return null;
676683
}
677684

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)