Disable and enable Alerts conditions using the API

In a New Relic Alerts policy, a condition identifies what triggers an alert. You can use the New Relic REST API to disable and enable Alerts conditions. You can also disable and enable Alerts conditions in the New Relic UI.

Alerts policies cannot be enabled or disabled, whether via the API or the UI. Policies can only be created, deleted, or have their conditions changed.

Requirements

Modifying any attribute in an Alerts condition using the API requires:

Enable and disable an Alerts condition

The process for disabling or enabling an Alerts condition is the same general process for changing any attribute in an Alerts condition. A more detailed example comes after this general procedure:

  1. Find the ID for the policy that contains the condition you want to change.

    If the policy's ID is unknown, use the policy's name or type to make an API call and find the policy's ID. For more on this process, see List a single policy.

  2. With the policy ID, make an API call that returns the conditions associated with that policy. There are four different condition categories. If you don't know the category, this may require making up to four API calls in order to find the condition.

    Details on searching for condition ID

    If you don't know the category of the condition you want to change, you must search for it by making API calls using the four condition categories. Here are the different API call formats for the various condition categories.

  3. For the returned JSON, find the JSON object of the condition you want to change.
  4. Copy and paste the condition's JSON in a text editor of your choice and edit the JSON. To enable the condition, set "enabled" to true. To disable the condition, set "enabled" to false.
  5. Update the condition by submitting your edited JSON via an Update API request. Different New Relic products require different API requests.

    Details on Update API requests

    Use the Update API request that corresponds to the product in question:

    An Update API request can only change one condition at a time, it cannot update a vector of objects. For example, to change three conditions, you will have to make three separate requests.

Example: Disable an APM condition

The following example shows how to disable a New Relic Alerts condition for an apm_app_metric condition. With the exception of the types of API calls required, the process is similar to the process for changing other condition types.

  1. Obtain the policy_id of the Alerts policy you want to update. For an imaginary policy named Logjam Alert, the command would be:

    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}
    

    The output for this request might look like:

    {
      "policies": [
        {
          "id": 85,      <---<<<  {policy_id}
          "incident_preference": "PER_POLICY",
          "name": "Logjam Alert",
          "created_at": 1461176510393,
          "updated_at": 1461176510393
        }
      ]
    }
    
  2. 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'
    

    The output for this request might look like:

    {
      "conditions": [
        {
          "id": 12345,       <---<<< {condition_id}
          "type": "apm_app_metric",
          "name": "Apdex (Low)",
          "enabled": true,    <---<<< Note the condition is enabled
          "entities": [
            "8288171"
          ],
          "metric": "apdex",
          "terms": [
            {
              "duration": "5",
              "operator": "below",
              "priority": "critical",
              "threshold": "1",
              "time_function": "any"
            }
          ]
        },
        {
          "id": 2468,       <---<<< another condition_id
          "type": "apm_app_metric",
          "name": "Throughput (Low)",
          ...
        }
      ]
    }
    
  3. Copy the JSON for only the condition in question and paste it in a text editor. Change "enabled": true to "enabled": false. The edited JSON would look like:

    curl -X PUT 'https://api.newrelic.com/v2/alerts_conditions/12345.json' \
         -H 'X-Api-Key:{YOUR_API_KEY}' -i \
         -H 'Content-Type: application/json' \
         -d \
    '{
      "condition": {
        "type": "apm_app_metric",
        "name": "Apdex (Low)",
        "enabled": false,       <---<<<  Changed to false
        "entities": [
          "8288171"
        ],
        "metric": "apdex",
        "terms": [
          {
            "duration": "5",
            "operator": "below",
            "priority": "critical",
            "threshold": "1",
            "time_function": "any"
          }
        ]
      }
    }' 
    
    
  4. Update the condition by submitting the edited condition JSON via an Update API request. For this specific condition, you would follow the steps in Update conditions for APM policies. Other product conditions would have other API requests, as detailed in Update API requests.

For more help

Additional documentation resources include:

Recommendations for learning more: