Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Synthetic API monitor script check


#1

Hi All,
I have a url which should be under monitoring.But URL is IE based and wont work in chorme or in mozilla.So i created a api get request script with 401 status code to ignore as it was coming as unauthorised access.So wanted to check if this script works fine:

//Import the `assert` module to validate results.
var assert = require('assert');

var options = {
    url: "https://bix.aon.net",
        "headers": {
          "oauth_clientid": 123,
          
           },
        "timeout": 15000
        };

$http.get(options, function(error, response, body) {
    console.log(response.statusCode + " status code")
    assert.ok(response.statusCode == 401, 'Expected 401 OK response');  
       });

If not what else type of monitor.i can try.i have tried all.


#2

Hi @pradeep.p, this looks like it’s an internal site and not publicly accessible is that correct? If so, and you’re just looking to check if the site is up and running, you could use a Ping monitor run on a Private Location?.

Hope this helps :slight_smile:


#3

Hi Douglas,
Yes its an internal site url.The issue with ping monitoring was 401 error is coming.So configured this api script with 401 error as success as we dont have the credentials for the url.


#4

@pradeep.p great so in this case you would have to run the Ping Monitor on a Private Location, if you are already doing that would you mind sending me a permalink to the monitor and I can take a closer look :slight_smile:


#5

Hi Douglas,
Here is the permalink of the monitor:
https://synthetics.newrelic.com/accounts/1737254/monitors/705221dc-56a2-4145-98dc-c15e0c006f8b?tw[start]=1555665867.427&tw[end]=1555667667.427


#6

Hi @pradeep.p,

Taking a look at the link you provided, I think I see what you’re talking about. The Ping monitor is receiving 401 Unauthorized responses from the endpoint, resulting in failures.

It sounds like this behavior is expected due to a credentials issue. In that case, an API Test monitor would be your best option for monitoring this endpoint. With an API Test monitor, you can write a script to succeed even when the target endpoint returns a non-200/300 response. The script you provided in your initial post looks like it should work.

Have you created an API Test monitor with this script? If so, we’d be happy to take a look at it if it’s not working as expected. You can either send us a permalink via DM or post it here.


#7

//Import the assert module to validate results.
var assert = require(‘assert’);

var options = {
url: “https://bix.aon.net”,
“headers”: {
“oauth_clientid”: 123,

       },
    "timeout": 15000
    };

$http.get(options, function(error, response, body) {
console.log(response.statusCode + " status code")
assert.ok(response.statusCode == 401, ‘Expected 401 OK response’);
});
This is the API script i created to supress 401 error.or anything else i can do with it.


#8

Try changing the last line from:

assert.ok(response.statusCode == 401, ‘Expected 401 OK response’);

to:

assert.equal(response.statusCode, 401, 'Expected a 401 response');

#9

Hi Phil,
The script is working fine.Just wanted to know is this script is fine with the monitoring.