How to create a synthetic script and pass nrql-query inside the script to get the SLA for particular monitor

Hi All,

Please help me to writing this script. I know how to write normal synthetic script. But how to pass the nrql-query inside synthetic script don’t know.

I have the query to get the SLA response for particular Monitor ID
(SELECT average(duration) as ‘Duration’,
percentage(count(*), WHERE result=‘SUCCESS’) AS ‘Uptime’,
apdex((duration/1000), t:7),
WHERE (duration/1000) <= 7 AND result = ‘SUCCESS’)
AS ‘% Satisfied’,
WHERE (duration/1000) > 7 AND (duration/1000) < 28 AND result = ‘SUCCESS’)
AS ‘% Tolerating’,
WHERE (duration/1000) >= 28) + percentage(count(timestamp),
WHERE result != ‘SUCCESS’))
AS ‘% Frustrated’
FROM SyntheticCheck
FACET monitorName since 7 days ago limit 1000 WHERE monitorId = ‘d2cdf4c0-71d6-4aa6-ba37-e920e0685b52’ ).

But what I need is I want to pass this script in synthetic browser and get the output and send through mail. Could anyone please tell me how to do it…


Hey @subhakankshi.swain - I think we got this solved in Slack, right?

But for the interest of the rest of the community - here’s a script that we came up with.

Note that a scripted browser needs to make a browser request for it to succeed. So we did need to specify a $browser.get();

var request = require('request');

var accountId = $secure.ACC_ID;
var queryKey = $secure.QUERY_KEY;

var options = {
  'method': 'GET',
  'url': ''+accountId+'/query?nrql=SELECT%20average(duration)%20FROM%20PageView',
  'headers': {
    'Accept': 'application/json',
    'X-Query-Key': queryKey

    request(options, function (error, response) {
  if (error) throw new Error(error);

Obviously this would need to be updated to include your API key / Account ID / NRQL query


You are correct Ryan. First I posted here then got to know about the slack channel.

Thank you Ryan… It is working…

1 Like

Thanks for posting this back. Slack will be lost forever.

Suggest showing the example using secure credentials.

1 Like

Great point - updated the script to use Secure Creds :smiley:

1 Like