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 New Relic One.
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.
Requirements
Modifying any attribute in a condition using the API requires:
- An API key and permissions to manage Alerts
- The condition's
id
(available from API Explorer: Alerts Conditions > GET > List) - If your account hosts data in the EU data center, ensure you are using the proper API endpoints for EU region accounts.
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:
-
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.
-
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.
- APM, Browser, and Mobile
Conditions available:apm_app_metric
,apm_kt_metric
,browser_metric
, andmobile_metric
API Explorer link Get>List - External services
Conditions available:apm_external_service
,mobile_external_service
API Explorer link Get>List - Synthetic monitoring
API Explorer link Get>List - Plugins
API Explorer link Get>List
- APM, Browser, and Mobile
- For the returned JSON, find the JSON object of the condition you want to change.
- Copy and paste the condition's JSON in a text editor of your choice and edit the JSON. To enable the condition, set
"enabled"
totrue
. To disable the condition, set"enabled"
tofalse
. -
Update the condition by submitting your edited JSON via an Update API request. Our different products require different API requests.
- Details on Update API requests
-
Use the Update API request that corresponds to the product in question:
- Conditions for APM, Browser, and Mobile
Conditions available:apm_app_metric
,apm_kt_metric
,browser_metric
, andmobile_metric
API Explorer PUT>Update link - Conditions for external services
Conditions available:apm_external_service
,mobile_external_service
API Explorer PUT>Update - Conditions for Synthetic monitoring
API Explorer PUT>Update - Conditions for Plugins
API Explorer PUT>Update
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.
- Conditions for APM, Browser, and Mobile
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.
-
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 '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 } ] }
-
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)", ... } ] } -
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" } ] } }' - 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:
- API calls for alerts (list of all API calls available)
- Using the API Explorer (using the API Explorer's user interface to get data in and data out of New Relic)
- Parts of the API Explorer (a quick reference for how to use each section of the API Explorer)