Skip to content

Commit 5c9d173

Browse files
Merge pull request #139 from NETWAYS/feature/sshport
Add port configuration for SSH
2 parents fb301c0 + f84f878 commit 5c9d173

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Not supported at the moment is Kerberos.
2525
```
2626
Arguments:
2727
-H, --host string Host name, IP Address of the remote host (default "127.0.0.1")
28-
-p, --port int Port number WinRM
28+
-p, --port int Port number WinRM (default: 5985 & 5986 for TLS)
2929
-U, --user string Username of the remote host
3030
-P, --password string Password of the user
3131
-k, --insecure Don't verify the hostname on the returned certificate
@@ -37,6 +37,7 @@ Arguments:
3737
--icingacmd string Executes commands of Icinga PowerShell Framework (e.g. Invoke-IcingaCheckCPU)
3838
--auth string Authentication mechanism - NTLM | SSH (default "basic")
3939
--sshhost string SSH Host (mandatory if --auth=SSH)
40+
--sshport int SSH Port (default 22)
4041
--sshuser string SSH Username (mandatory if --auth=SSH)
4142
--sshpassword string SSH Password (mandatory if --auth=SSH)
4243
-t, --timeout int Abort the check after n seconds (default 10)

check.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
SSHHost string
4545
SSHUser string
4646
SSHPassword string
47+
SSHPort int
4748
validated bool
4849
}
4950

@@ -52,7 +53,7 @@ func BuildConfigFlags(fs *pflag.FlagSet) (config *Config) {
5253

5354
fs.StringVarP(&config.Host, "host", "H", "127.0.0.1",
5455
"Host name, IP Address of the remote host")
55-
fs.IntVarP(&config.Port, "port", "p", 0, "Port number WinRM") // TODO: document default
56+
fs.IntVarP(&config.Port, "port", "p", 0, "Port number WinRM (default: 5985 & 5986 for TLS)")
5657

5758
fs.StringVarP(&config.User, "user", "U", "", "Username of the remote host")
5859
fs.StringVarP(&config.Password, "password", "P", "", "Password of the user")
@@ -72,6 +73,7 @@ func BuildConfigFlags(fs *pflag.FlagSet) (config *Config) {
7273

7374
// AuthSSH
7475
fs.StringVar(&config.SSHHost, "sshhost", "", "SSH Host (mandatory if --auth=SSH)")
76+
fs.IntVarP(&config.SSHPort, "sshport", "", 22, "SSH Port")
7577
fs.StringVar(&config.SSHUser, "sshuser", "", "SSH Username (mandatory if --auth=SSH)")
7678
fs.StringVar(&config.SSHPassword, "sshpassword", "", "SSH Password (mandatory if --auth=SSH)")
7779

@@ -212,9 +214,8 @@ func (c *Config) Run(timeout time.Duration) (rc int, output string, err error) {
212214
return &winrm.ClientAuthRequest{}
213215
}
214216
case AuthSSH:
215-
// TODO: port configuration?
216217
var sshClient *ssh.Client
217-
sshClient, err = ssh.Dial("tcp", c.SSHHost+":22", &ssh.ClientConfig{
218+
sshClient, err = ssh.Dial("tcp", fmt.Sprintf("%s:%d", c.SSHHost, c.SSHPort), &ssh.ClientConfig{
218219
User: c.SSHUser,
219220
Auth: []ssh.AuthMethod{ssh.Password(c.SSHPassword)},
220221
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //nolint:gosec // TODO: really?

0 commit comments

Comments
 (0)