diff --git a/gala-ops/server/.gitignore b/gala-ops/server/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..924f0758c11b1fc4f0b158efcb1986c2fb63a8b6 --- /dev/null +++ b/gala-ops/server/.gitignore @@ -0,0 +1,6 @@ +# config file +config.yml + +# bin files +server +*.exe diff --git a/gala-ops/server/config.yml.templete b/gala-ops/server/config.yml.templete new file mode 100644 index 0000000000000000000000000000000000000000..63d7de830fc3ab10a48e90fb5160e59e2f491d8b --- /dev/null +++ b/gala-ops/server/config.yml.templete @@ -0,0 +1,6 @@ +grafana: + addr: "localhost:3000" + user: "" + passwd: "" +http: + addr: "0.0.0.0:7888" diff --git a/gala-ops/server/config/config.go b/gala-ops/server/config/config.go new file mode 100644 index 0000000000000000000000000000000000000000..55f875a177314c02671417335d4cdf8045ccd7f7 --- /dev/null +++ b/gala-ops/server/config/config.go @@ -0,0 +1,54 @@ +package config + +import ( + "fmt" + "io/ioutil" + "os" + + "gopkg.in/yaml.v3" +) + +type GrafanaConf struct { + Addr string `yaml:"addr"` + User string `yaml:"user"` + Passwd string `yaml:"passwd"` +} +type HttpConf struct { + Addr string `yaml:"addr"` +} + +type ServerConfig struct { + Grafana GrafanaConf `yaml:"grafana"` + Http HttpConf `yaml:"http"` +} + +const config_file = "./config.yaml" + +var global_config ServerConfig + +func Init() { + err := readConfig(config_file, &global_config) + if err != nil { + fmt.Printf("") + os.Exit(-1) + } +} + +func Config() *ServerConfig { + return &global_config +} + +func readConfig(file string, config interface{}) error { + bytes, err := ioutil.ReadFile(file) + if err != nil { + fmt.Printf("open %s failed! err = %s\n", file, err.Error()) + return err + } + + err = yaml.Unmarshal(bytes, config) + if err != nil { + fmt.Printf("yaml Unmarshal %s failed!\n", string(bytes)) + return err + } + return nil +} diff --git a/gala-ops/server/go.mod b/gala-ops/server/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..2f14138b1ff22ebfd0c7129058e0a073e5c03432 --- /dev/null +++ b/gala-ops/server/go.mod @@ -0,0 +1,3 @@ +module openeuler.org/PilotGo/gala-ops-plugin + +go 1.19 diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go new file mode 100644 index 0000000000000000000000000000000000000000..02b7b4908b0f43b821c00133a47ee5597840c3d6 --- /dev/null +++ b/gala-ops/server/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "openeuler.org/PilotGo/gala-ops-plugin/config" + "openeuler.org/PilotGo/plugin-sdk/plugin" +) + +const Version = "0.0.1" + +func main() { + fmt.Println("hello gala-ops") + + config.Init() + + client := plugin.DefaultClient(&plugin.PluginInfo{ + Name: "gala-ops", + Version: Version, + Description: "gala-ops智能运维工具", + Author: "guozhengxin", + Email: "guozhengxin@kylinos.cn", + Url: "http://192.168.48.163:9999/plugin/grafana", + // ReverseDest: "http://192.168.48.163:3000/", + }) + + client.Serve(":8888") +}