Example of how to setup SSH script/commands?

Started by Millenium7, May 28, 2019, 08:16:33 AM

Previous topic - Next topic

Millenium7

I'm slowly getting more comfortable with NetXMS but unfortunately it can be difficult to find out how to actually implement things at times :( One of these is how to send SSH commands to a device. I've googled and seen this is possible but I can't find any actual examples to help set it up

I want to be able to be able to send commands via SSH to a device. A simple example being I have created a DCI summary table to show MikroTik RouterOS versions. I want to be able to select all that are outdated, right click, choose Tools->MikroTik Commands->Update RouterOS
And in the background NetXMS would connect to the device with SSH and execute '/system package update install'

How do I set this up?
Then once I get the basics working, is it possible to parse more advanced commands via SSH? I.e. using variables so I could choose 'Update RouterOS' but specify a time as a variable and it would send
'/system scheduler add on-event="/system package update install" start-time=$NetXMSTimeVariable'
So the device would update at 3:30am instead of immediately

Victor Kirhenshtein

Hi,

you can use NXSL script and function AgentReadList like this:


AgentReadList($node, "SSH.Command(mikrotik_ip,login,password,/system package update install)");


where $node is a node with SSH subagent installed. Of course you can use string concatenation to insert proper credentials and device IP address. For example, if variable $node points to NetXMS server node and variable mt to Mikrotik device, you can do


AgentReadList($node, "SSH.Command(" . mt->ipAddr . ",login,password,/system package update install)");


Best regards,
Victor

Millenium7

Only agent is the NetXMS server itself, so can I just use 127.0.0.1 for the node?
And how about longer commands with multiple lines? I have some custom scripts that are 50 lines long, impossible to put them into a single line

Victor Kirhenshtein

Yes, but you have to use node object here, not IP address. You can use FindObject or FindNodeObject functions to get object by name.

Longer commands are not possible without agent and/or server modifications. Currently there is 1024 character limit on parameter length in AgentRead... functions.

I've also created couple of feature requests for SSH improvements:
https://track.radensolutions.com/issue/NX-1649
https://track.radensolutions.com/issue/NX-1650

Best regards,
Victor

Egert143

Hello

Millenium7, did you get ssh script working ? I could use some examples also, how to get basic ssh commands working.

Egert