fix(watchdog): fix watchdog unable to send webhook and simplify the parsing of json config
- Change webhook config headers and body from map to string format - Move command parsing logic to separate function in command.go - Add debug logging for webhook operations - Improve exception handling with proper JSON parsing - Simplify config loading logic with default values
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
// If the status code is not 200, it logs the error and returns the status code and response message.
|
||||
// If the status code is 200, it returns an empty error message, status code, and response message.
|
||||
func SendHook(url string, method string, headers map[string]string, body string) (err string, code int, msg string) {
|
||||
postLog.Debug(fmt.Sprintf("[SendHook] SendHook { %s, %s, %s, %s }", url, method, headers, body))
|
||||
req, reqErr := http.NewRequest(method, url, strings.NewReader(body))
|
||||
if reqErr != nil {
|
||||
return reqErr.Error(), 500, ""
|
||||
@@ -34,6 +35,8 @@ func SendHook(url string, method string, headers map[string]string, body string)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
postLog.Debug(fmt.Sprintf("[SendHook] SendHook { %s, %s, %s, %s } failed, status code: %d, response: [%s]: %s", url, method, headers, body, resp.StatusCode, resp.Status, respMsg))
|
||||
return fmt.Sprintf("unexpected status code: %d, response: [%s]: %s", resp.StatusCode, resp.Status, respMsg), resp.StatusCode, respMsg
|
||||
} else {
|
||||
postLog.Debug(fmt.Sprintf("[SendHook] SendHook { %s, %s, %s, %s } success, status code: %d, response: [%s]: %s", url, method, headers, body, resp.StatusCode, resp.Status, respMsg))
|
||||
}
|
||||
return "", 200, ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user