Monitor the response status of website URL

Hi Support,
We want to set up a monitor to make sure tenant’s server is up and running. The requirement is pretty simple: We want to make sure web server return “Forbidden” (response is 403, and text in the webpage is “Forbidden”) and not a 404 or 502 or something when clicking the link below (example).
https://iuc-dev.ddd-dev-01-50159a23985222300aa854e0f89024-0000.east.containers.appdomain.cloud/api/v1/consent
Here, I have a couple of questions:

  1. Can I use synthetic monitor to do it? This url provides some examples. Should I use scripted browser to do it? One thing I am not quite clear is, I want to check both text in the webpage and the return status (403). How can I check both?
  2. I need to alert people if something goes wrong, I understand that I need to create alert policy, but how the browser script knows the alert policy exists and sent out alert based on the policy?

Thank you,
William

Hi, @wshao1: Here is a scripted browser example that checks both status code and webpage text; it does so by making two requests:

const assert = require('assert');
const $http = require('request');

const expectedStatusCode = 200;
const expectedText = 'Gmail';

// First, check status code
$http.get('https://www.google.com/', 
  // Callback
  function (err, response, body) {
    assert.equal(response.statusCode, expectedStatusCode, 'Expected status code ' + expectedStatusCode);
  }
);

// Next, check page body for expected text
$browser.get('https://www.google.com/')
  .then(function() {
    return $browser.findElement($driver.By.css('body'))
    .then(function(element) {
      return element.getText()
      .then(function(text) {
        assert.equal(true, text.indexOf(expectedText) != -1, 'Page does not contain expected text');
      });
    });
  });

You may follow the documentation here to add your Synthetic monitor to an alert policy: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/using-monitors/alerts-synthetic-monitoring. If the monitor fails, the alert condition will create a violation and send out notifications according to the policy’s notification preference.

1 Like

Hi @philweber
The script is very helpful. The issue is, we expect to get the status 403 (Forbidden). but the script gives error:
image
Normally, 403 is bad, but in this case, it is correct (this server is not allowed to access, we only want to know it is up and running. If we get 403, we know it is still reachable). Anyways to work around the error?

Try adding a catch() block to handle the error:

.catch(function(e) {
  // You don't have to do anything here
});
1 Like