From a67af9765caa1d2608b4728fb3f6bf17a2374271 Mon Sep 17 00:00:00 2001 From: zhangxiquan Date: Mon, 6 Jan 2025 10:07:02 +0000 Subject: [PATCH] + [task#135735] Debugging cne monitor setting api. --- module/cne/model.php | 42 +++++++++++++++++++++++++ module/space/control.php | 11 ++++--- module/space/lang/de.php | 4 +++ module/space/ui/monitorsetting.html.php | 16 +++++----- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/module/cne/model.php b/module/cne/model.php index 1b9b0f0eef..ebdb6bf004 100644 --- a/module/cne/model.php +++ b/module/cne/model.php @@ -789,6 +789,48 @@ class cneModel extends model return $result->data; } + /** + * 设置监控。 + * Set monitor. + * + * @param object $formData + * @access public + * @return bool + */ + public function setMonitor(object $formData): bool + { + $apiUrl = "/api/cne/system/monitor"; + $result = $this->apiPost($apiUrl, $formData, $this->config->CNE->api->headers); + if($result && $result->code != 200) return false; + + return true; + } + + /** + * 获取监控。 + * Get monitor. + * + * @access public + * @return object + */ + public function getMonitor(): object + { + $apiUrl = "/api/cne/system/monitor"; + $result = $this->apiGet($apiUrl, new stdclass(), $this->config->CNE->api->headers); + if(!$result || $result->code != 200) return new stdclass(); + + return $result->data; + } + + public function deleteMonitor() + { + $apiUrl = "/api/cne/system/monitor/remove"; + $result = $this->apiPost($apiUrl, new stdclass(), $this->config->CNE->api->headers); + if($result && $result->code != 200) return null; + + return $result->data; + } + /** * 获取应用实例状态。 * Query status of an app instance. diff --git a/module/space/control.php b/module/space/control.php index 23f1a2a840..6a08fed5a1 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -74,12 +74,15 @@ class space extends control if ($_POST) { $formData = form::data()->get(); - $this->loadModel('cne')->monitorSetting($formData); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + $formData = $this->spaceZen->checkMonitorFormData($formData); + if (dao::isError()) return $this->sendError(dao::getError()); + $resp = $this->loadModel('cne')->setMonitor($formData); + if($resp) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true)); + return $this->sendError($this->lang->space->monitor->cneError); } - $json = '{"warning":{"cpu":{"threshold":"45","duration":"3"},"memory":{"threshold":"70"},"disk":{"threshold":"80"}},"danger":{"cpu":{"threshold":"60","duration":"1"},"memory":{"threshold":"75"},"disk":{"threshold":"90"}}}'; + $this->view->title = $this->lang->space->monitorSetting; - $this->view->setting = json_decode($json); + $this->view->setting = $this->loadModel('cne')->getMonitor(); $this->display(); } diff --git a/module/space/lang/de.php b/module/space/lang/de.php index 42b246af4d..9da9e2bce6 100644 --- a/module/space/lang/de.php +++ b/module/space/lang/de.php @@ -30,6 +30,10 @@ $lang->space->monitor->minutes = 'Minutes'; $lang->space->monitor->tips = '%s exceeds %d%%.'; $lang->space->monitor->cpuTips = '%s occupied %d%%,duration %d minutes.'; +$lang->space->monitor->error = 'Percentage must be an integer between 1 and 100.'; +$lang->space->monitor->durationError = 'Duration must be a positive integer.'; +$lang->space->monitor->cneError = 'Failed to call cne.'; + $lang->space->notice = new stdClass(); $lang->space->notice->toInstall = 'Please go to the application market to install'; diff --git a/module/space/ui/monitorsetting.html.php b/module/space/ui/monitorsetting.html.php index e31fcbdf40..12cf85a479 100644 --- a/module/space/ui/monitorsetting.html.php +++ b/module/space/ui/monitorsetting.html.php @@ -72,7 +72,7 @@ formPanel input ( set::name('warning[cpu][threshold]'), - set::value(zget($warning->cpu, 'threshold', 80)) + set::value(zget(empty($warning->cpu) ? new stdClass() : $warning->cpu, 'threshold', 80)) ), '%' ) @@ -85,7 +85,7 @@ formPanel input ( set::name('warning[cpu][duration]'), - set::value(zget($warning->cpu, 'duration', 5)) + set::value(zget(empty($warning->cpu) ? new stdClass() : $warning->cpu, 'duration', 5)) ), $lang->space->monitor->minutes, ) @@ -107,7 +107,7 @@ formPanel input ( set::name('danger[cpu][threshold]'), - set::value(zget($danger->cpu, 'threshold', 90)) + set::value(zget(empty($danger->cpu) ? new stdClass() : $danger->cpu, 'threshold', 90)) ), '%' ) @@ -120,7 +120,7 @@ formPanel input ( set::name('danger[cpu][duration]'), - set::value(zget($danger->cpu, 'duration', 10)) + set::value(zget(empty($danger->cpu) ? new stdClass() : $danger->cpu, 'duration', 10)) ), $lang->space->monitor->minutes, ) @@ -153,7 +153,7 @@ formPanel input ( set::name('warning[memory][threshold]'), - set::value(zget($warning->memory, 'threshold', 80)) + set::value(zget(empty($warning->memory) ? new stdClass() : $warning->memory, 'threshold', 80)) ), '%' ) @@ -175,7 +175,7 @@ formPanel input ( set::name('danger[memory][threshold]'), - set::value(zget($danger->memory, 'threshold', 90)) + set::value(zget(empty($danger->memory) ? new stdClass() : $danger->memory, 'threshold', 90)) ), '%' ) @@ -208,7 +208,7 @@ formPanel input ( set::name('warning[disk][threshold]'), - set::value(zget($warning->disk, 'threshold', 80)) + set::value(zget(empty($warning->disk) ? new stdClass() : $warning->disk, 'threshold', 80)) ), '%' ) @@ -230,7 +230,7 @@ formPanel input ( set::name('danger[disk][threshold]'), - set::value(zget($danger->disk, 'threshold', 90)) + set::value(zget(empty($danger->disk) ? new stdClass() : $danger->disk, 'threshold', 90)) ), '%' )