azure - Azure Powershell cmd-let - Get-AzureRmLog 不显示“Microsoft.Authorization/”日志
问题描述
我准备了 Azure PowerShell 脚本,用于从 Azure 活动日志中捕获 RBAC 更改信息。当我在我的测试订阅上测试这个脚本时,脚本工作正常。问题是当我使用connect-azurermaccount -subscription
命令并切换到产品订阅时。在 Azure 活动日志刀片中,我看到有一些与 RBAC 更改相关的日志,例如“创建角色分配”之类的日志名称。我正在使用如下命令进行测试:
Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) |
Where-Object {$_.Authorization.Action -like
"Microsoft.Authorization/roleAssignments/*"}
和
Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Authorization/*"}
我没有在控制台中看到任何输出。当我登录到 Azure 门户并打开活动日志时,我能够看到与 RBAC 更改、日志名称相关的日志——>“删除角色分配”、“创建角色分配”。我正在使用字符串“Microsoft.Compute”测试提到的命令:
Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) |
Where-Object {$_.Authorization.Action -like
""*Microsoft.Compute/*""}
和
Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Compute/*"}`
我可以在输出中看到日志信息。我不确定什么是错的,我应该纠正什么。为什么我不能在我的产品订阅中使用这个过滤器——>“ Microsoft.Authorization/ ”,我想在我的测试订阅脚本中强调它工作得很好。
解决方案
如果要获取 RBAC 更改相关的日志,可以使用以下脚本获取。
Connect-AzureRmAccount
Get-AzureRmLog -ResourceProvider Microsoft.Authorization -StartTime (Get-Date).AddMonths(-1)
更新
如果要使用 Azure rest api 获取与 RBAC 更改相关的日志,则需要使用如下所示的rest api:
Method : GET
URL:https://management.azure.com/subscriptions/<subscription id>/providers/microsoft.insights/eventtypes/management/values
Params:
api-version = 2017-03-01-preview
$filter = eventTimestamp ge 'your strat time' and resourceTypes eq 'microsoft.authorization/roleassignments'
Header:
Authorization : Bearer access_token
根据我的测试,如果你的日志数量太大,结果会被分页。如果要获取其他页面的结果,我们需要向 nextlink 发送请求,nextlink 是结果中的一个参数。
推荐阅读
- performance - 如何优化 Python 代码以使用多处理生成和过滤非常大的活动 url 列表?[代码很慢]
- python - Python WebDriver - ChromeDriver.exe 不工作,要求我提供一些权限(!?)
- python - PySpark:如何将 Python UDF 应用于 PySpark DataFrame 列?
- java - Accepted as string despite being inputted as integer through nextInt()
- javascript - 将数据从 json 文件直接放入 javascript 变量
- javascript - 如何使文本内的单词可点击?
- amazon-web-services - AWS API Gateway Execution Logs to ELK
- java - Alternate Printing 2 Strings with multiple variables with Java
- python - Python Fit Function (Could not convert float to string)
- r - How can I use a reactive filtered dataset within a gauge plot?