|
@@ -3,12 +3,13 @@ package worker
|
|
|
import (
|
|
import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "net/http"
|
|
|
|
|
+ "sync"
|
|
|
|
|
+
|
|
|
"github.com/coroot/coroot-node-agent/flags"
|
|
"github.com/coroot/coroot-node-agent/flags"
|
|
|
"github.com/coroot/coroot-node-agent/utils"
|
|
"github.com/coroot/coroot-node-agent/utils"
|
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
|
log "github.com/sirupsen/logrus"
|
|
log "github.com/sirupsen/logrus"
|
|
|
- "net/http"
|
|
|
|
|
- "sync"
|
|
|
|
|
//
|
|
//
|
|
|
//log "github.com/sirupsen/logrus"
|
|
//log "github.com/sirupsen/logrus"
|
|
|
)
|
|
)
|
|
@@ -29,7 +30,7 @@ const (
|
|
|
type ServerWorker interface {
|
|
type ServerWorker interface {
|
|
|
//InstallReport(r ReportRequest) error
|
|
//InstallReport(r ReportRequest) error
|
|
|
|
|
|
|
|
- RegisterHost(RegisterHostReq) error
|
|
|
|
|
|
|
+ RegisterHost(RegisterHostReq) (int, error)
|
|
|
|
|
|
|
|
RegisterApp(RegisterAppReq) error
|
|
RegisterApp(RegisterAppReq) error
|
|
|
|
|
|
|
@@ -85,16 +86,23 @@ func (w *ServerHTTPWorker) PullAllAppInfo(request EbpfAppReq) (EbpfAppResp, erro
|
|
|
return response, nil
|
|
return response, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (w *ServerHTTPWorker) RegisterHost(request RegisterHostReq) error {
|
|
|
|
|
|
|
+func (w *ServerHTTPWorker) RegisterHost(request RegisterHostReq) (int, error) {
|
|
|
//log.Infof("[server register host] request:%v.", utils.ToString(request))
|
|
//log.Infof("[server register host] request:%v.", utils.ToString(request))
|
|
|
- //result, err := w.requestServer("/v2/app/registerHost", request)
|
|
|
|
|
- _, err := w.requestServer("/v2/app/registerHost", request)
|
|
|
|
|
|
|
+ result, err := w.requestServer("/v2/app/registerHost", request)
|
|
|
//log.Infof("[server register host] resp:%v.", string(result))
|
|
//log.Infof("[server register host] resp:%v.", string(result))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.WithError(err).Errorf("[server register] Failed RegisterHost request:%v.", utils.ToString(request))
|
|
log.WithError(err).Errorf("[server register] Failed RegisterHost request:%v.", utils.ToString(request))
|
|
|
- return err
|
|
|
|
|
|
|
+ return 0, err
|
|
|
}
|
|
}
|
|
|
- return nil
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var response RegisterHostResponse
|
|
|
|
|
+ err = json.Unmarshal(result, &response)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.WithError(err).Errorf("[server register] Failed to parse RegisterHost response: %s", string(result))
|
|
|
|
|
+ return 0, err
|
|
|
|
|
+ }
|
|
|
|
|
+ log.Infof("[server register] RegisterHost success, account_id: %d", response.AccountID)
|
|
|
|
|
+ return response.AccountID, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (w *ServerHTTPWorker) RegisterApp(request RegisterAppReq) error {
|
|
func (w *ServerHTTPWorker) RegisterApp(request RegisterAppReq) error {
|