//add your user API key - ideally set this as a secure credential per: https://docs.newrelic.com/docs/synthetics/synthetic-monitoring/using-monitors/store-secure-credentials-scripted-browsers-api-tests/ var myQueryKey = 'NRAK-<>'; function countDashboards(){ var options = { uri: 'https://api.newrelic.com/v2/dashboards.json', headers: { 'Api-Key': myQueryKey, 'Accept': 'application/json' } }; function callback (err, response, body){ var body = JSON.parse(body); console.log('there are ' + body.dashboards.length + ' dashboards.'); $util.insights.set('dashboardCount', body.dashboards.length); } $http.get(options,callback); } function countPolicies(){ var options = { uri: 'https://api.newrelic.com/v2/alerts_policies.json', headers: { 'Api-Key': myQueryKey, 'Accept': 'application/json' } }; function callback (err, response, body){ var body = JSON.parse(body); console.log('there are ' + body.policies.length + ' policies.'); $util.insights.set('policyCount', body.policies.length); for (let i = 0; i < body.policies.length; i++) { countConditions(body.policies[i].id); } } $http.get(options,callback); } function countConditions(policy_id){ var options = { uri: 'https://api.newrelic.com/v2/alerts_conditions.json?policy_id=' + policy_id, headers: { 'Api-Key': myQueryKey, 'Accept': 'application/json' } }; function callback (err, response, body){ var body = JSON.parse(body); console.log('there are ' + body.conditions.length + ' conditions for policy ' + policy_id); $util.insights.set(policy_id + '-conditionsCount', body.conditions.length); } $http.get(options,callback); } countDashboards(); countPolicies();