1

I have a template deployed on azure which creates a resource group with various resources. These resources include an Application Insight. I want to access the latest data generated in 'event1' and 'event2' in my Application Insight using python 2.7.5. How to do that?

I have tried using azurerm but couldn't get the data.

New_to_work
  • 253
  • 2
  • 5
  • 16
  • do you have any progress on this? – Ivan Glasenberg Jul 31 '19 at 05:42
  • Yes I have gone through the links that you provided. I am looking for the query formats which I think will be done soon. – New_to_work Jul 31 '19 at 05:49
  • It would be more easier if you nav to azure portal -> your application insights -> Logs (Analytics): write your query there, if you get the result you want, just use that query. – Ivan Glasenberg Jul 31 '19 at 05:53
  • Thank you so much. It worked. I got the required data through postman. But when I copy the python code from postman and run it on my linux machine, I get the following output: {"error":{"message":"The request had some invalid properties","code":"BadArgumentError","innererror":{"code":"SyntaxError","message":"A recognition error occurred in the query.","innererror":{"code":"SYN0002","message":"Query could not be parsed at '%' on line [1,6]","line":1,"pos":6,"token":"%"}}}} – New_to_work Jul 31 '19 at 07:06
  • can you please try encode your url? For python 2.7, you can refer to this [SO issue](https://stackoverflow.com/questions/37541436/url-encode-using-python-2-7?answertab=active#tab-top). – Ivan Glasenberg Jul 31 '19 at 07:20
  • When I run the same code without adding any query, it works fine. But adding query also adds '%' in the request which gives error. – New_to_work Jul 31 '19 at 07:37
  • I used json.dumps for the query. It doesnt give any error now but it is returning empty list. output: {"tables":[]} table should contain values according to my queries. The same code runs fine on postman. – New_to_work Jul 31 '19 at 09:42
  • I only have python 3.7 environment, if you don't mind, I can write a sample with python 3.7 tomorrow. Is it ok for you? – Ivan Glasenberg Jul 31 '19 at 09:43
  • Thank you so much for the help. But it worked out now. I passed the query in the url itself instead of passing it as a parameter in the GET request. Thank you again. :) – New_to_work Aug 01 '19 at 04:12

1 Answers1

3

If you want to get the data in application insights, you should use App Insights rest api.

First, you should follow this doc on how to get API key and Application ID.

Second, you can nav to this link, write your query to get the data you want. It will generate a get query url which you should use it for the query.

Thrid, you should use python to build a get request. And in this doc, there is an exmaple written in c#, you can try to modify it with python.

If everything is ok, you should get the data.

And if you cannot figure it out, I can provide you a python example later when I'm availabe.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60