fix: сохранять пороги частично (warning/critical отдельно), flash сообщение с подробностями
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
ce577c5d51
commit
ade719f3e0
|
|
@ -297,23 +297,56 @@ class ServerDetailController extends Model
|
||||||
VALUES (:server_id, :metric_name_id, :warning_threshold, :critical_threshold, :duration)
|
VALUES (:server_id, :metric_name_id, :warning_threshold, :critical_threshold, :duration)
|
||||||
");
|
");
|
||||||
|
|
||||||
|
$saved = [];
|
||||||
|
$partial = [];
|
||||||
|
|
||||||
foreach ($metricTypes as $metricType) {
|
foreach ($metricTypes as $metricType) {
|
||||||
$warning = $params[$metricType['name'] . '_warning'] ?? '';
|
$warning = $params[$metricType['name'] . '_warning'] ?? '';
|
||||||
$critical = $params[$metricType['name'] . '_critical'] ?? '';
|
$critical = $params[$metricType['name'] . '_critical'] ?? '';
|
||||||
$duration = (int)($params[$metricType['name'] . '_duration'] ?? 0);
|
$duration = (int)($params[$metricType['name'] . '_duration'] ?? 0);
|
||||||
|
|
||||||
if ($warning !== '' && $critical !== '') {
|
// Сохраняем если хотя бы один порог заполнен
|
||||||
|
if ($warning !== '' || $critical !== '') {
|
||||||
|
// Если не указано - ставим NULL
|
||||||
|
$warningVal = $warning !== '' ? (float)$warning : null;
|
||||||
|
$criticalVal = $critical !== '' ? (float)$critical : null;
|
||||||
|
|
||||||
$insertStmt->execute([
|
$insertStmt->execute([
|
||||||
':server_id' => $id,
|
':server_id' => $id,
|
||||||
':metric_name_id' => $metricType['id'],
|
':metric_name_id' => $metricType['id'],
|
||||||
':warning_threshold' => (float)$warning,
|
':warning_threshold' => $warningVal,
|
||||||
':critical_threshold' => (float)$critical,
|
':critical_threshold' => $criticalVal,
|
||||||
':duration' => $duration
|
':duration' => $duration
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$name = $metricType['name'];
|
||||||
|
if ($warningVal !== null && $criticalVal !== null) {
|
||||||
|
$saved[] = $name;
|
||||||
|
} else {
|
||||||
|
$missing = [];
|
||||||
|
if ($warningVal === null) $missing[] = 'warning';
|
||||||
|
if ($criticalVal === null) $missing[] = 'critical';
|
||||||
|
$partial[] = $name . ' (нет: ' . implode(', ', $missing) . ')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response->withHeader('Location', "/servers/{$id}")->withStatus(302);
|
// Формируем flash сообщение
|
||||||
|
$messages = [];
|
||||||
|
if (count($saved) > 0) {
|
||||||
|
$messages[] = 'Сохранено: ' . implode(', ', $saved);
|
||||||
|
}
|
||||||
|
if (count($partial) > 0) {
|
||||||
|
$messages[] = 'Сохранено частично (используются значения по умолчанию): ' . implode(', ', $partial);
|
||||||
|
}
|
||||||
|
if (count($messages) === 0) {
|
||||||
|
$messages[] = 'Все пороги удалены';
|
||||||
|
}
|
||||||
|
|
||||||
|
$_SESSION['flash_message'] = implode('. ', $messages);
|
||||||
|
$_SESSION['flash_type'] = count($partial) > 0 ? 'warning' : 'success';
|
||||||
|
|
||||||
|
return $response->withHeader('Location', "/servers/{$id}?tab=thresholds")->withStatus(302);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveServices(Request $request, Response $response, $args)
|
public function saveServices(Request $request, Response $response, $args)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
|
|
||||||
<main class="container mt-4">
|
<main class="container mt-4">
|
||||||
{% if session.flash_message is defined and session.flash_message %}
|
{% if session.flash_message is defined and session.flash_message %}
|
||||||
<div class="alert alert-{{ session.flash_type == "error" ? "danger" : "success" }} alert-dismissible fade show mb-3" role="alert">
|
<div class="alert alert-{{ session.flash_type == "error" ? "danger" : (session.flash_type == "warning" ? "warning" : "success") }} alert-dismissible fade show mb-3" role="alert">
|
||||||
{{ session.flash_message|nl2br }}
|
{{ session.flash_message|nl2br }}
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue