You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/troubleshoot/ports/troubleshoot_ports.go

54 lines
1.3 KiB

NET-3860 - [Supportability] consul troubleshoot CLI for verifying ports (#18329) * init * udp * added support for custom port * removed grpc * rename constants * removed udp * added change log * fix synopsis * pr comment chagnes * make private * added tests * added one more test case * defer close results channel * removed unwanted comment * licence update * updated docs * fix indent * fix path * example update * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update command/troubleshoot/ports/troubleshoot_ports.go Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/index.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update command/troubleshoot/ports/troubleshoot_ports.go Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update command/troubleshoot/ports/troubleshoot_ports.go Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * Update website/content/commands/troubleshoot/ports.mdx Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com> * pr comment resolved --------- Co-authored-by: trujillo-adam <47586768+trujillo-adam@users.noreply.github.com>
12 months ago
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package ports
import (
"fmt"
"strings"
)
func TroubleshootDefaultPorts(host string) []string {
// Source - https://developer.hashicorp.com/consul/docs/install/ports
ports := []string{"8600", "8500", "8501", "8502", "8503", "8301", "8302", "8300"}
return troubleshootRun(ports, host)
}
func TroubleShootCustomPorts(host string, ports string) []string {
portsArr := strings.Split(ports, ",")
return troubleshootRun(portsArr, host)
}
func troubleshootRun(ports []string, host string) []string {
resultsChannel := make(chan string)
defer close(resultsChannel)
var counter = 0
for _, port := range ports {
counter += 1
tcpTroubleShoot := troubleShootTcp{}
port := port
go func() {
err := tcpTroubleShoot.dialPort(&hostPort{host: host, port: port})
var res string
if err != nil {
res = fmt.Sprintf("TCP: Port %s on %s is closed, unreachable, or the connection timed out.\n", port, host)
} else {
// If no error occurs, the connection was successful, and the port is open.
res = fmt.Sprintf("TCP: Port %s on %s is open.\n", port, host)
}
resultsChannel <- res
}()
}
resultsArr := make([]string, counter)
for itr := 0; itr < counter; itr++ {
res := <-resultsChannel
fmt.Print(res)
resultsArr[itr] = res
}
return resultsArr
}