소스 검색

fix: handle CPU threshold error to prevent false notifications (#3603)

Previously, when GetTgCpu() failed, the error was ignored and threshold
defaulted to 0, causing notifications to be sent for any CPU usage.

Now the job properly checks for errors and skips notifications if:
- The threshold cannot be retrieved (error)
- The threshold is not set or is 0

This ensures notifications are only sent when CPU usage exceeds the
configured threshold value from settings.
Борисов Семён 4 일 전
부모
커밋
f000322a06
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      web/job/check_cpu_usage.go

+ 5 - 1
web/job/check_cpu_usage.go

@@ -22,7 +22,11 @@ func NewCheckCpuJob() *CheckCpuJob {
 
 // Run checks CPU usage over the last minute and sends a Telegram alert if it exceeds the threshold.
 func (j *CheckCpuJob) Run() {
-	threshold, _ := j.settingService.GetTgCpu()
+	threshold, err := j.settingService.GetTgCpu()
+	if err != nil || threshold <= 0 {
+		// If threshold cannot be retrieved or is not set, skip sending notifications
+		return
+	}
 
 	// get latest status of server
 	percent, err := cpu.Percent(1*time.Minute, false)