Ping Network Devices From a List

That flow is a bit much for something simple. It is also out of date due to the node-red-node-ping now able to ping multiple devices.

This is a basic working demo...

image

...

  • Import the flow
  • adjust the ping list in the inject.
    • alternatively get this list from a database or other place - just ensure it is the same format.
  • select your bot in the telegram node

flow...

[{"id":"e9e310aa.76a0d","type":"debug","z":"83a23089.dc697","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1610,"y":80,"wires":[]},{"id":"8614c5fd.bf5588","type":"inject","z":"83a23089.dc697","name":"*** Setup devices to ping here ***","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"name\":\"router\",\"host\":\"192.168.1.1\"},{\"name\":\"nvr\",\"host\":\"192.168.1.50\"},{\"name\":\"cam1\",\"host\":\"192.168.1.38\"},{\"name\":\"bad device\",\"host\":\"192.168.2.99\"}]","payloadType":"json","x":1230,"y":80,"wires":[["29069ffe.93c78"]]},{"id":"29069ffe.93c78","type":"ping","z":"83a23089.dc697","mode":"triggered","name":"","host":"","timer":"20","inputs":1,"x":1450,"y":80,"wires":[["e9e310aa.76a0d","9774ee36.6c7ff"]]},{"id":"9774ee36.6c7ff","type":"function","z":"83a23089.dc697","name":"Prepare telegram message (if bad)","func":"if(msg.payload === false) {\n    msg.payload = {};\n    msg.payload.type = 'message';\n    msg.payload.content = `Ping to '${msg.ping.name}' (${msg.ping.host}) failed`;\n    msg.payload.chatId = 11111111\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":160,"wires":[["f275d6de.1e4fc8","8d95831d.c0745"]]},{"id":"f275d6de.1e4fc8","type":"debug","z":"83a23089.dc697","name":"to Telegram node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1650,"y":160,"wires":[]},{"id":"8d95831d.c0745","type":"telegram sender","z":"83a23089.dc697","name":"","bot":"fa7a9376.321ce","haserroroutput":false,"outputs":1,"x":1650,"y":220,"wires":[[]]},{"id":"fa7a9376.321ce","type":"telegram bot","botname":"mybot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","botpath":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

PS: when you post code or flow - always put it in a code block

```
code goes between backticks otherwise it looks rubbish and actually doesn't work due to forum formatting!!!
```

1 Like