How to retrieve Azure Log Activity Data using python for any resource alongwith 'Tags'?

%3CLINGO-SUB%20id%3D%22lingo-sub-1389485%22%20slang%3D%22en-US%22%3EHow%20to%20retrieve%20Azure%20Log%20Activity%20Data%20using%20python%20for%20any%20resource%20alongwith%20'Tags'%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1389485%22%20slang%3D%22en-US%22%3E%3CP%3EMy%20colleague%20used%20the%20below%20powershell%20query%20to%20retrieve%20log%20data%20for%20past%204%20days%20excluding%20today%20which%20matches%20operations%20of%20the%20resources%20and%20collects%20features%20such%20as%20EventTimeStamp%2C%20Caller%2C%20SubscriptionId%20etc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-AzureRmLog%20-StartTime%20(Get-Date).AddDays(-4)%20-EndTime%20(Get-Date).AddDays(-1)%20%7C%20Where-Object%20%7B%24_.OperationName.LocalizedValue%20-match%20%22Start%7CStop%7CRestart%7CCreate%7CUpdate%7CDelete%22%7D%20%7C%0ASelect-Object%20EventTimeStamp%2C%20Caller%2C%20SubscriptionId%2C%20%40%7Bname%3D%22Operation%22%3B%20Expression%20%3D%20%7B%24_.operationname.LocalizedValue%7D%7D%2C%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3EI%20am%20a%20newbie%20to%20azure%20and%20want%20to%20generate%20a%20report%20where%20I%20can%20also%20fetch%20the%20'Tags'%20name%20%26amp%3B%20value%20against%20a%20resource%20for%20past%2090%20days%20in%20this%20report.%20What%20will%20be%20the%20powershell%20query%20for%20this%3F%20Can%20I%20also%20use%20python%20to%20query%20this%20data%3F%20I%20tried%20searching%20the%20documentation%20and%20was%20unable%20to%20dig%20into%20it%2C%20so%20if%20anybody%20could%20redirect%20me%20to%20the%20right%20place%20it%20will%20be%20helpful.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1389485%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECustom%20Logs%20and%20Custom%20Fields%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMachine%20Learning%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowershell%20and%20Rest%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epython%20sdk%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuery%20Language%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1389989%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20retrieve%20Azure%20Log%20Activity%20Data%20using%20python%20for%20any%20resource%20alongwith%20'Tags'%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1389989%22%20slang%3D%22en-US%22%3EI%20cannot%20start%20a%20conversation%20there%20due%20to%20insufficient%20privileges.%20And%20this%20question%20also%20asks%20azure%20support%20with%20python%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1389838%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20retrieve%20Azure%20Log%20Activity%20Data%20using%20python%20for%20any%20resource%20alongwith%20'Tags'%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1389838%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20and%20welcome%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F667966%22%20target%3D%22_blank%22%3E%40shmoolya%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20is%20a%20dedicated%20PowerShell%20group%2C%20that%20maybe%20a%20better%20place%20to%20ask%20and%20get%20help%20from%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fpowershell%2Fct-p%2FWindowsPowerShell%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fpowershell%2Fct-p%2FWindowsPowerShell%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

My colleague used the below powershell query to retrieve log data for past 4 days excluding today which matches operations of the resources and collects features such as EventTimeStamp, Caller, SubscriptionId etc.

 

Get-AzureRmLog -StartTime (Get-Date).AddDays(-4) -EndTime (Get-Date).AddDays(-1) | Where-Object {$_.OperationName.LocalizedValue -match "Start|Stop|Restart|Create|Update|Delete"} |
Select-Object EventTimeStamp, Caller, SubscriptionId, @{name="Operation"; Expression = {$_.operationname.LocalizedValue}},

 

I am a newbie to azure and want to generate a report where I can also fetch the 'Tags' name & value against a resource for past 90 days in this report. What will be the powershell query for this? Can I also use python to query this data? I tried searching the documentation and was unable to dig into it, so if anybody could redirect me to the right place it will be helpful.
 
 
 
2 Replies
Highlighted

Hello and welcome @shmoolya 

 

There is a dedicated PowerShell group, that maybe a better place to ask and get help from  https://techcommunity.microsoft.com/t5/powershell/ct-p/WindowsPowerShell

 

Thanks 

Highlighted
I cannot start a conversation there due to insufficient privileges. And this question also asks azure support with python