diff --git a/agent/ui_endpoint.go b/agent/ui_endpoint.go index 3de9eac15568..3d69cd44de77 100644 --- a/agent/ui_endpoint.go +++ b/agent/ui_endpoint.go @@ -13,9 +13,12 @@ import ( "strings" "github.com/hashicorp/go-hclog" + "github.com/hashicorp/serf/serf" "github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/agent/config" + "github.com/hashicorp/consul/agent/consul" + "github.com/hashicorp/consul/agent/metadata" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/logging" @@ -136,6 +139,47 @@ RPC: return append(out.Dump, out.ImportedDump...), nil } +// AgentMembersMapAddrVer is used to get version info from all serf members into a +// map of key-address,value-version. +func AgentMembersMapAddrVer(s *HTTPHandlers, req *http.Request) (map[string]string, error) { + var members []serf.Member + + //Get WAN Members + wanMembers := s.agent.WANMembers() + + //Get LAN Members + //Get the request partition and default to that of the agent. + entMeta := s.agent.AgentEnterpriseMeta() + if err := s.parseEntMetaPartition(req, entMeta); err != nil { + return nil, err + } + filter := consul.LANMemberFilter{ + Partition: entMeta.PartitionOrDefault(), + } + if acl.IsDefaultPartition(filter.Partition) { + filter.AllSegments = true + } + + lanMembers, err := s.agent.delegate.LANMembers(filter) + if err != nil { + return nil, err + } + + //aggregate members + members = append(wanMembers, lanMembers...) + + //create a map with key as IPv4 address and value as consul-version + mapAddrVer := make(map[string]string, len(members)) + for i := range members { + buildVersion, err := metadata.Build(&members[i]) + if err == nil { + mapAddrVer[members[i].Addr.String()] = buildVersion.String() + } + } + + return mapAddrVer, nil +} + // UINodeInfo is used to get info on a single node in a given datacenter. We return a // NodeInfo which provides overview information for the node func (s *HTTPHandlers) UINodeInfo(resp http.ResponseWriter, req *http.Request) (interface{}, error) {