Created
April 17, 2019 13:34
-
-
Save rluisr/8e16bcb3f058179f3e3ca5396b138a37 to your computer and use it in GitHub Desktop.
Get elasticache's memcached cluster from config endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"net" | |
"strings" | |
) | |
func main() { | |
configEndpoint := "test.pidknw.cfg.usw2.cache.amazonaws.com:11211" | |
conn, err := net.Dial("tcp", configEndpoint) | |
if err != nil { | |
panic(err) | |
} | |
defer conn.Close() | |
reader, writer := bufio.NewReader(conn), bufio.NewWriter(conn) | |
_, err = writer.Write([]byte("config get cluster\r\n")) | |
if err != nil { | |
panic(err) | |
} | |
err = writer.Flush() | |
if err != nil { | |
panic(err) | |
} | |
_, err = reader.ReadString('\n') | |
if err != nil { | |
panic(err) | |
} | |
_, err = reader.ReadString('\n') | |
if err != nil { | |
panic(err) | |
} | |
line, err := reader.ReadString('\n') | |
if err != nil { | |
panic(err) | |
} | |
endPoints := strings.Split(line, " ") | |
if len(endPoints) < 1 { | |
panic(err) | |
} | |
var ips []string | |
var fqdns []string | |
for _, v := range endPoints { | |
endPoint := strings.Split(v, "|") | |
if len(endPoint) < 3 { | |
continue | |
} | |
fqdns = append(fqdns, endPoint[0]) | |
ips = append(ips, fmt.Sprintf("%s:%s", endPoint[1], strings.TrimSpace(endPoint[2]))) | |
} | |
fmt.Printf("FQDNs: %v\n", strings.Join(fqdns, ",")) | |
fmt.Printf("IPs: %v\n", strings.Join(ips, ",")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
[root@ip-172-31-46-217 test]# go run main.go FQDNs: test.pidknw.0001.usw2.cache.amazonaws.com,test.pidknw.0002.usw2.cache.amazonaws.com IPs: 172.31.13.162:11211,172.31.28.99:11211