Files
backend/watchdog/processor.go
T
NanamiAdmin 0890c8136f feat(watchdog): add exception handling and webhook integration
- Implement exception handling in TCP client to process error messages
- Add webhook functionality to send notifications for exceptions
- Introduce utility functions for string parsing
- Update config with webhook template
2026-04-28 15:46:31 +08:00

33 lines
947 B
Go

package watchdog
import (
"fmt"
"strings"
"super-frpc/global"
"super-frpc/webhook"
)
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)
}
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)
}