Skip to content

Commit

Permalink
Get version for HaProxy (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinated92 authored Nov 15, 2024
1 parent 00d79a4 commit 5431b8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cluster/prx_haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions router/haproxy/runtime_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5431b8b

Please sign in to comment.