Created
February 25, 2021 11:25
-
-
Save gspncr/aa0b439091caafb9272c54d50d0ef17d to your computer and use it in GitHub Desktop.
fetch-nr-apps.py
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
ID | Name | |
---|---|---|
876990294 | Application name is required. | |
516776661 | Blog Prod | |
968623920 | MyDotNetApp | |
887470292 | Node Workshop | |
305164720 | staging-blog | |
781875136 | tic tac toe | |
968641669 | windowshit |
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, csv | |
graphQLEndpoint = 'https://api.newrelic.com/graphql' | |
#graphQLEndpoint = 'https://api.eu.newrelic.com/graphql' | |
#hidestream is hiding APIKey = '<API Key>' | |
APIKey = '<API Key>' | |
headers = { | |
"Content-Type": 'application/json', | |
"API-Key": APIKey | |
} | |
query = """ | |
{ | |
actor { | |
entitySearch(queryBuilder: {domain: APM}) { | |
results { | |
entities { | |
... on ApmApplicationEntityOutline { | |
name | |
applicationId | |
} | |
} | |
} | |
} | |
} | |
} | |
""" | |
request = requests.post( | |
graphQLEndpoint, | |
json={'query': query}, | |
headers=headers | |
) | |
def parseIDs(request): | |
jsonpayload = json.loads(request.text) | |
entries = len(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"]) | |
print(entries) | |
for x in range(entries): | |
print(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["name"], | |
jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["applicationId"]) | |
parseIDs(request) | |
def IDstoCSV(request): | |
with open('appList.csv', 'w', newline='') as csvfile: | |
fieldnames = ['ID', 'Name'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
jsonpayload = json.loads(request.text) | |
entries = len(jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"]) | |
writer.writeheader() | |
for x in range(entries): | |
writer.writerow({'ID': jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["applicationId"], 'Name': jsonpayload["data"]["actor"]["entitySearch"]["results"]["entities"][x]["name"]}) | |
IDstoCSV(request) |
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
7 | |
Application name is required. 876990294 | |
Blog Prod 516776661 | |
MyDotNetApp 968623920 | |
Node Workshop 887470292 | |
staging-blog 305164720 | |
tic tac toe 781875136 | |
windowshit 968641669 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment