Node-red-node-ping : add name in output

Hello,

This ping node offers the ping result as payload and the target as topic.
By default the target is shown on the node, if a name is entered, the name is shown.
I would like this name to be available in the output data, somehow.

Is this possible?

Kind regards,

Peter Hunt.

In Node-RED, typically the name field is just used to help make your flows clearer in the Editor and they are not involved with msg flows. So this request would be a break from that standard approach.

If you change to trigger mode you can send an object or array of objects (to ping multiple items) with any amount of additional properties that you can see in the output msg. See the built in help.

Thanks both, as for the trigger, I understand what you mean but this doesn't offer what I'm looking for, as I want to monitor several IP's and if I need as much triggers as servers, I might as well create an array in a function node as well :slight_smile:

Here is how i do it, i feed an array of objects to the ping node( as @Steve-Mcl describes) including any extra info i want to include, in this case a name property. I then join the results back to an array , I then create a table for display etc.

[{"id":"c59f8e4a.b682","type":"ping","z":"336d1a7d.c0d64e","protocol":"Automatic","mode":"triggered","name":"","host":"","timer":"20","inputs":1,"x":195,"y":1460,"wires":[["10110cd2.4cde1b"]],"l":false},{"id":"d9da2791.99656","type":"inject","z":"336d1a7d.c0d64e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"[{\"host\":\"192.168.1.10\",\"name\":\"OpenLuup/MSR\"},{\"host\":\"192.168.1.11\",\"name\":\"Vera\"},{\"host\":\"192.168.1.149\",\"name\":\"Ezlo\"},{\"host\":\"192.168.1.12\",\"name\":\"CCTV\"},{\"host\":\"192.168.1.25\",\"name\":\"Node-red/Mosquitto\"}]","payloadType":"json","x":135,"y":1460,"wires":[["c59f8e4a.b682"]],"l":false},{"id":"10110cd2.4cde1b","type":"change","z":"336d1a7d.c0d64e","name":"","rules":[{"t":"set","p":"ping.online","pt":"msg","to":"payload ? true : false","tot":"jsonata"},{"t":"move","p":"ping","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload.style","pt":"msg","to":"$$.payload.online? \"green\" : \"red\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":255,"y":1460,"wires":[["19e7a9a.b9a3256"]],"l":false},{"id":"19e7a9a.b9a3256","type":"join","z":"336d1a7d.c0d64e","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"ping.name","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"6","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":315,"y":1460,"wires":[["88465e53.68064"]],"l":false},{"id":"88465e53.68064","type":"change","z":"336d1a7d.c0d64e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload^(name)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":375,"y":1460,"wires":[["2d3e081f.8a5a58"]],"l":false},{"id":"2d3e081f.8a5a58","type":"debug","z":"336d1a7d.c0d64e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":1420,"wires":[]}]
1 Like

@Hunter I am on mobile and find it difficult to write long posts and provide demos but @E1cid has nicely summed up exactly what I was saying.

In other words if you use an array the only 1 trigger and 1 ping node is required.

I really should have RTFM, this dynamically setting of the payload solved my issues.
Thanks for your replies! :slight_smile:

This node has recently been updated but it seems that the array is not working no more

msg.payload = [
    {
        "host": "172.18.1.2",
        "name": "1"
    },
    {
        "host": "172.18.1.3",
        "name": "2"
    },
    {
        "host": "172.18.1.4",
        "name": "3"
    },
    {
        "host": "website.nl",
        "name": "website.nl"
    }
];
return msg;

This results in 4 pings to website.nl. Before the update, I had 4 different pings...

@hunter this may be due to a reference value change (i.e. the msg object probably needs to be cloned)

Are you in a position add a line of code to your core code and test a modification?

You would need to locate the file 88-ping.js - it will be in the nodes_modules of your .node-red directory

At line 238 you should change

if (element) { doPing(node, element, msg, false); }

to

if (element) { doPing(node, element, RED.util.cloneMessage(msg), false); }

At line 243 you should change

if (element) { doPing(node, element, msg, true); }

to

if (element) { doPing(node, element, RED.util.cloneMessage(msg), true); }

Then restart node-red and try again?

1 Like

Good old pass-by-reference... - pushed fix as v0.3.3

Thanks for checking this out guys. I'm not able to modify the core code myself, I'd prefer to wait for the v0.3.3 :slight_smile:

should be there already

Yes, just updated and the issue is fixed now. Thanks for the quick response :slight_smile:

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