ping hosts

Ping hosts on the list. Keeping statistics min/current/max and triggering an alarm if the value exceeds the set.

https://flows.nodered.org/node/node-red-contrib-advanced-ping

May need node red update

  • Node-RED version: v2.1.3
  • Node.js version: v14.18.1
[{"id":"eecd83b1b68acc89","type":"function","z":"a872a8f8280b40c1","name":"hosts","func":"const monitored = flow.get('monitor') ??\n    {'cur':0,\n    'alarm':[],\n    'hosts':[   /*add new values here HOST must be unique*/\n        {'title':'Вконтакте','host':'vk.com',     'min':50,'cur':60,'max':150,'alarm':200},\n        {'title':'Яндекс',   'host':'ya.ru',      'min':50,'cur':60,'max':150,'alarm':200},\n        {'title':'Майл',     'host':'mail.com',   'min':50,'cur':60,'max':150,'alarm':5},\n        {'title':'Полмира',  'host':'polmira.ru', 'min':50,'cur':60,'max':150,'alarm':200},\n        {'title':'Гугл',     'host':'google.com', 'min':50,'cur':60,'max':150,'alarm':1}\n    ]}\n\n//don't edit it\nmonitored.cur >= monitored.hosts.length -1 ? monitored.cur = 0 : monitored.cur += 1\nmsg.data = monitored.hosts[monitored.cur]\nmsg.host = msg.data.host\nflow.set('monitor',monitored)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":458,"y":318,"wires":[["2543a62a0d0c092a"]]},{"id":"2543a62a0d0c092a","type":"adv ping","z":"a872a8f8280b40c1","name":"ping","host":"","x":572,"y":318,"wires":[["82f7ba9dbfe7fc38"]]},{"id":"dabef35a63f69f06","type":"inject","z":"a872a8f8280b40c1","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":375,"y":318,"wires":[["eecd83b1b68acc89"]],"l":false},{"id":"82f7ba9dbfe7fc38","type":"function","z":"a872a8f8280b40c1","name":"update","func":"const monitored = flow.get('monitor') ?? {}\n\nmonitored.hosts[monitored.cur].cur = msg.payload\nif(monitored.hosts[monitored.cur].min > msg.payload){\n    monitored.hosts[monitored.cur].min = msg.payload\n} \n\nif(monitored.hosts[monitored.cur].max < msg.payload){\n    monitored.hosts[monitored.cur].max = msg.payload\n} \n\nif(msg.payload > monitored.hosts[monitored.cur].alarm){\n    if(!monitored.alarm.find( h => h.host === msg.host)){\n        monitored.alarm.push({'title':msg.data.title,\n                              'host': msg.host, \n                              'ping': msg.payload})\n    }\n}\n\nflow.set('monitor',monitored)\nnode.warn(`Ответ от ${msg.host}: число байт=32 время=${msg.payload} TTL=54`)","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":696,"y":318,"wires":[]},{"id":"bdc2efddeff7f2e4","type":"function","z":"a872a8f8280b40c1","name":"Alarm","func":"const monitored = flow.get('monitor') ?? {}\nlet alarm = monitored.alarm ?? []\n\nif(alarm.length != 0){\n    msg.payload = monitored.alarm\n    monitored.alarm = []\n    flow.set('monitor', monitored)\n    return msg;\n}\nelse { return null }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":572,"y":354,"wires":[["6f6c7adc8e12d7e0"]]},{"id":"6f6c7adc8e12d7e0","type":"debug","z":"a872a8f8280b40c1","name":"alarm","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":686,"y":354,"wires":[]},{"id":"bbb6453f12bb38b7","type":"inject","z":"a872a8f8280b40c1","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":375,"y":354,"wires":[["bdc2efddeff7f2e4"]],"l":false},{"id":"70541b6b799c1b34","type":"function","z":"a872a8f8280b40c1","name":"hosts","func":"const monitored = flow.get('monitor') ?? {}\nlet hosts = monitored.hosts ?? []\nif(hosts.length != 0){\n    msg.payload = monitored.hosts\n    return msg;\n}\nelse { return null }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":572,"y":390,"wires":[["3ea9c545cfaeafbd"]]},{"id":"3ea9c545cfaeafbd","type":"debug","z":"a872a8f8280b40c1","name":"show","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":686,"y":390,"wires":[]},{"id":"6313322a4aec8f90","type":"inject","z":"a872a8f8280b40c1","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":375,"y":390,"wires":[["70541b6b799c1b34"]],"l":false}]

Flow Info

Created 3 years, 9 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • debug (x2)
  • function (x4)
  • inject (x3)
Other

Tags

  • ping
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option