diff --git a/cluster/prx_haproxy.go b/cluster/prx_haproxy.go index c9c1e2b0d..b7ef87e8a 100644 --- a/cluster/prx_haproxy.go +++ b/cluster/prx_haproxy.go @@ -274,8 +274,16 @@ func (proxy *HaproxyProxy) Refresh() error { } - result, err := haRuntime.ApiCmd("show stat") + if proxy.Version == "" { + vstring, err := haRuntime.GetVersion() + if err == nil { + if vstring != "" { + proxy.Version = vstring + } + } + } + result, err := haRuntime.ApiCmd("show stat") if err != nil { cluster.SetState("ERR00052", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["ERR00052"], err), ErrFrom: "MON"}) return err diff --git a/router/haproxy/runtime_api.go b/router/haproxy/runtime_api.go index 28549a620..b7c041644 100644 --- a/router/haproxy/runtime_api.go +++ b/router/haproxy/runtime_api.go @@ -27,6 +27,25 @@ func (r *Runtime) ApiCmd(cmd string) (string, error) { return string(result), nil } +func (r *Runtime) GetVersion() (string, error) { + conn, err := net.DialTimeout("tcp", r.Host+":"+r.Port, DefaultTimeout) + if err != nil { + return "", err + } + defer conn.Close() + _, err = conn.Write([]byte("show version \n")) + if err != nil { + + return "", err + } + // cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral,config.LvlErr, "haproxy entering readall stats: ") + result, err := io.ReadAll(conn) + if err != nil { + return "", err + } + return string(result), nil +} + func (r *Runtime) SetMaster(host string, port string) (string, error) { if net.ParseIP(host) == nil {