| func makeRequest(url string) error { | |
| //payload := map[string]string{ | |
| // "text": string(clusterJSON), | |
| //} | |
| //payload := map[string]interface{}{ | |
| // "blocks": []map[string]interface{}{ | |
| // { | |
| // "type": "section", | |
| // "text": map[string]string{ | |
| // "type": "mrkdwn", | |
| // "text": "*Cluster1 is Unhealthy*\n*controller-manager:* ❌ Unhealthy\n*etcd:* ✅ Healthy", | |
| // }, | |
| // }, | |
| // { | |
| // "type": "context", | |
| // "elements": []map[string]string{ | |
| // { | |
| // "type": "mrkdwn", | |
| // "text": "_Sent by KubeStellar Health Monitor_", | |
| // }, | |
| // }, | |
| // }, | |
| // }, | |
| //} | |
| payload := map[string]interface{}{ | |
| "blocks": []map[string]interface{}{ | |
| { | |
| "type": "section", | |
| "text": map[string]string{ | |
| "type": "mrkdwn", | |
| "text": "*Cluster1 is Unhealthy*\n*controller-manager:* ❌ Unhealthy\n*etcd:* ✅ Healthy", | |
| }, | |
| }, | |
| }, | |
| } | |
| body, err := json.Marshal(payload) | |
| //req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer([]byte(requestBody))) | |
| req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(body)) | |
| if err != nil { | |
| //c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | |
| return fmt.Errorf(err.Error()) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| client := &http.Client{} | |
| resp, err := client.Do(req) | |
| if err != nil { | |
| //c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) | |
| return fmt.Errorf(err.Error()) | |
| } | |
| defer resp.Body.Close() | |
| return nil | |
| } |