mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
re-re-fix Ping node to assemble full result before parsing....
This commit is contained in:
parent
ebbd9f4494
commit
d47b7f57a2
@ -32,21 +32,21 @@ module.exports = function(RED) {
|
|||||||
else if (plat == "darwin") { ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]); }
|
else if (plat == "darwin") { ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]); }
|
||||||
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 regex = /from.*time.(.*)ms/;
|
||||||
|
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9\.]*)/;
|
||||||
ex.stdout.on('data', function (data) {
|
ex.stdout.on('data', function (data) {
|
||||||
//console.log('[ping] stdout: ' + data.toString());
|
line += data.toString();
|
||||||
var regex = /=.*[<|=]([0-9]*).*TTL|ttl..*=([0-9]*)/;
|
|
||||||
//var regex = /from.*time.(.*)ms/;
|
|
||||||
var m = regex.exec(data.toString())||"";
|
|
||||||
if (m !== '') {
|
|
||||||
if (m[1]) { res = Number(m[1]); }
|
|
||||||
if (m[2]) { res = Number(m[2]); }
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
ex.stderr.on('data', function (data) {
|
ex.stderr.on('data', function (data) {
|
||||||
//console.log('[ping] stderr: ' + data);
|
//console.log('[ping] stderr: ' + data);
|
||||||
});
|
});
|
||||||
ex.on('close', function (code) {
|
ex.on('close', function (code) {
|
||||||
//console.log('[ping] result: ' + code);
|
var m = regex.exec(line)||"";
|
||||||
|
if (m !== '') {
|
||||||
|
if (m[1]) { res = Number(m[1]); }
|
||||||
|
if (m[2]) { res = Number(m[2]); }
|
||||||
|
}
|
||||||
var msg = { payload:false, topic:node.host };
|
var msg = { payload:false, topic:node.host };
|
||||||
if (code === 0) { msg = { payload:res, topic:node.host }; }
|
if (code === 0) { msg = { payload:res, topic:node.host }; }
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-ping",
|
"name" : "node-red-node-ping",
|
||||||
"version" : "0.0.1",
|
"version" : "0.0.3",
|
||||||
"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…
Reference in New Issue
Block a user