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.
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 | The account where the entity will be stored. |
Sample request
mutation CreateScorecard($description: String, $name: String!, $id: ID!) { entityManagementCreateScorecard( scorecardEntity: {description: $description, name: $name, scope: {id: $id, type: ACCOUNT}} ) { entity { description id rules { id // COLLECTION ID } name } } } // PARAMETERS { "description": "Test test Best Practices", "name": "Test Engineering Best Practices", "id": 1 }
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. |
Sample request
mutation CreateRule($name: String!, $description: String, $query: String!, $accounts: [Int!]!) { entityManagementCreateScorecardRule( scorecardRuleEntity: { name: $name, description: $description enabled: true, nrqlEngine: { accounts: $accounts, query: $query }, scope: {id: 1, type: ACCOUNT}} ) { entity { id // RULE Id } } }
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. |
Sample request
mutation CreateRule($name: String!, $description: String, $query: String!, $accounts: [Int!]!) { entityManagementCreateScorecardRule( scorecardRuleEntity: { name: $name, description: $description enabled: true, nrqlEngine: { accounts: $accounts, query: $query }, scope: {id: 1, type: ACCOUNT}} ) { 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", "accounts": [1] }
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 } } } } }}
You can retrieve the Scorecard details associated with a specific rule by first retrieving the collection ID that contains the rule using the FindRuleOwnerCollections
query, and then retrieving the details of collection parents using the FetchCollectionParent
query.
FindRuleOwnerCollections
query
Input parameters
Parameter | Data Type | Is it Required? | Description |
---|---|---|---|
| String | Yes | The unique identifier of the rule. |
Sample request
query FindRuleOwnerCollections($ruleId: ID!) { actor { entityManagement { relationships( filter: { targetId: { eq: $ruleId }, type: { eq: "HAS_MEMBER" } } ) { items { source { id type } type } } } }}
FetchCollectionParent
query
You can retrieve the details of collection parents using the FetchCollectionParent
query, which requires the collection ID obtained from the FindRuleOwnerCollections
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 } } }}