Refactor: Integrate regional agents in service-operation

Integrate distributed monitoring agents for HTTP, PING, TCP, and DNS checks
This commit is contained in:
Tola Leng
2025-06-21 17:48:55 +07:00
parent ea95490f13
commit 57a65106cb
16 changed files with 422 additions and 40 deletions
@@ -9,6 +9,50 @@ import (
"net/http"
)
func (c *PocketBaseClient) parseResponse(resp *http.Response, target interface{}) error {
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
return json.Unmarshal(body, target)
}
func (c *PocketBaseClient) updateRecord(collection string, recordID string, data interface{}) error {
jsonData, err := json.Marshal(data)
if err != nil {
return err
}
req, err := http.NewRequest("PATCH",
fmt.Sprintf("%s/api/collections/%s/records/%s", c.baseURL, collection, recordID),
bytes.NewBuffer(jsonData))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
resp, err := c.httpClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
bodyString := string(bodyBytes)
fmt.Printf("Failed to update record in %s collection. Status: %d, Response: %s\n",
collection, resp.StatusCode, bodyString)
return fmt.Errorf("failed to update record in %s, status: %d, response: %s",
collection, resp.StatusCode, bodyString)
}
return nil
}
func (c *PocketBaseClient) createRecord(collection string, data interface{}) error {
jsonData, err := json.Marshal(data)
if err != nil {