Reputation: 11
I have been trying to get the last active time of a disk/VM using Kusto Query Language on Azure portal. Is it possible to track it? I want this information to alert the user if that resource is not used for more than 14 days.
Also, could anyone help me finding out if there is any other way to query the list of unused resources (say for N days) within a subscription?
Thanks!
Upvotes: 1
Views: 764
Reputation: 5570
As far as I know, you need to find the max authenticationStepDateTime
to be more than 14 days ago.
To get the list of unused resources (say for N=15 days) within a subscription using Kusto Query Language on Azure portal, try using the sample query like below:
let SigninUsersWithin15Days = SigninLogs
| extend d = parse_json(AuthenticationDetails)
| extend LoginTimestamp = todatetime(d[0].authenticationStepDateTime)
| where AppDisplayName == "Azure Portal" and OperationName == "Sign-in activity" and isnotempty(AlternateSignInName)
| summarize max(LoginTimestamp) by AlternateSignInName, Identity
| where max_LoginTimestamp < ago(15d)
| distinct AlternateSignInName;
where
clause and pipe (|) delimiter are key to writing KQL queries.extend
to provide an alias for timestamps that compute the session duration based on queried date and time.For your reference, please find these links:Ref1, Ref2
Upvotes: 0