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

**URL:** https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917
**Category:** Feature Requests
**Created:** [19 September 2022 11:12 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917 "2022-09-19T11:12:36Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [19 September 2022 11:12 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/1 "2022-09-19T11:12:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [19 September 2022 11:18 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/2 "2022-09-19T11:18:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [19 September 2022 12:12 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/3 "2022-09-19T12:12:32Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [19 September 2022 12:52 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/4 "2022-09-19T12:52:43Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [19 September 2022 13:00 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/5 "2022-09-19T13:00:06Z")

</div>

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.

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [19 September 2022 13:08 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/6 "2022-09-19T13:08:30Z")

</div>

@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.

---

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [19 September 2022 13:24 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/7 "2022-09-19T13:24:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [2 October 2022 08:43 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/8 "2022-10-02T08:43:12Z")

</div>

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

```auto
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...

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [2 October 2022 09:10 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/9 "2022-10-02T09:10:16Z")

</div>

@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

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

```

to

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

```

At line 243 you should change

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

```

to

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

```

Then restart node-red and try again?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [2 October 2022 09:35 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/10 "2022-10-02T09:35:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [2 October 2022 10:51 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/11 "2022-10-02T10:51:38Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [2 October 2022 10:55 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/12 "2022-10-02T10:55:52Z")

</div>

should be there already

---

<div class="post-metadata">

### Author: ![Hunter](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hunter/32/60045_2.png) [@Hunter](https://discourse.nodered.org/u/Hunter)
#### Post date: [2 October 2022 11:01 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/13 "2022-10-02T11:01:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 December 2022 11:01 UTC](https://discourse.nodered.org/t/node-red-node-ping-add-name-in-output/67917/14 "2022-12-01T11:01:57Z")

</div>

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