Skip to content

Commit

Permalink
database exception monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyxjh authored and bxy4543 committed Jul 4, 2024
1 parent f11eded commit 30ab8ea
Showing 1 changed file with 42 additions and 41 deletions.
83 changes: 42 additions & 41 deletions service/exceptionmonitor/helper/notification/feishu.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package notification

import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"

"github.com/labring/sealos/service/exceptionmonitor/api"
)
Expand Down Expand Up @@ -148,46 +149,46 @@ func GetNotificationMessage(notificationInfo Info) string {
}

func SendFeishuNotification(message, feishuWebHook string) error {
log.Print(message, feishuWebHook)
//if api.MonitorType != "all" {
// feishuWebHook = api.FeishuWebhookURLMap["FeishuWebhookURLImportant"]
//}
//
//// Create a map to hold the POST request body
//bodyMap := map[string]interface{}{
// "msg_type": "interactive",
// "card": message,
//}
//
//// Convert the map to a JSON byte slice
//bodyBytes, err := json.Marshal(bodyMap)
//if err != nil {
// return err
//}
//
//// Create a new HTTP request
//req, err := http.NewRequest("POST", feishuWebHook, bytes.NewBuffer(bodyBytes))
//if err != nil {
// return err
//}
//
//// Set the request header
//req.Header.Set("Content-Type", "application/json")
//
//// Send the request using the default client
//client := &http.Client{}
//resp, err := client.Do(req)
//if err != nil {
// return err
//}
//defer resp.Body.Close()
//
//// Print the status and response body
//buf := new(bytes.Buffer)
//_, err = buf.ReadFrom(resp.Body)
//if err != nil {
// return err
//}
//log.Print(message, feishuWebHook)
if api.MonitorType != "all" {
feishuWebHook = api.FeishuWebhookURLMap["FeishuWebhookURLImportant"]
}

// Create a map to hold the POST request body
bodyMap := map[string]interface{}{
"msg_type": "interactive",
"card": message,
}

// Convert the map to a JSON byte slice
bodyBytes, err := json.Marshal(bodyMap)
if err != nil {
return err
}

// Create a new HTTP request
req, err := http.NewRequest("POST", feishuWebHook, bytes.NewBuffer(bodyBytes))
if err != nil {
return err
}

// Set the request header
req.Header.Set("Content-Type", "application/json")

// Send the request using the default client
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()

// Print the status and response body
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(resp.Body)
if err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit 30ab8ea

Please sign in to comment.