diff --git a/prometheus/server/go.mod b/prometheus/server/go.mod index 4cc4828924ac9bf713e83d9e893539013941e9f5..1c8388490b95ba2eefd7593cf7e34afb36096932 100644 --- a/prometheus/server/go.mod +++ b/prometheus/server/go.mod @@ -1,3 +1,28 @@ module openeuler.org/PilotGo/prometheus-plugin go 1.19 + +require github.com/gin-gonic/gin v1.7.1 + +require ( + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/json-iterator/go v1.1.11 // indirect + github.com/kr/pretty v0.2.0 // indirect + github.com/leodido/go-urn v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/stretchr/testify v1.8.0 // indirect + github.com/ugorji/go/codec v1.1.7 // indirect + golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect + golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/sdk/plugin/client.go b/sdk/plugin/client.go index 3816dd2e95e36dd1b17eb1e49751275389032fae..bf29991434bd4036c8ff7d8f026585dea5618caa 100644 --- a/sdk/plugin/client.go +++ b/sdk/plugin/client.go @@ -90,7 +90,7 @@ func (c *Client) RunScript(batch []string, cmd string) (int, string, string, err return 0, "", "", err } - res := struct { + res := &struct { Code int Stdout string Stderr string @@ -101,3 +101,37 @@ func (c *Client) RunScript(batch []string, cmd string) (int, string, string, err return res.Code, res.Stdout, res.Stderr, nil } + +type MachineNode struct { + UUID string + Department string + IP string + CPUArch string + OSInfo string + State int +} + +func (c *Client) MachineList() ([]*MachineNode, error) { + url := c.Server + "/api/v1/pluginapi/machine_list" + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + + hc := &http.Client{} + resp, err := hc.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + bs, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + result := []*MachineNode{} + if err := json.Unmarshal(bs, &result); err != nil { + return nil, err + } + return result, nil +}