Node JS: Getting error when using tcp-ping module in apigee

Hi,

I'm using the tcp-ping module and also installed the node_modules for that in apigee.

Please find below is the node js code.

var tcpp = require('tcp-ping'); tcpp.probe('www.google.com', 80, function(err, available) { console.log(available); }); tcpp.ping({ address: 'www.google.com' }, function(err, data) { console.log(data); });

When I test this, I'm getting 500 internal server error.

{"fault":{"faultstring":"Script node executed prematurely: Script nj-ping.js exited with status code 0","detail":{"errorcode":"scripts.node.runtime.ScriptExitedError"}}}

Scriptoutput is as below.

*** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 29.552331, max: 59.545281, min: 25.998569, results: [ { seq: 0, time: 59.545281 }, { seq: 1, time: 26.29472 }, { seq: 2, time: 25.998569 }, { seq: 3, time: 26.159917 }, { seq: 4, time: 26.31019 }, { seq: 5, time: 26.414659 }, { seq: 6, time: 26.387812 }, { seq: 7, time: 26.120186 }, { seq: 8, time: 26.178659 }, { seq: 9, time: 26.113317 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 28.099805500000002, max: 46.232003, min: 25.688347, results: [ { seq: 0, time: 26.719822 }, { seq: 1, time: 26.225708 }, { seq: 2, time: 25.802322 }, { seq: 3, time: 46.232003 }, { seq: 4, time: 25.688347 }, { seq: 5, time: 25.917152 }, { seq: 6, time: 26.085629 }, { seq: 7, time: 26.435544 }, { seq: 8, time: 25.987074 }, { seq: 9, time: 25.904454 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script { address: 'www.google.com', port: 80, attempts: 10, avg: 29.339385400000005, max: 59.034029, min: 25.57112, results: [ { seq: 0, time: 59.034029 }, { seq: 1, time: 26.33388 }, { seq: 2, time: 26.297341 }, { seq: 3, time: 25.746513 }, { seq: 4, time: 25.787845 }, { seq: 5, time: 26.122622 }, { seq: 6, time: 26.049475 }, { seq: 7, time: 25.907924 }, { seq: 8, time: 25.57112 }, { seq: 9, time: 26.543105 } ] } true *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 29.479161599999998, max: 58.902149, min: 25.94649, results: [ { seq: 0, time: 58.902149 }, { seq: 1, time: 26.431136 }, { seq: 2, time: 25.94649 }, { seq: 3, time: 26.240265 }, { seq: 4, time: 26.267003 }, { seq: 5, time: 25.956701 }, { seq: 6, time: 26.216872 }, { seq: 7, time: 26.70566 }, { seq: 8, time: 26.045721 }, { seq: 9, time: 26.079619 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 30.664022900000003, max: 59.057425, min: 25.825715, results: [ { seq: 0, time: 59.057425 }, { seq: 1, time: 25.825715 }, { seq: 2, time: 26.5129 }, { seq: 3, time: 26.051442 }, { seq: 4, time: 26.129827 }, { seq: 5, time: 26.161203 }, { seq: 6, time: 26.01639 }, { seq: 7, time: 38.175671 }, { seq: 8, time: 26.191469 }, { seq: 9, time: 26.518187 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 29.645783299999994, max: 60.07772, min: 25.955065, results: [ { seq: 0, time: 60.07772 }, { seq: 1, time: 25.955065 }, { seq: 2, time: 26.321326 }, { seq: 3, time: 26.552822 }, { seq: 4, time: 26.130396 }, { seq: 5, time: 26.416793 }, { seq: 6, time: 26.399723 }, { seq: 7, time: 26.400152 }, { seq: 8, time: 26.083942 }, { seq: 9, time: 26.119894 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 31.621371999999997, max: 59.96495, min: 25.60728, results: [ { seq: 0, time: 59.96495 }, { seq: 1, time: 25.854694 }, { seq: 2, time: 26.355518 }, { seq: 3, time: 25.996082 }, { seq: 4, time: 26.615463 }, { seq: 5, time: 26.137608 }, { seq: 6, time: 47.800928 }, { seq: 7, time: 25.87297 }, { seq: 8, time: 26.008227 }, { seq: 9, time: 25.60728 } ] } *** Script nj-ping.js exited with status code 0 *** Starting script true { address: 'www.google.com', port: 80, attempts: 10, avg: 29.488880900000005, max: 60.611127, min: 25.622124, results: [ { seq: 0, time: 60.611127 }, { seq: 1, time: 25.772864 }, { seq: 2, time: 26.375957 }, { seq: 3, time: 26.064949 }, { seq: 4, time: 25.622124 }, { seq: 5, time: 25.936646 }, { seq: 6, time: 26.152048 }, { seq: 7, time: 26.283004 }, { seq: 8, time: 26.125113 }, { seq: 9, time: 25.944977 } ] } *** Script nj-ping.js exited with status code 0

Please assist on this in resolving this.

Thanks,

Bindu

Solved Solved
0 6 1,157
1 ACCEPTED SOLUTION

Hi @Bindu.Kadiyala,

Apigee has restricted support for Node's "net" module which is being used internally by tcp-ping. Please refer the documentation for the same here.

http://docs.apigee.com/api-services/content/understanding-edge-support-nodejs-modules

If your use case is to check if target server has the specified port open or not, then you can use the "Health Monitor" feature of Target Endpoint configurations. It allows both HTTP and TCP monitoring.

Details for the same can be found at below link.

http://docs.apigee.com/api-services/content/load-balancing-across-backend-servers#healthmonitoring

Hope this helps.

View solution in original post

6 REPLIES 6

Hi @Bindu.Kadiyala,

Apigee has restricted support for Node's "net" module which is being used internally by tcp-ping. Please refer the documentation for the same here.

http://docs.apigee.com/api-services/content/understanding-edge-support-nodejs-modules

If your use case is to check if target server has the specified port open or not, then you can use the "Health Monitor" feature of Target Endpoint configurations. It allows both HTTP and TCP monitoring.

Details for the same can be found at below link.

http://docs.apigee.com/api-services/content/load-balancing-across-backend-servers#healthmonitoring

Hope this helps.

Hi @Bindu.Kadiyala, You can use something like below if all you want to do is check the ports are open or not.

// dependencies
var express = require('express');
// var bodyParser = require('body-parser');
// var controller = require('./controller');


var net = require('net');
var client = new net.Socket();


var app = express();


app.get('/connect-google',function(req,res){
    console.log('Connecting....')
    
    client.connect("80", "google.com", connectedFn);

function connectedFn(){
    console.log("Connected to Google");
res.send("hello");
    client.destroy();
}
});

// start node app
app.listen(3000);

you can tweak the code with your requirements.

Cheers!!

Hi Mohammed,

Thanks for your help on this.

I would like to pass the hostname from the query parameter and this is what I have used in the code and also include apigee-access module

var express = require('express');

var net = require('net');

var http = require('http');

var apigee = require('apigee-access');

var client = new net.Socket();

var app = express();

app.get('/',function(req,res)

{

var hostname = apigee.getVariable(req, 'req.queryparam.hostname');

console.log('Connecting....');

client.connect("80", hostname, connectedFn);

function connectedFn(){

console.log("Connected to host");

res.send("Connected");

client.destroy(); } });

// start node app app.listen(3000);

I'm getting 500 internal error. Kindly advice.

Thanks,

Bindu

Hi @Bindu.Kadiyala, Please use below for getting "hostname" from query parameters instead of apigee-access, as apigee-access only works with "http" module request object.

app.get('/connect-google',function(req,res){
    console.log('Connecting....');
    client.connect("80", req.query.hostname, connectedFn);


function connectedFn(){
    console.log("Connected to Google");
    res.send("Connected to " + req.query.hostname);
    client.destroy();
}
});

Since here I have used "express" to create the app server the request object will be a little different than that of "http" module.

PS: Please mention user names with @Mohammed Zuber. This will send the notification to the user 🙂

Cheers!

Hi @Mohammed Zuber ,

Thanks for your assistance.

I have tried with req.query.hostname but it is throwing 504 gateway timed out error

Request URL:

http://test.apigee.net/tcptest?hostname="google.com"

When I hard coded it to "google.com" then it is giving 200 response code.

client.connect("80", "google.com", connectedFn);

Kindly advice.

Thanks,

Bindu

Hi @Mohammed Zuber,

It is working with this URL http://test.apigee.net/tcptest?hostname=google.com

Thanks for your assistance.

Thanks,

Bindu