-2

It would be a great help if somebody helps me to understand how the following command can be executed using python:

curl -X POST https://insights-collector.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/events -H "Content-Type: application/json" -H "X-Insert-Key: YOUR_KEY_HERE" -d '{"eventType":"Custom Event Name", "attribute1": "value"}'

SQL query results need to be converted to JSON format and need to be pushed to new relic using the above command.

anaghapramesh
  • 77
  • 1
  • 2
  • 11
  • Seem its already answered, Please refer https://stackoverflow.com/questions/26000336/execute-curl-command-within-a-python-script – Dhamodharan Apr 29 '19 at 11:22
  • What have you tried doing? – Yaniv Oliver Apr 29 '19 at 11:23
  • @yanivoliver : Hello.. I have fetched a mysql query result and converted into json format. I have to push the json data to new relic using the above command mentioned. Since, I am new to python, I don't have a clear idea of how to execute the above command using python. Thank you! – anaghapramesh Apr 30 '19 at 05:57
  • @Dhamodharan : Thank you so much. I think I missed that. – anaghapramesh Apr 30 '19 at 05:59

1 Answers1

0

try doing this

import requests

headers = {
    'Content-Type': 'application/json',
    'X-Insert-Key': 'YOUR_KEY_HERE',
}

data = '{"eventType":"Custom Event Name", "attribute1": "value"}'

response = requests.post('https://insights-collector.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/events', headers=headers, data=data)
noob_coder
  • 749
  • 4
  • 15
  • 35