Created
August 2, 2021 14:27
-
-
Save gspncr/2f638deadcfa4e80ab8a6a6364e6f413 to your computer and use it in GitHub Desktop.
count NR dashboards, policies, conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment