Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Not sure how to do this with the Alerts Rest API

restapi
alerts

#1

Hi everybody, here is my situation:
Starting with the name of an application, I am trying to write a script that gets all of the Alert Policies that have an alert condition using that application as an entity using the REST Api. I am able to get the alert conditions that use the application as an entity through the Alerts Entity Conditions endpoint: https://rpm.newrelic.com/api/explore/alerts_entity_conditions/list
However, I do not know how to find the alert policies that these alert conditions are a part of easily. The only way I can think of is to get all of the alert conditions of every alert policy and see if any of them are the same as the ones the application is used as an entity in. This is a pretty taxing way to do this, I would rather be able to get the policy immediately from the alert condition instead of looking through every single alert condition. Does anybody have any suggestions on how to go about this?


#2

Hi @brendan.armani,

At this time, the only way to programmatically return the policy associated with an alerts_entity_conditions output would indeed require chaining together multiple API calls, like you’ve described. I can totally understand how that might not be ideal, and I’ve passed that feedback onto our Alerts engineers for consideration on a future platform update.

In the meantime, you might benefit from setting up an Alerts -> Insights webhook to store your incident notifications as event data. Depending on the frequency and the nature in which your alert incidents are generated, this may help you correlate condition IDs and policies; for instance, you could hit our Query API to find if there were recent incidents associated with a particular condition ID, and then grab an associated policy URL.

It may help to read our documentation on default webhook values if you’re interested. This might not be a perfect solution for your use case, but I wanted to share in case it could be of some help.