In , an entity is defined as any target for monitoring, such as an application, a browser, or a host. The alerts UI shows available entities that you can select. You can also use the REST API and API Explorer to add or remove entities for a condition.
Before using the REST API
The REST API is no longer the preferred way to programmatically manage your alerts. For more context, read the Intro to APIs for alerts.
Requirements
Modifying the list of entities in a condition requires you to know:
- Your API key
- The {entity_ID} of the entity you want to monitor
- The {condition_ID} of the condition you want to modify
General procedure
To update the entity list for a condition:
- Locate the appropriate entity ID; for example, Application ID and browser ID.
- Identify the policy ID by name or type.
- Get the list of conditions associated with the policy and choose the one you want to modify for the appropriate category:
- Modify the condition using the add or remove API requests.
Important
Follow the requirements for the minimum and maximum number of entities you can add to conditions.
Example: Add or remove an entity
The following example shows how to add a Ruby application named TimberTime
in a condition and how to remove an entity from that same condition.
Only the first step in this example is unique to choosing the Ruby app as the entity. The remaining steps will be the same for whichever entity you choose.
Get the
entity_id
; for example,application_id
:bash$curl -X GET 'https://api.newrelic.com/v2/applications.json' \>-H $API_KEY -iOR
If you know the application name, use this command and specify the
app_name
:bash$curl -X GET 'https://api.newrelic.com/v2/applications.json' \>-H $API_KEY -i \>-d 'filter[name]=TimberTime'Review the output to find the
application_id
, and use it as theentity_id
:{"applications": [{"id": 12345, // application_id == entity_id"name": "TimberTime","language": "ruby","health_status": "gray",...},Get the
policy_id
you want to update; for example, theTimberTime
app'sLogjam Alert
policy. To get thepolicy_id
, use this command:
$curl -X GET 'https://api.newrelic.com/v2/alerts_policies.json' \> -H $API_KEY -i \> -G -d 'filter[name]= Logjam Alert' # policy_name
Review the policy output; for example:
{"policies": [{"id": 85, // policy_id"incident_preference": "PER_POLICY","name": "Logjam Alert","created_at": 1461176510393,"updated_at": 1461176510393},List all of this policy's conditions and locate the
condition_id
:
$curl -X GET 'https://api.newrelic.com/v2/alerts_conditions.json' \> -H $API_KEY -i \> -G -d 'policy_id=85'
Review the policy conditions; for example:
{ "conditions": [ { "id": 234567, // condition_id "type": "apm_app_metric", "name": "Throughput (web) (High)", "enabled": true, "entities": [ "8288171" // Entity currently included in the policy ], "metric": "response_time_web", "terms": [ { "duration": "5", "operator": "above", "priority": "critical", "threshold": "500", "time_function": "all" } ] } ]}
Use API requests to add entities to or remove entities from the policy's condition:
To add
entity_id
12345 tocondition_id
234567, withentity_type
set asApplication
:bash$curl -X PUT 'https://api.newrelic.com/v2/alerts_entity_conditions/12345.json' \>-H $API_KEY -i \>-H 'Content-Type: application/json' \>-G -d 'entity_type=Application&condition_id=234567'To remove
entity_id
8288171 fromcondition_id
234567, withentity_type
set asApplication
:
$curl -X DELETE 'https://api.newrelic.com/v2/alerts_entity_conditions/8288171.json' \> -H $API_KEY -i \> -G -d 'entity_type=Application&condition_id=234567'