diff options
| author | Борисов Семён <kotopheiop@mail.ru> | 2025-12-12 16:29:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-12 16:29:27 +0300 |
| commit | f000322a06f78273f48fb354768418c6fd8c3290 (patch) | |
| tree | e660f1b0d40436ba982e983e3d8ac6f8a3d078d2 | |
| parent | 0ea8b5352a0482e6201faf55fe3963362e7a6d33 (diff) | |
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.
| -rw-r--r-- | web/job/check_cpu_usage.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/web/job/check_cpu_usage.go b/web/job/check_cpu_usage.go index 2ea87747..b2208f31 100644 --- a/web/job/check_cpu_usage.go +++ b/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) |
