【发布时间】:2022-11-02 18:56:45
【问题描述】:
我正在尝试查询特定天蓝色资源的活动日志。但是,我不知道该怎么做。我只在互联网上找到了只能过滤到资源组级别的基本代码。
from azure.mgmt.monitor import MonitorManagementClient
import datetime
# Get a client for Monitor
credentials = connectSP() # Custom function to get credentials
client = MonitorManagementClient(
credentials,
sub_id
)
# Generate query here
today = datetime.datetime.now().date()
filter = "eventTimestamp ge {}".format(today)
select = ",".join([
"eventTimestamp",
"eventName",
"operationName",
"resourceGroupName",
])
# Grab activity logs
activity_logs = client.activity_logs.list(
filter=filter,
select=select
)
# Print the logs
for log in activity_logs:
print(" ".join([
str(log.event_timestamp),
str(log.resource_group_name),
log.event_name.localized_value,
log.operation_name.localized_value
]))
我试图通过 resource_id 属性过滤它,但遇到了这个错误:
Code: BadRequest
Message: The filter property: resource_id is not supported.
是否可以将范围缩小到一个资源?还有关于如何修改过滤器查询的任何文档吗?我刚刚在 Microsoft 文档中找到了基本的。 https://learn.microsoft.com/en-us/python/api/azure-mgmt-monitor/azure.mgmt.monitor.v2015_04_01.operations.activitylogsoperations?view=azure-python
【问题讨论】:
-
尝试按 resourceUri 过滤。
filter = "eventTimestamp ge {} and resourceUri eq {}".format(today, resourceUri)
标签: python azure activitylog