New Relic: Audit your services with Python and the NerdGraph API


First, you need to import the Python json queries and modules into the code. These modules allow you to make an API call.

Next, import the plug-in license into your code. The license module is a separate file in which the API USER key is stored.

From there, you can use a simple GraphQL query to validate that your query was successful. This example asks for parameter information. Throughout this tutorial guide, you will create queries similar to this one to automate tasks.

This is where you can customize your URL and authorization headers. This example uses strings to include your USER API key.

Next, you will convert the JSON response from NerdGraph into a dictionary using the json module. Optionally, you can use Pandas with dataframes.

Sometimes it’s beneficial to see your query response as a JSON-formatted stream. You can optionally decide if you want to include it in your output.

Finally, if there is an error, you want to raise an exception with an HTTP response code.

You will see the following results if your query is successful:


New Relic Inc. published this content on March 15, 2022 and is solely responsible for the information contained therein. Distributed by publicunedited and unmodified, on March 15, 2022 5:21:01 PM UTC.


About Author

Comments are closed.