Need help with --query parameter in Azure CLI

%3CLINGO-SUB%20id%3D%22lingo-sub-2174419%22%20slang%3D%22en-US%22%3ENeed%20help%20with%20--query%20parameter%20in%20Azure%20CLI%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2174419%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe've%20used%20the%20Az%20CLI%20sometimes%20to%20view%20log%20streams%20from%20App%20Service%20web%20apps.%20This%20works%20ok-ish%2C%20like%20so%3A%3C%2FP%3E%3CPRE%3Eaz%20webapp%20log%20tail%20--name%20some-demo-app%20--resource-group%20some-demo-rg%3C%2FPRE%3E%3CP%3EBut%20we're%20pretty%20stuck%20with%20how%20to%20filter%20the%20results.%20There's%20a%20ton%20of%20stuff%20streamed%20that%20we're%20not%20interested%2C%20so%20we'd%20like%20to%20just%20filter%20-%20as%20in%20grep%20or%20whatever%20-%20the%20results.%20The%20documentation%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fcli%2Fazure%2Fwebapp%2Flog%3Fview%3Dazure-cli-latest%23az_webapp_log_tail%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eaz%20webapp%20log%20%7C%20Microsoft%20Docs%3C%2FA%3E)%20is...%20lacking%2C%20to%20be%20polite%3A%20it%20mentions%20the%20%22--query%22%20parameter%20and%20has%20a%20link%20to%20JMespath%20website%2C%20but%20darned%20if%20I%20can%20figure%20out%20how%20to%20use%20it%20in%20this%20case.%3C%2FP%3E%3CP%3EI%20understand%20(well%2C%20sorta)%20how%20the%20JMespath%20stuff%20works%20on%20JSON%20objects%2C%20but%20the%20%22webapp%20log%20tail%22%20returns%20just%20simple%20strings.%20How%20can%20I%20filter%20on%20strings%20on%20the%20output%20strings%3F%20I%20feel%20like%20I'm%20trying%20to%20do%20something%20too%20simple%20here...%20%3B)%3C%2Fimg%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20welcome!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2174419%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20CLI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

Hi all!

 

We've used the Az CLI sometimes to view log streams from App Service web apps. This works ok-ish, like so:

az webapp log tail --name some-demo-app --resource-group some-demo-rg

But we're pretty stuck with how to filter the results. There's a ton of stuff streamed that we're not interested, so we'd like to just filter - as in grep or whatever - the results. The documentation (az webapp log | Microsoft Docs) is... lacking, to be polite: it mentions the "--query" parameter and has a link to JMespath website, but darned if I can figure out how to use it in this case.

I understand (well, sorta) how the JMespath stuff works on JSON objects, but the "webapp log tail" returns just simple strings. How can I filter on strings on the output strings? I feel like I'm trying to do something too simple here... ;)  

Any ideas welcome!

2 Replies
Have had similar issues :)
You can either use the query feature, there are some examples here albeit a bit tricky to get the syntax right:
https://docs.microsoft.com/en-us/cli/azure/query-azure-cli
Be mindful of the comment about potentially having to escape and wrapping also.
Otherwise an alternative is to pipe the output to another process and filter from there.
az webapp log tail --name some-demo-app --resource-group some-demo-rg | grep -ie 'value1' -ie 'value2'
grep or similar depending on where it is being run from.
Thanks; I've used grep for this and it works fine, I was just wondering how to actually make use of JMESHPath - it has the "contains" function which should do the trick, but as the correct syntax is "contains(string, substring)" - I have no idea what to put in the "string" part. i.e. how to refer to the output of the tail, when it doesn't seem to be JSON...