Skip to content

Commit

Permalink
agent: avoid loop in log receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobioz committed Sep 1, 2020
1 parent 331faf9 commit 00d77ab
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,31 @@ func Backup(targetURL, backupPath, hostname string, force bool, logReceiver stri
output := e.Backup(backupPath, hostname, force)

if logReceiver != "" {
for {
data := `{"data":` + output + `}`
req, err := http.NewRequest("POST", logReceiver, bytes.NewBuffer([]byte(data)))
if err != nil {
log.Errorf("failed to build new request: %s\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("BIVAC_SERVER_PSK"))
data := `{"data":` + output + `}`
req, err := http.NewRequest("POST", logReceiver, bytes.NewBuffer([]byte(data)))
if err != nil {
log.Errorf("failed to build new request: %s\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("BIVAC_SERVER_PSK"))

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Errorf("failed to send data: %s\n", err)
continue
}
defer resp.Body.Close()
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Errorf("failed to send data: %s\n", err)
return
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Errorf("failed to read body: %s\n", err)
return
}
if resp.StatusCode != 200 {
log.Infof("Response from API: %s", b)
return
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Errorf("failed to read body: %s\n", err)
return
}
if resp.StatusCode != 200 {
log.Infof("Response from API: %s", b)
return
}
return
}
Expand Down

0 comments on commit 00d77ab

Please sign in to comment.