Hi Noob here trying to understand node RED and SSH Client Output

I'm trying to do a SSH using SSHV2. and I got it working. It now outputs msg: Object in an array[1]. Now how do I use this? I guess a Function Witch I know nothing about. and looking for your visdom here:)

This is what the debug is outputting.. Now i'm after the values "running" or "shut off"

msg : Object
object
code: 0
stdout: array[1]
0: string
4 Hydra-vm-Name running
stderr: array[0]
_msgid: "ed0d16cd6cc99354"

You are going to need to supply a lot more context here if we are going to be able to help you.

  • Explain in plain English what you are trying to achieve here
  • Exactly which nodes are you using?
  • Show the flow and explain what it is doing and exactly where the output you've shown has come from.

First guess is that you should expand the stdout array to see what the single entry in the array is.

@Stian this page in the docs provides a guide to understanding the output in the Debug sidebar and how to identify the path to any element of the message object.

https://nodered.org/docs/user-guide/messages

1 Like

Also I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour.

1 Like

Hi yes I ham trying to turn off a KVM VM at night I had been using a script on Linux to do it. But now with Home Assistant and NR. I would like for the Kids to be able to Turn it on off with a switch. I have made the Switch and it runs the SSH bash command fine. But I would like to get the state of the machine in NR. and I installed the addon SSHv2 and it is working. I have added the debug output. and I am after the running in that string 0: so I can feed it into a switch then if machine is on or off turn it on or off using Call service. I am sorry but I can not acces my machine at the time to get the flow out.

This is the strng output, and I only want the last part running .. (or shutdown if it's shutdown) The awk feature in the SSH message could hav efilter this, but somehow it does not wotk using SSH client in NR. Works fine on bash in linux.

Given the data you have shown us, this function will give you "running" or "shut" (not "shut off")

let data = msg.stdout[0].split(' ');
msg.payload = data[2];
return msg;

I hope that is some help.

I have no idea how that relates to what you first said you wanted, but I know nothing about Home Assistant, KVM VM, SSHv2, yaml or even what a Call service is.

OK s the others have said - give us the debug output by taking a screenshot of the expanded debug bar so we can see the full path.

I assume as you are running HA you have installed the NR HACS add-on ? Hence you are running this in a Docker container.

Presumably you have installed all the HA additional webhook nodes for interfacing events from HA into NR ?

Please post up the debug output, your flow that you have so far.

Also - if you have not worked with NR before - it may be easier for you to look at Automations in HA which should do what you want.

Craig

Sorry this is another post ted fail.. :slight_smile: sry.

Thank you I will try this.. :slight_smile:

@jbudd Thx but this did not give me any more output than before.
@craigcurtin here is a expanded debug. I am after the State of a VM . as you can see in the debug I get a ID if vm is up and running What I want is to get the name of VM if the VM is Off start it with a button in Home Assistant . and a Shutdown /reset VM if VM is stuck and they need to reset. it.
So the best option is if I can get the Name and State into a Switch. :slight_smile:

Thx everyone for helping out.

What command are you running to get that output ? and can you use the same command to only get the 'hydra-vm' ? and is there perhaps a direct api available ? or an json/xml/csv output option ?

@bakman2 this is the command:
ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' sjefen@192.168.198.66 "bash -l -c "virsh list --all""
It does not work with |grep 4| awk '{ print $3 }' so I made a script to run it on the host. but I realy want to be able to only add the VM name in NR and then get state from that machine.
Here is the script. if you see any thing I can use to improw it to make this work much obliged :slight_smile:

tmp=$(virsh list --all | grep " $1 " | awk '{ print $3}')
if ([ "x$tmp" == "x" ] || [ "x$tmp" != "xrunning" ])
then
    echo "down"
    # Try additional commands here...
else
    echo "running"
fi

I think I got it working my quotes is wrong :slight_smile: so I now used 'bash -lc "/path/to/script.sh argument"'
and I get running or down :slight_smile: as expected. Thank you for all the help guys and for pointing me to try it using KIS method :stuck_out_tongue:

Note that the virsh command also have options like virsh list --state-shutoff if you are looking for specifics.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.