mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
6c88122fdb
* 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>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// 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
|
|
}
|