mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Better error catching in ping node for spawn errors...
This commit is contained in:
parent
739e8cd9b6
commit
89d7853891
@ -18,6 +18,7 @@ module.exports = function(RED) {
|
|||||||
else { node.error("Sorry - your platform - "+plat+" - is not recognised."); }
|
else { node.error("Sorry - your platform - "+plat+" - is not recognised."); }
|
||||||
var res = false;
|
var res = false;
|
||||||
var line = "";
|
var line = "";
|
||||||
|
var fail = false;
|
||||||
//var regex = /from.*time.(.*)ms/;
|
//var regex = /from.*time.(.*)ms/;
|
||||||
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/;
|
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/;
|
||||||
ex.stdout.on('data', function (data) {
|
ex.stdout.on('data', function (data) {
|
||||||
@ -26,7 +27,20 @@ module.exports = function(RED) {
|
|||||||
//ex.stderr.on('data', function (data) {
|
//ex.stderr.on('data', function (data) {
|
||||||
//console.log('[ping] stderr: ' + data);
|
//console.log('[ping] stderr: ' + data);
|
||||||
//});
|
//});
|
||||||
|
ex.on('error', function (err) {
|
||||||
|
fail = true;
|
||||||
|
if (err.code === "ENOENT") {
|
||||||
|
node.error(err.code + " ping command not found");
|
||||||
|
}
|
||||||
|
else if (err.code === "EACCES") {
|
||||||
|
node.error(err.code + " can't run ping command");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node.error(err.code);
|
||||||
|
}
|
||||||
|
});
|
||||||
ex.on('close', function (code) {
|
ex.on('close', function (code) {
|
||||||
|
if (fail) { fail = false; return; }
|
||||||
var m = regex.exec(line)||"";
|
var m = regex.exec(line)||"";
|
||||||
if (m !== '') {
|
if (m !== '') {
|
||||||
if (m[1]) { res = Number(m[1]); }
|
if (m[1]) { res = Number(m[1]); }
|
||||||
|
@ -11,9 +11,11 @@ Run the following command in your Node-RED user directory - typically `~/.node-r
|
|||||||
|
|
||||||
npm install node-red-node-ping
|
npm install node-red-node-ping
|
||||||
|
|
||||||
**Gotcha**
|
**Gotchas**
|
||||||
|
|
||||||
On some versions on Raspbian (Raspberry Pi) `ping` seems to be a root only command.
|
1 This won't run on Ubunti Snap as the strict container does not allow spawning of external commands (like ping).
|
||||||
|
|
||||||
|
2 On some versions on Raspbian (Raspberry Pi) `ping` seems to be a root only command.
|
||||||
The fix is to allow it as follows
|
The fix is to allow it as follows
|
||||||
|
|
||||||
sudo setcap cap_net_raw=ep /bin/ping
|
sudo setcap cap_net_raw=ep /bin/ping
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-ping",
|
"name" : "node-red-node-ping",
|
||||||
"version" : "0.0.15",
|
"version" : "0.0.16",
|
||||||
"description" : "A Node-RED node to ping a remote server, for use as a keep-alive check.",
|
"description" : "A Node-RED node to ping a remote server, for use as a keep-alive check.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user