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

How to programatically retrieve monitor id by giving monitor name

synthetics-api

#1

I need to programatically retrieve monitor id by giving a monitor name.
Is there an API or command for it?


#2

Hi, @senthila: Try something like this:

import requests

monitorToFind = 'Monitor Name'

headers = { 'X-Api-Key': 'YOUR_ADMIN_KEY' }
url = 'https://synthetics.newrelic.com/synthetics/api/v3/monitors'
response = requests.get(url, headers = headers)

data = response.json()

for monitor in data['monitors']:
    if monitor['name'] == monitorToFind:
        print monitor['id']

#3

Thanks @philweber. The get response from Newrelic paginates to 20 results. I can do below, but limit is set to 100 max by Newrelic. I will have thousands of monitors. Any way to get that?
url = https://synthetics.newrelic.com/synthetics/api/v3/monitors?offset=0&limit=100


#4

You may find this thread helpful: