• English日本語한국어
  • Log inStart now

Disable and enable alerts conditions using the API

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

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

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 and applied intelligence.

Requirements

Modifying any attribute in a condition using the API requires:

Enable and disable a condition

The process for disabling or enabling a condition is the same general process for changing any attribute in a 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.

  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. Our different products require different API requests.

Example: Disable an APM condition

The following example shows how to disable a 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 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:$API_KEY" -i \
         -G --data-urlencode '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:$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:$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.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.