Created
October 15, 2021 09:20
-
-
Save MatsA/92af2fdec846cca94c57cc4d96285113 to your computer and use it in GitHub Desktop.
NodeRed flow for SIGNL4 alerts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": "2282c8f1.9bde88", | |
"type": "tab", | |
"label": "Export", | |
"disabled": false, | |
"info": "" | |
}, | |
{ | |
"id": "cea17d201d504ef4", | |
"type": "udp in", | |
"z": "2282c8f1.9bde88", | |
"name": "AIS msg via UDP", | |
"iface": "", | |
"port": "5697", | |
"ipv": "udp4", | |
"multicast": "false", | |
"group": "", | |
"datatype": "utf8", | |
"x": 140, | |
"y": 120, | |
"wires": [ | |
[ | |
"fcd178bef5719698" | |
] | |
] | |
}, | |
{ | |
"id": "7314b4ebb41b4c52", | |
"type": "comment", | |
"z": "2282c8f1.9bde88", | |
"name": "Check if AIS messages are received at least every hour, otherwise send mess to SIGNL4", | |
"info": "", | |
"x": 370, | |
"y": 40, | |
"wires": [] | |
}, | |
{ | |
"id": "566a200cc5693f44", | |
"type": "inject", | |
"z": "2282c8f1.9bde88", | |
"name": "1 second clock", | |
"props": [ | |
{ | |
"p": "payload" | |
}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "1", | |
"crontab": "", | |
"once": true, | |
"onceDelay": 0.1, | |
"topic": "", | |
"payload": "clock", | |
"payloadType": "str", | |
"x": 160, | |
"y": 80, | |
"wires": [ | |
[ | |
"fcd178bef5719698" | |
] | |
] | |
}, | |
{ | |
"id": "fcd178bef5719698", | |
"type": "function", | |
"z": "2282c8f1.9bde88", | |
"name": "Timeout are sent to SIGNL4", | |
"func": "let timeoutTime = 600 // Max seconds before a missing AIS message is reported\n\nif (msg.payload == \"clock\"){ // \"clock\" transaction => add to timeoutTimer\n \n timeoutTimerValue = flow.get('timeoutTimer') + 1;\n flow.set('timeoutTimer', timeoutTimerValue)\n \n // Show timeoutTimerValue\n node.status({fill:\"green\",shape:\"dot\",text:\"Timeout timer \" + timeoutTimerValue});\n \n // Save the longest time between AIS messages\n timeoutTimerMaxValue = flow.get('timeoutTimerMax');\n if (timeoutTimerValue > timeoutTimerMaxValue){ \n flow.set('timeoutTimerMax', timeoutTimerValue);\n }\n // No AIS message received within \"timeoutTime\" => Send Signl4 msg\n if (timeoutTimerValue >= timeoutTime){\n \n flow.set('timeoutTimer', 0);\n msg.payload = {\n 'Subject': 'No AIS info received in one hour',\n 'X-S4-Service': \"IT\"\n };\n return msg;\n }\n else {\n return null; \n }\n\n} else { // AIS transaction => reset timeoutTimer\n flow.set('timeoutTimer', 0);\n return null; \n}\n\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "// Code added here will be run once\n// whenever the node is started.\nflow.set('timeoutTimer', 0);\nflow.set('timeoutTimerMax', 0);", | |
"finalize": "", | |
"libs": [], | |
"x": 420, | |
"y": 80, | |
"wires": [ | |
[ | |
"dc5ecf93eb7caa8c", | |
"e55f66944299ad0e" | |
] | |
] | |
}, | |
{ | |
"id": "dc5ecf93eb7caa8c", | |
"type": "debug", | |
"z": "2282c8f1.9bde88", | |
"name": "", | |
"active": true, | |
"tosidebar": true, | |
"console": false, | |
"tostatus": false, | |
"complete": "false", | |
"statusVal": "", | |
"statusType": "auto", | |
"x": 650, | |
"y": 120, | |
"wires": [] | |
}, | |
{ | |
"id": "e55f66944299ad0e", | |
"type": "http request", | |
"z": "2282c8f1.9bde88", | |
"name": "SIGNL4 Alert", | |
"method": "POST", | |
"ret": "obj", | |
"paytoqs": "ignore", | |
"url": "https://connect.signl4.com/webhook/xxxxxxxxx", | |
"tls": "", | |
"persist": false, | |
"proxy": "", | |
"authType": "", | |
"x": 650, | |
"y": 80, | |
"wires": [ | |
[] | |
], | |
"icon": "node-red/alert.png" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment