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 our pre-release policies.
New Relic lets you to use NerdGraph Scorecards 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 the actor
query.
Sample request
query FetchYourOrgId { actor { organization { id } }}
You can create your own Scorecard using the entityManagementCreateScorecard
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
mutation CreateScorecard($name: String!, $desc: String, $organizationId: ID!) { entityManagementCreateScorecard( scorecardEntity: {description: $desc, name: $name, scope: {type: ORGANIZATION, id: $organizationId}} ) { entity { id rules { 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 the entityManagementCreateScorecardRule
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. |
| String (ID) | Yes | Your organization ID, see Fetch your organization ID above to know how to fetch it |
Sample request
mutation CreateRule($name: String!, $description: String, $query: String!, $accounts: [Int!]!, $organizationId: ID!) { entityManagementCreateScorecardRule( scorecardRuleEntity: { name: $name, description: $description enabled: true, nrqlEngine: { accounts: $accounts, query: $query }, scope: {id: $organizationId, type: ORGANIZATION}} ) { entity { id // RULE Id } } } // PARAMETERS { "name": "APM Services Have Alerts Defined", "description": "Check that APM services have alerts associated with them", "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 the entityManagementAddCollectionMembers
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
mutation AddRuleToCollection($collectionId: ID!, $rules: [ID!]!) { entityManagementAddCollectionMembers( collectionId: $collectionId ids: $rules ) } // PARAMETERS { "collectionId": "", // Collection ID is from the rule.id from scorecard entity "rules": [] // Provide list of all rule ids which are generated during rule creation. }
You can update the details of an existing Scorecard using the entityManagementUpdateScorecard
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
mutation UpdateScorecard($id: ID!, $description: String, $name: String!) { entityManagementUpdateScorecard( id: $id scorecardEntity: { description: $description, name: $name } ) { entity { name id rules { id } } }}
You can update a rule for the Scorecard using the entityManagementUpdateScorecardRule
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. |
| Boolean | No | Enable or disable the rule. |
Sample request
mutation UpdateRule( $ruleId: ID! $name: String! $description: String $query: String! $queryAccounts: [Int!]! $enabled: Boolean) { entityManagementUpdateScorecardRule( id: $ruleId scorecardRuleEntity: { description: $description name: $name enabled: $enabled nrqlEngine: { accounts: $queryAccounts, query: $query } } ) { entity { id name description nrqlEngine { accounts query } } }}
You can delete an existing Scorecard or rule using the entityManagementDelete
mutation.
Input parameters
Parameter | Data Type | Is it Required? | Description |
---|---|---|---|
| ID | Yes | The target Scorecard or rule ID to be deleted. |
Sample request
mutation DeleteEntity($id: ID!) { entityManagementDelete(id: $id) { id }}
NerdGraph queries for Scorecards
You can retrieve all rules associated with a specific Scorecard using the FetchScorecardDetails
query.
Input parameters
Parameter | Data Type | Is it Required? | Description |
---|---|---|---|
| String | Yes | The Scorecard's ID to fetch the rules. |
Sample request
query FetchScorecardDetails($scorecardId: ID!) { actor { entityManagement { entity(id: $scorecardId) { ... on EntityManagementScorecardEntity { name description rules { id } } } } }}
FetchRulesCollection
query
You can retrieve the details of collection using the FetchRulesCollection
query, which requires the rules ID obtained from the FetchScorecardDetails
response.
Input parameters
Parameter | Data Type | Is it Required? | Description |
---|---|---|---|
| String | Yes | The ID obtained from the |
Sample request
query FetchRulesCollection($rulesId: ID!) { actor { entityManagement { collectionElements(filter: { collectionId: { eq: $rulesId } }) { items { ... on EntityManagementScorecardRuleEntity { id name nrqlEngine { accounts query } } } nextCursor } } }}