fix(watchdog): integrate instance management with watchdog

Add watchdog instance management in Start/StopInstanceHandler to sync with watchdog service
Add notification enabled check in exceptionHandle function
This commit is contained in:
2026-04-28 19:50:52 +08:00
parent 0890c8136f
commit 8108d4d01f
2 changed files with 58 additions and 26 deletions
+23 -18
View File
@@ -9,24 +9,29 @@ import (
)
func exceptionHandle(exceptionType string, serviceName string, errorMsg string) {
body := make(map[string]string)
for k, v := range global.CurrentConfig.Webhook.Body {
replaced := v
for strings.Contains(replaced, "{{ exceptionType }}") ||
strings.Contains(replaced, "{{ serviceName }}") ||
strings.Contains(replaced, "{{ exceptionMsg }}") {
replaced = strings.ReplaceAll(replaced, "{{ exceptionType }}", exceptionType)
replaced = strings.ReplaceAll(replaced, "{{ serviceName }}", serviceName)
replaced = strings.ReplaceAll(replaced, "{{ exceptionMsg }}", errorMsg)
if global.CurrentConfig.Notification.Enabled {
body := make(map[string]string)
if global.CurrentConfig.Notification.Method == "Webhook" {
for k, v := range global.CurrentConfig.Webhook.Body {
replaced := v
for strings.Contains(replaced, "{{ exceptionType }}") ||
strings.Contains(replaced, "{{ serviceName }}") ||
strings.Contains(replaced, "{{ exceptionMsg }}") {
replaced = strings.ReplaceAll(replaced, "{{ exceptionType }}", exceptionType)
replaced = strings.ReplaceAll(replaced, "{{ serviceName }}", serviceName)
replaced = strings.ReplaceAll(replaced, "{{ exceptionMsg }}", errorMsg)
}
body[k] = replaced
}
bodyJSON := ""
for k, v := range body {
bodyJSON = fmt.Sprintf(`{"%s": "%s"}`, k, v)
break
}
webhook.SendHook(global.CurrentConfig.Webhook.URL, global.CurrentConfig.Webhook.Method, global.CurrentConfig.Webhook.Headers, bodyJSON)
}
body[k] = replaced
}
bodyJSON := ""
for k, v := range body {
bodyJSON = fmt.Sprintf(`{"%s": "%s"}`, k, v)
break
}
webhook.SendHook(global.CurrentConfig.Webhook.URL, global.CurrentConfig.Webhook.Method, global.CurrentConfig.Webhook.Headers, bodyJSON)
}