Skip to content

Commit

Permalink
Revert "cli: Also update is_reachable of hosts and services"
Browse files Browse the repository at this point in the history
This reverts commit 29627ca.
  • Loading branch information
nilmerg committed Dec 12, 2024
1 parent 4d68829 commit 851bdfe
Showing 1 changed file with 19 additions and 63 deletions.
82 changes: 19 additions & 63 deletions application/clicommands/DependencyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ public function syncStateAction(): void

$problematicHosts = [];
$problematicServices = [];
$unreachableHosts = [];
$unreachableServices = [];

$dependencies = Dependency::on($this->getDb())
->columns([
Expand All @@ -259,9 +257,7 @@ public function syncStateAction(): void
'host_problem' => 'edge.parent.host.state.is_problem',
'service_id' => 'edge.parent.service_id',
'service_reachable' => 'edge.parent.service.state.is_reachable',
'service_state' => 'edge.parent.service.state.hard_state',
'child_host_id' => 'edge.child.host_id',
'child_service_id' => 'edge.child.service_id'
'service_state' => 'edge.parent.service.state.hard_state'
]);
foreach ($this->getDb()->select($dependencies->assembleSelect()) as $dependency) {
if ($dependency->service_id !== null) {
Expand Down Expand Up @@ -293,14 +289,6 @@ public function syncStateAction(): void
}
}

if ($failed) {
if ($dependency->child_service_id !== null) {
$unreachableServices[$dependency->child_service_id] = true;
} elseif ($dependency->child_host_id !== null) {
$unreachableHosts[$dependency->child_host_id] = true;
}
}

try {
$this->getDb()->insert('dependency_state', [
'id' => $dependency->id,
Expand All @@ -316,58 +304,26 @@ public function syncStateAction(): void
}
}

if (! empty($problematicHosts) || ! empty($unreachableHosts)) {
$data = [];
if (! empty($problematicHosts)) {
$data['affects_children'] = new Expression(
sprintf(
"(CASE WHEN host_id IN (%s) THEN 'y' ELSE 'n' END)",
str_repeat('?,', count($problematicHosts) - 1) . '?'
),
null,
...array_keys($problematicHosts)
);
}

if (! empty($unreachableHosts)) {
$data['is_reachable'] = new Expression(
sprintf(
"(CASE WHEN host_id IN (%s) THEN 'n' ELSE 'y' END)",
str_repeat('?,', count($unreachableHosts) - 1) . '?'
),
null,
...array_keys($unreachableHosts)
);
}

$this->getDb()->update('host_state', $data);
if (! empty($problematicHosts)) {
$this->getDb()->update('host_state', ['affects_children' => new Expression(
sprintf(
"(CASE WHEN host_id IN (%s) THEN 'y' ELSE 'n' END)",
str_repeat('?,', count($problematicHosts) - 1) . '?'
),
null,
...array_keys($problematicHosts)
)]);
}

if (! empty($problematicServices) || ! empty($unreachableServices)) {
$data = [];
if (! empty($problematicServices)) {
$data['affects_children'] = new Expression(
sprintf(
"(CASE WHEN service_id IN (%s) THEN 'y' ELSE 'n' END)",
str_repeat('?,', count($problematicServices) - 1) . '?'
),
null,
...array_keys($problematicServices)
);
}

if (! empty($unreachableServices)) {
$data['is_reachable'] = new Expression(
sprintf(
"(CASE WHEN service_id IN (%s) THEN 'n' ELSE 'y' END)",
str_repeat('?,', count($unreachableServices) - 1) . '?'
),
null,
...array_keys($unreachableServices)
);
}

$this->getDb()->update('service_state', $data);
if (! empty($problematicServices)) {
$this->getDb()->update('service_state', ['affects_children' => new Expression(
sprintf(
"(CASE WHEN service_id IN (%s) THEN 'y' ELSE 'n' END)",
str_repeat('?,', count($problematicServices) - 1) . '?'
),
null,
...array_keys($problematicServices)
)]);
}

$members = RedundancyGroup::on($this->getDb())
Expand Down

0 comments on commit 851bdfe

Please sign in to comment.