Azure DevOps 审核日志下载休息 api 未下载给定月份的过滤数据
Azure DevOps audit logs download rest api not downloading filtered data for given months
您好,我无法下载上述持续时间的数据,它会下载所有日志。
$outfile = "/logs.csv"
$connectionToken=""
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::
ASCII.GetBytes(":$($connectionToken)"))
$AuditLogURL = "https://auditservice.dev.azure.com/{og_name}/_apis/audit/downloadlog?
format=csv&startTime=2020-09-04T00.00.00&endTime=2020-10-05T00.00.00&api-version=6.1-
preview.1"
$AuditInfo = Invoke-RestMethod -Uri $AuditLogURL -Headers @{authorization = "Basic
$base64AuthInfo"} -Method Get –OutFile $outfile
这里我提到的开始日期是第 9 个月,我仍然可以看到第 8 个月的日志。
这是 Microsoft 的 url - GET https://auditservice.dev.azure.com/{organization}/_apis/audit/downloadlog?format=json&startTime=2020-09-04T14:05:59.928Z&endTime=2020-10-05T14:05:59.928Z&api-version=6.0-preview.1
我尝试使用相同的日期格式 - startTime=2019-03-04T14:05:59.928Z&endTime=2019-03-05T14:05:59.928Z 然后它 returns 空文件
如何只下载选定月份和时间的过滤数据?
谢谢。
如果省略时间(请参阅下面的第一次调用),它似乎默认为午夜。
我认为您遇到的问题是您使用的是 .
而不是 :
(请参阅下面的第二次调用)。
关于你关于 .928Z
的最后一个问题,我不确定为什么它不起作用,你可能想检查脚本中是否还有其他问题,它对我来说很好(见第三下面的调用)。
这是我编写的一些 PowerShell,可以更容易地发现问题:
function Export-AzureDevOpsAuditLog {
param (
[Parameter(Mandatory = $true)]
[String] $Outfile,
[Parameter(Mandatory = $true)]
[String] $PersonalToken,
[Parameter(Mandatory = $true)]
[String] $Organization,
[Parameter(Mandatory = $true)]
[String] $StartTime,
[Parameter(Mandatory = $true)]
[String] $EndTime
)
$api_version = '6.1-preview.1'
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PersonalToken)"))
$headers = @{authorization = "Basic $token" }
$uri = "https://auditservice.dev.azure.com/$Organization/_apis/audit/downloadlog?format=csv&startTime=$StartTime&endTime=$EndTime&api-version=$api_version"
$result = Invoke-RestMethod -uri $uri -Headers $headers -Method Get -OutFile $Outfile
}
$organization = 'REDACTED'
$outfile1 = '.\AzureDevOpsAuditLog-1.csv'
$outfile2 = '.\AzureDevOpsAuditLog-2.csv'
$outfile3 = '.\AzureDevOpsAuditLog-3.csv'
$personalToken = 'REDACTED'
Export-AzureDevOpsAuditLog -Outfile $outfile1 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-23' -EndTime '2020-10-24'
Export-AzureDevOpsAuditLog -Outfile $outfile2 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-24T02:00:00' -EndTime '2020-10-24T05:00:00'
Export-AzureDevOpsAuditLog -Outfile $outfile3 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-24T02:00:00.928Z' -EndTime '2020-10-24T05:00:00.928Z'
How can I download filtered data for only selected month and time?
您的问题的原因是您使用的是.
而不是:
采用您的日期格式。
正确的日期格式应该是:
startTime=2020-09-04T00:00:00&endTime=2020-10-05T00:00:00
时间格式有严格要求,如yyyy-MM-dd'T'HH:mm:ss.SSSz
:
yyyy: Year
MM: Month
dd: Day
HH: Hour
mm: Minute
ss: Second
SSS: Millisecond
z: Time zone
对于您的要求,我们甚至可以忽略详细时间,只保留日期:
startTime=2020-09-04&endTime=2020-10-05
除了之外,为什么在示例中使用日期格式时仍然得到空文件的原因。 startTime=2019-03-04T14:05:59.928Z&endTime=2019-03-05T14:05:59.928Z
。那是因为事件会被存储90天然后被删除。:
Access, export, and filter audit logs:
Auditing is turned on by default for all Azure DevOps Services
organizations. You can't turn auditing off, which ensures that you
never miss an actionable event. Events get stored for 90 days and then
they’re deleted. However, you can back up audit events to an external
location to keep the data for longer than the 90-day period.
您好,我无法下载上述持续时间的数据,它会下载所有日志。
$outfile = "/logs.csv"
$connectionToken=""
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::
ASCII.GetBytes(":$($connectionToken)"))
$AuditLogURL = "https://auditservice.dev.azure.com/{og_name}/_apis/audit/downloadlog?
format=csv&startTime=2020-09-04T00.00.00&endTime=2020-10-05T00.00.00&api-version=6.1-
preview.1"
$AuditInfo = Invoke-RestMethod -Uri $AuditLogURL -Headers @{authorization = "Basic
$base64AuthInfo"} -Method Get –OutFile $outfile
这里我提到的开始日期是第 9 个月,我仍然可以看到第 8 个月的日志。
这是 Microsoft 的 url - GET https://auditservice.dev.azure.com/{organization}/_apis/audit/downloadlog?format=json&startTime=2020-09-04T14:05:59.928Z&endTime=2020-10-05T14:05:59.928Z&api-version=6.0-preview.1
我尝试使用相同的日期格式 - startTime=2019-03-04T14:05:59.928Z&endTime=2019-03-05T14:05:59.928Z 然后它 returns 空文件
如何只下载选定月份和时间的过滤数据?
谢谢。
如果省略时间(请参阅下面的第一次调用),它似乎默认为午夜。
我认为您遇到的问题是您使用的是 .
而不是 :
(请参阅下面的第二次调用)。
关于你关于 .928Z
的最后一个问题,我不确定为什么它不起作用,你可能想检查脚本中是否还有其他问题,它对我来说很好(见第三下面的调用)。
这是我编写的一些 PowerShell,可以更容易地发现问题:
function Export-AzureDevOpsAuditLog {
param (
[Parameter(Mandatory = $true)]
[String] $Outfile,
[Parameter(Mandatory = $true)]
[String] $PersonalToken,
[Parameter(Mandatory = $true)]
[String] $Organization,
[Parameter(Mandatory = $true)]
[String] $StartTime,
[Parameter(Mandatory = $true)]
[String] $EndTime
)
$api_version = '6.1-preview.1'
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PersonalToken)"))
$headers = @{authorization = "Basic $token" }
$uri = "https://auditservice.dev.azure.com/$Organization/_apis/audit/downloadlog?format=csv&startTime=$StartTime&endTime=$EndTime&api-version=$api_version"
$result = Invoke-RestMethod -uri $uri -Headers $headers -Method Get -OutFile $Outfile
}
$organization = 'REDACTED'
$outfile1 = '.\AzureDevOpsAuditLog-1.csv'
$outfile2 = '.\AzureDevOpsAuditLog-2.csv'
$outfile3 = '.\AzureDevOpsAuditLog-3.csv'
$personalToken = 'REDACTED'
Export-AzureDevOpsAuditLog -Outfile $outfile1 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-23' -EndTime '2020-10-24'
Export-AzureDevOpsAuditLog -Outfile $outfile2 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-24T02:00:00' -EndTime '2020-10-24T05:00:00'
Export-AzureDevOpsAuditLog -Outfile $outfile3 -PersonalToken $personalToken -Organization $organization -StartTime '2020-10-24T02:00:00.928Z' -EndTime '2020-10-24T05:00:00.928Z'
How can I download filtered data for only selected month and time?
您的问题的原因是您使用的是.
而不是:
采用您的日期格式。
正确的日期格式应该是:
startTime=2020-09-04T00:00:00&endTime=2020-10-05T00:00:00
时间格式有严格要求,如yyyy-MM-dd'T'HH:mm:ss.SSSz
:
yyyy: Year
MM: Month
dd: Day
HH: Hour
mm: Minute
ss: Second
SSS: Millisecond
z: Time zone
对于您的要求,我们甚至可以忽略详细时间,只保留日期:
startTime=2020-09-04&endTime=2020-10-05
除了之外,为什么在示例中使用日期格式时仍然得到空文件的原因。 startTime=2019-03-04T14:05:59.928Z&endTime=2019-03-05T14:05:59.928Z
。那是因为事件会被存储90天然后被删除。:
Access, export, and filter audit logs:
Auditing is turned on by default for all Azure DevOps Services organizations. You can't turn auditing off, which ensures that you never miss an actionable event. Events get stored for 90 days and then they’re deleted. However, you can back up audit events to an external location to keep the data for longer than the 90-day period.