11/7/2022 0 Comments Powershell json query![]() ![]() The result itself is an array of tables, and not so surprisingly each table (in my case just one table) has rows, and a row an array of items. If you’ve specififed the headers you will get a JSON result in return, and PowerShell has the fabulous ConertFrom-Json cmdlet that you can use to parse out the result. $json = ConvertFrom-Json $response.Content $response = Invoke-WebRequest -uri “ $appId/$operation$sqlQuery" -Headers $headers $headers = “X-Api-Key” = $key “Content-Type” = “application/json” } $sqlQuery=::EscapeUriString("?query=dependencies|where timestamp >= ago(15h) and type ='SQL’ and target notcontains ‘Hangfire’ | order by timestamp desc | take 100 | project timestamp, target,sql = substring(data, 0, 25) “) Afterwards you pass in a parameter, and it needs the actual query so that is what you pass in as a query string. The API URI lets you specify the type of operation and for queries it’s the ‘query’ operation. ![]() In this post I’m focusing on doing queries, which is what I use the most. You can do different types of queries and the documentation is the best place to go for the information. Copy and save the key somewhere safe- you won’t be able to retrieve it afterwards. Go to the Application Insight resource, scroll down to API access, and grab the id, and generate a key. The API key can be generated in the Azure portal. The application (Application Insights resource) id, and an API key. The query below gets all SQL queries executed the last 15 minutes (excluding Hangfire queries), it takes the last 100 queries and then grabs the timestamp, target and a substring of the SQL data. ![]() Working with the Application Insights API is very easy and straightforward. It has been frustrating that I can’t really get my colleagues to use them more, so I decided to spend an hour and put together a simple app that pulls out some data for us while we are testing a major refactoring that we recently published to QA. The Log Analytics interface can be a bit intimidating, and same goes for the charts for Application Insight resources. It shouldn’t come as a surprise that I have another blog post on Application Insights- I can’t help it, I’m smitten. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |