NerdGraph tutorial: View and manage Scorecards
preview
We're still working on this feature, but we'd love for you to try it out!
This feature is currently provided as part of a preview program pursuant to ourpre-release policies.
New Relic lets you to use NerdGraphScorecards GraphQL mutations to manage Scorecards and rules. These mutations let you create, update, delete, and retrieve Scorecards and their associated rules in your existing workflows and integrations.
This tutorial provides examples of how to use NerdGraph to manage Scorecards and rules. You can use these examples to automate Scorecard management tasks, such as creating Scorecards, adding rules, and updating Scorecard details.
Mutations
New Relic provides various NerdGraph mutations to create and manage Scorecards and related rules.
For managing Scorecards and rules, you need to provide your organization ID. You can retrieve your organization ID using theactor query.
Sample request
queryFetchYourOrgId{actor{organization{id}}}You can create your own Scorecard using theentityManagementCreateScorecard mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The name of the Scorecard. |
| String | No | A brief description of the Scorecard. |
| String | Yes | Your organization ID. |
Sample request
mutationCreateScorecard($name:String!,$desc:String,$organizationId:ID!){entityManagementCreateScorecard(scorecardEntity:{description:$desc,name:$name,scope:{type:ORGANIZATION,id:$organizationId}}){entity{idrules{id}}}} //PARAMETERS{"description":"Test test Best Practices","name":"Test Engineering Best Practices","organizationId":"xxxxxxxx-yyyy-0000-aaaa-0123456789qwe"}You can create a new rule for a Scorecard using theentityManagementCreateScorecardRule mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The name of the rule. |
| String | No | A brief description of the rule. |
| String | Yes | A NRQL query to evaluate compliance. |
| Int | Yes | List of account IDs where the rule should execute the query. |
| Int | No | List of account IDs that need to be joined with each account where the query is executed. |
| String (ID) | Yes | Your organization ID, seeFetch your organization ID above to know how to fetch it |
Sample request
mutationCreateRule($name:String!,$description:String,$query:String!,$accounts:[Int!]!,$joinAccounts:[Int!],$organizationId:ID!){entityManagementCreateScorecardRule(scorecardRuleEntity:{name:$name,description:$descriptionenabled:true,nrqlEngine:{accounts:$accounts,joinAccounts:$joinAccounts,query:$query},scope:{id:$organizationId,type:ORGANIZATION}}){entity{id //RULEId}}} //PARAMETERS{"name":"APM Services Have Alerts Defined","description":"Check that APM services have alerts associated with them","accounts":[1,2,3],"query":"SELECT if(latest(alertSeverity) != 'NOT_CONFIGURED', 1, 0) as 'score' FROM Entity WHERE type = 'APM-APPLICATION' AND tags.nr.team IS NOT NULL AND tags.environment IS NOT NULL FACET id as 'entityGuid', tags.nr.team as 'team', tags.environment as 'environment' LIMIT MAX SINCE 1 day ago","organizationId":"xxxxxxxx-yyyy-0000-aaaa-0123456789qwe"}You can associate a rule with a Scorecard using theentityManagementAddCollectionMembers mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The Scorecard's ID to add the rules. |
| String | Yes | List of rule IDs to be added to the Scorecard. |
Sample request
mutationAddRuleToCollection($collectionId:ID!,$rules:[ID!]!){entityManagementAddCollectionMembers(collectionId:$collectionIdids:$rules)} //PARAMETERS{"collectionId":"", //CollectionIDisfromtherule.idfromscorecardentity"rules":[] //Providelistofallruleidswhicharegeneratedduringrulecreation.}You can update the details of an existing Scorecard using theentityManagementUpdateScorecard mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The unique identifier of the Scorecard. |
| String | No | Updated description of the Scorecard. |
| String | Yes | Updated name of the Scorecard. |
Sample request
mutationUpdateScorecard($id:ID!,$description:String,$name:String!){entityManagementUpdateScorecard(id:$idscorecardEntity:{description:$description,name:$name}){entity{nameidrules{id}}}}You can update a rule for the Scorecard using theentityManagementUpdateScorecardRule mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| ID | Yes | The unique identifier of the rule. |
| String | Yes | The name of the rule. |
| String | No | A brief description of the rule. |
| String | Yes | A NRQL query to evaluate compliance. |
| Int | Yes | List of account IDs where the rule should execute the query. |
| Int | No | List of account IDs that need to be joined with each account where the query is executed. |
| Boolean | No | Enable or disable the rule. |
Sample request
mutationUpdateRule($ruleId:ID!$name:String!$description:String$query:String!$queryAccounts:[Int!]!$joinAccounts:[Int!]$enabled:Boolean){entityManagementUpdateScorecardRule(id:$ruleIdscorecardRuleEntity:{description:$descriptionname:$nameenabled:$enablednrqlEngine:{accounts:$queryAccountsjoinAccounts:$joinAccountsquery:$query}}){entity{idnamedescriptionnrqlEngine{accountsjoinAccountsquery}}}}You can delete an existing Scorecard or rule using theentityManagementDelete mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| ID | Yes | The target Scorecard or rule ID to be deleted. |
Sample request
mutationDeleteEntity($id:ID!){entityManagementDelete(id:$id){id}}NerdGraph queries for Scorecards
You can retrieve all rules associated with a specific Scorecard using theFetchScorecardDetails query.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The Scorecard's ID to fetch the rules. |
Sample request
queryFetchScorecardDetails($scorecardId:ID!){actor{entityManagement{entity(id:$scorecardId){...onEntityManagementScorecardEntity{namedescriptionrules{id}}}}}}FetchRulesCollection query
You can retrieve the details of collection using theFetchRulesCollection query, which requires the rules ID obtained from theFetchScorecardDetails response.
Input parameters
Parameter | Data Type | Is it Required? | Description |
|---|---|---|---|
| String | Yes | The ID obtained from the |
Sample request
queryFetchRulesCollection($rulesId:ID!){actor{entityManagement{collectionElements(filter:{collectionId:{eq:$rulesId}}){items{...onEntityManagementScorecardRuleEntity{idnamenrqlEngine{accountsjoinAccountsquery}}}nextCursor}}}}On this page
Was this doc helpful?