feat: per-server notification thresholds with alert on agent metrics push
This commit is contained in:
@@ -1969,4 +1969,24 @@ class ServerController
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveThresholds(int $id): void
|
||||
{
|
||||
$server = $this->requireServerAccess($id, 'manager');
|
||||
$role = $this->serverModel->getUserRole($id, (int) Session::get('user_id'));
|
||||
|
||||
if ($role !== 'owner') {
|
||||
$this->view->json(['success' => false, 'error' => 'Only the server owner can modify notification thresholds.'], 403);
|
||||
}
|
||||
|
||||
$fields = ['cpu_warning', 'cpu_critical', 'ram_warning', 'ram_critical', 'disk_warning', 'disk_critical'];
|
||||
$data = [];
|
||||
foreach ($fields as $f) {
|
||||
$key = 'threshold_' . $f;
|
||||
$data[$key] = isset($_POST[$f]) ? max(0, min(100, (float) $_POST[$f])) : null;
|
||||
}
|
||||
|
||||
$this->serverModel->update($id, $data);
|
||||
$this->auditService->log('thresholds_updated', 'server', $id, $data);
|
||||
$this->view->json(['success' => true, 'message' => 'Notification thresholds updated.']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user