mirror of
https://github.com/fankes/komari-agent.git
synced 2025-10-19 02:59:23 +08:00
fix: ws api endpoint
This commit is contained in:
@@ -16,10 +16,10 @@ type RemoteConfig struct {
|
|||||||
Swap bool `json:"swap"`
|
Swap bool `json:"swap"`
|
||||||
Load bool `json:"load"`
|
Load bool `json:"load"`
|
||||||
Uptime bool `json:"uptime"`
|
Uptime bool `json:"uptime"`
|
||||||
Temperature bool `json:"temp"`
|
Temperature bool `json:"temperature"`
|
||||||
Os bool `json:"os"`
|
Os bool `json:"os"`
|
||||||
Disk bool `json:"disk"`
|
Disk bool `json:"disk"`
|
||||||
Network bool `json:"net"`
|
Network bool `json:"network"`
|
||||||
Process bool `json:"process"`
|
Process bool `json:"process"`
|
||||||
Interval int `json:"interval"`
|
Interval int `json:"interval"`
|
||||||
Connections bool `json:"connections"`
|
Connections bool `json:"connections"`
|
||||||
@@ -32,7 +32,7 @@ type RemoteConfig struct {
|
|||||||
// Request the remote configuration
|
// Request the remote configuration
|
||||||
func LoadRemoteConfig(endpoint string, token string) (RemoteConfig, error) {
|
func LoadRemoteConfig(endpoint string, token string) (RemoteConfig, error) {
|
||||||
const maxRetry = 3
|
const maxRetry = 3
|
||||||
endpoint = strings.TrimSuffix(endpoint, "/") + "/api/getRemoteConfig" + "?token=" + token
|
endpoint = strings.TrimSuffix(endpoint, "/") + "/api/clients/getRemoteConfig" + "?token=" + token
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var err error
|
var err error
|
||||||
|
6
main.go
6
main.go
@@ -36,7 +36,7 @@ func main() {
|
|||||||
log.Fatalln("Failed to upload basic info:", err)
|
log.Fatalln("Failed to upload basic info:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
websocketEndpoint := strings.TrimSuffix(localConfig.Endpoint, "/") + "/ws/report"
|
websocketEndpoint := strings.TrimSuffix(localConfig.Endpoint, "/") + "/api/clients/report?token=" + localConfig.Token
|
||||||
websocketEndpoint = "ws" + strings.TrimPrefix(websocketEndpoint, "http")
|
websocketEndpoint = "ws" + strings.TrimPrefix(websocketEndpoint, "http")
|
||||||
|
|
||||||
var conn *websocket.Conn
|
var conn *websocket.Conn
|
||||||
@@ -130,7 +130,7 @@ func handleWebSocketMessages(localConfig config.LocalConfig, remoteConfig config
|
|||||||
}
|
}
|
||||||
|
|
||||||
func reportWithPOST(endpoint string, data []byte) error {
|
func reportWithPOST(endpoint string, data []byte) error {
|
||||||
url := strings.TrimSuffix(endpoint, "/") + "/api/report"
|
url := strings.TrimSuffix(endpoint, "/") + "/api/clients/report"
|
||||||
req, err := http.NewRequest("POST", url, strings.NewReader(string(data)))
|
req, err := http.NewRequest("POST", url, strings.NewReader(string(data)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -163,7 +163,7 @@ func uploadBasicInfo(endpoint string, token string) error {
|
|||||||
"os": osname,
|
"os": osname,
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = strings.TrimSuffix(endpoint, "/") + "/api/nodeBasicInfo"
|
endpoint = strings.TrimSuffix(endpoint, "/") + "/api/clients/uploadBasicInfo?token=" + token
|
||||||
payload, err := json.Marshal(data)
|
payload, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Reference in New Issue
Block a user