Last active
August 6, 2020 14:26
-
-
Save gspncr/5f4dc0ee879bb8833b71ad6f632c0b6f to your computer and use it in GitHub Desktop.
New Relic NerdGraph GUID Lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, json | |
graphQLEndpoint = 'https://api.newrelic.com/graphql' | |
#graphQLEndpoint = 'https://api.eu.newrelic.com/graphql' | |
APIKey = '<your key here>' | |
headers = { | |
"Content-Type": 'application/json', | |
"API-Key": APIKey | |
} | |
query = """ | |
{ | |
actor { | |
entitySearch(query: "name like 'prod'") { | |
results { | |
entities { | |
name | |
guid | |
} | |
} | |
} | |
} | |
} | |
""" | |
request = requests.post( | |
graphQLEndpoint, | |
json={'query': query}, | |
headers=headers | |
) | |
def parseGUIDs(request): | |
jsonpayload = json.loads(request.text) | |
entries = len(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"]) | |
for x in range(entries): | |
print(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["name"], | |
jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["guid"]) | |
parseGUIDs(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment