我正在尝试编写一个python脚本来获取azure中超过30天的资源列表。而且我无法找到任何可以告诉我创建该特定实例的时间的模块或包,例如创建它时的vm的时间戳。
答案 0 :(得分:0)
import os
import datetime
from pprint import pprint
from azure.monitor import MonitorClient
from azure.common.credentials import ServicePrincipalCredentials
subscription_id = '***'
client_id='***'
secret='***'
tenant='***'
today = datetime.datetime.now().date()
filter = " and ".join([ "eventTimestamp le '{}T00:00:00Z'".format(today), "resourceGroupName eq 'jay'" ])
credentials = ServicePrincipalCredentials(client_id=client_id, secret=secret, tenant=tenant)
client = MonitorClient(credentials, subscription_id)
select = ",".join([ "eventName", "operationName" ])
print select
print filter
activity_logs = client.activity_logs.list( filter=filter, select=select )
for log in activity_logs:
# assert isinstance(log, azure.monitor.models.EventData)
print(" ".join([
log.event_name.localized_value,
log.operation_name.localized_value
]))
重新评估A zure Monitor Python SDK之后,我发现了差异。 这是ge,而不是le。
修改代码中的关键字(ge,not le)
eventName,operationName
eventTimestamp ge '2017-10-17T00:00:00Z' and resourceGroupName eq 'jay'
End request Microsoft.Compute/virtualMachines/delete
End request Microsoft.Compute/virtualMachines/delete
End request Microsoft.Compute/virtualMachines/delete
Begin request Microsoft.Compute/virtualMachines/delete
End request Microsoft.Compute/virtualMachines/deallocate/action
End request Microsoft.Compute/virtualMachines/deallocate/action
Begin request Microsoft.Compute/virtualMachines/deallocate/action
End request Microsoft.Compute/virtualMachines/write
End request Microsoft.Compute/disks/write
End request Microsoft.Compute/virtualMachines/write
End request Microsoft.Network/networkSecurityGroups/write
End request Microsoft.Network/networkInterfaces/write
End request Microsoft.Network/publicIPAddresses/write