Author Topic: SSH.Command with different port  (Read 99 times)

pvo

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
SSH.Command with different port
« on: December 29, 2020, 03:13:54 pm »
I've seen that that the SSH.Command uses fixed port 22.
It would be useful to have the possibility to specify different port. Can I add the fifth optional parameter port with default value 22 to the SSH.Command? Would you add it this change to your sources?

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 7140
    • View Profile
Re: SSH.Command with different port
« Reply #1 on: December 29, 2020, 08:01:43 pm »
Hi,

port can be specified as part of host name after : character. This is relevant piece of code from SSH subagent: https://github.com/netxms/netxms/blob/819a9418773ce2fe4b5589397a70716d736c652e/src/agent/subagents/ssh/handlers.cpp#L39

Best regards,
Victor

pvo

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SSH.Command with different port
« Reply #2 on: December 29, 2020, 08:10:58 pm »
Hi Victor,

thank you for your answer. It was good idea first ask before I started  to modify the sources  ;).

If I understand this right, there is no such posibility for the NXSL function executeSSHCommand. Is it so?

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 7140
    • View Profile
Re: SSH.Command with different port
« Reply #3 on: December 29, 2020, 08:26:02 pm »
Yes, that's actually a problem - executeSSHCommand uses SSH settings from node it is called on, and it is actually not possible to set SSH port for node.
In NXSL workaround is to use agentReadList - all that executeSSHCommand does is reading agent list with necessary arguments (properly escaped). But it has to be fixed anyway - SSH port for node definitely should be configurable, and maybe optional port number, login, and password arguments can be added to executeSSHCommand.

Best regards,
Victor

pvo

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SSH.Command with different port
« Reply #4 on: December 29, 2020, 08:32:08 pm »
Thank you.
I know this workaround.