Manage entities in alerts conditions

In alerts, an entity is defined as any target for monitoring, such as an application, a browser, or a plugin. 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.

Requirements

Modifying the list of entities in a condition requires you to know:

General procedure

To update the entity list for a condition:

  1. Locate the appropriate entity ID; for example, Application ID and Browser ID.
  2. Identify the policy ID by name or type.
  3. Get the list of conditions associated with the policy and choose the one you want to modify for the appropriate category:
  4. Modify the condition using the add or remove API requests.

Follow the requirements for the minimum and maximum number of entities you can add to conditions.

Example: Add/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.

  1. Get the entity_id; for example, {application_id}:

    curl -X GET 'https://api.newrelic.com/v2/applications.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i
    

    OR

    If you know the application name, use this command and specify the app_name:

    curl -X GET 'https://api.newrelic.com/v2/applications.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i \
         -d 'filter[name]=TimberTime' 
    
  2. Review the output to find the {application_id}, and use it as the {entity_id}:

    {
      "applications": [
        {
          "id": 12345,    <---<<<  {application_id} == {entity_id}
          "name": "TimberTime",
          "language": "ruby",
          "health_status": "gray",
          ...
        },
  3. Get the policy_id you want to update; for example, the TimberTime app's Logjam Alert policy. To get the policy_id, use this command:

    curl -X GET 'https://api.newrelic.com/v2/alerts_policies.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i \
         -G -d 'filter[name]= Logjam Alert'    <---<<<  {policy_name}
  4. Review the policy output; for example:

    {
      "policies": [
        {
          "id": 85,      <---<<<  {policy_id}
          "incident_preference": "PER_POLICY",
          "name": "Logjam Alert",
          "created_at": 1461176510393,
          "updated_at": 1461176510393
        },
    
  5. List all of this policy's conditions and locate the {condition_id}:

    curl -X GET 'https://api.newrelic.com/v2/alerts_conditions.json' \
         -H 'X-Api-Key:{YOUR_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"
            }
          ]
        }
      ]
    }
  6. Use API requests to add entities to or remove entities from the policy's condition:

    To add {entity_id} 12345 to {condition_id} 234567, with {entity_type} set as application:

    
    curl -X PUT 'https://api.newrelic.com/v2/alerts_entity_conditions/12345.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i \
         -H 'Content-Type: application/json' \
         -G -d 'entity_type=Application&condition_id=234567'

    To remove {entity_id} 8288171 from {condition_id} 234567, with {entity_type} set as application:

    curl -X DELETE 'https://api.newrelic.com/v2/alerts_entity_conditions/8288171.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i \
         -G -d 'entity_type=Application&condition_id=234567'

For more help

If you need more help, check out these support and learning resources: