从Azure Data Lake存储检索审核日志(第2代)

从Azure Data Lake存储检索审核日志(第2代),azure,Azure,我正在尝试从Azure Data Lake Storage(Gen 2)检索审核日志 到目前为止,我已经尝试在Gen2中使用AZCOPY、REST API(目前不支持)来检索(连接)审计日志,并寻找检索日志的替代解决方案 当使用AZCOPY连接时,它只使用基于API的调用,当我尝试检索日志时,我得到一个错误,即分层命名空间帐户不支持API调用。添加图像以供参考。 对于这个用例或者我可以尝试检索日志的任何其他方法,是否有任何解决方法?更新: 我可以通过读取api从ADLS GEN2获取文件内容。

我正在尝试从Azure Data Lake Storage(Gen 2)检索审核日志

到目前为止,我已经尝试在Gen2中使用AZCOPY、REST API(目前不支持)来检索(连接)审计日志,并寻找检索日志的替代解决方案

当使用AZCOPY连接时,它只使用基于API的调用,当我尝试检索日志时,我得到一个错误,即分层命名空间帐户不支持API调用。添加图像以供参考。


对于这个用例或者我可以尝试检索日志的任何其他方法,是否有任何解决方法?

更新:

我可以通过读取api从ADLS GEN2获取文件内容。我可以为您提供一个由python代码编写的示例(您可以根据我的代码更改为任何其他语言)。从下面的代码中,您可以直接获取文件内容,或者获取可在postman中使用的
授权

Python 3.7代码如下所示:

import requests
import datetime
import hmac
import hashlib
import base64

storage_account_name = 'xxx'
storage_account_key = 'xxx'
api_version = '2018-11-09'
request_time = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
#the file path on adls gen2
FILE_SYSTEM_NAME='dd1/myfile.txt'

string_params = {
    'verb': 'GET',
    'Content-Encoding': '',
    'Content-Language': '',
    'Content-Length': '',
    'Content-MD5': '',
    'Content-Type': '',
    'Date': '',
    'If-Modified-Since': '',
    'If-Match': '',
    'If-None-Match': '',
    'If-Unmodified-Since': '',
    'Range': '',
    'CanonicalizedHeaders': 'x-ms-date:' + request_time + '\nx-ms-version:' + api_version,
    'CanonicalizedResource': '/' + storage_account_name+'/'+FILE_SYSTEM_NAME
    }

string_to_sign = (string_params['verb'] + '\n' 
                  + string_params['Content-Encoding'] + '\n'
                  + string_params['Content-Language'] + '\n'
                  + string_params['Content-Length'] + '\n'
                  + string_params['Content-MD5'] + '\n' 
                  + string_params['Content-Type'] + '\n' 
                  + string_params['Date'] + '\n' 
                  + string_params['If-Modified-Since'] + '\n'
                  + string_params['If-Match'] + '\n'
                  + string_params['If-None-Match'] + '\n'
                  + string_params['If-Unmodified-Since'] + '\n'
                  + string_params['Range'] + '\n'
                  + string_params['CanonicalizedHeaders']+'\n'
                  + string_params['CanonicalizedResource'])

signed_string = base64.b64encode(hmac.new(base64.b64decode(storage_account_key), msg=string_to_sign.encode('utf-8'), digestmod=hashlib.sha256).digest()).decode()

#print out the datetime
print(request_time)
#print out the Authorization
print('SharedKey ' + storage_account_name + ':' + signed_string)

headers = {
    'x-ms-date' : request_time,
    'x-ms-version' : api_version,
    'Authorization' : ('SharedKey ' + storage_account_name + ':' + signed_string)
}
url = ('https://' + storage_account_name + '.dfs.core.windows.net/'+FILE_SYSTEM_NAME)
#print out the url
print(url)
r = requests.get(url, headers = headers)

#print out the file content
print(r.text)
运行代码后,将获取文件内容:

您还可以在上述代码中的邮递员中使用生成的值,如authorization/date:


正如您可能知道的,SDK还没有为azure data lake gen 2做好准备,因此到目前为止,解决方案正在使用

检索文件内容后,可以保存它


您可以自己进行身份验证。如果您对如何使用ADLS Gen 2 api阅读有任何疑问,请随时通知我。

更新:

我可以通过读取api从ADLS GEN2获取文件内容。我可以为您提供一个由python代码编写的示例(您可以根据我的代码更改为任何其他语言)。从下面的代码中,您可以直接获取文件内容,或者获取可在postman中使用的
授权

Python 3.7代码如下所示:

import requests
import datetime
import hmac
import hashlib
import base64

storage_account_name = 'xxx'
storage_account_key = 'xxx'
api_version = '2018-11-09'
request_time = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
#the file path on adls gen2
FILE_SYSTEM_NAME='dd1/myfile.txt'

string_params = {
    'verb': 'GET',
    'Content-Encoding': '',
    'Content-Language': '',
    'Content-Length': '',
    'Content-MD5': '',
    'Content-Type': '',
    'Date': '',
    'If-Modified-Since': '',
    'If-Match': '',
    'If-None-Match': '',
    'If-Unmodified-Since': '',
    'Range': '',
    'CanonicalizedHeaders': 'x-ms-date:' + request_time + '\nx-ms-version:' + api_version,
    'CanonicalizedResource': '/' + storage_account_name+'/'+FILE_SYSTEM_NAME
    }

string_to_sign = (string_params['verb'] + '\n' 
                  + string_params['Content-Encoding'] + '\n'
                  + string_params['Content-Language'] + '\n'
                  + string_params['Content-Length'] + '\n'
                  + string_params['Content-MD5'] + '\n' 
                  + string_params['Content-Type'] + '\n' 
                  + string_params['Date'] + '\n' 
                  + string_params['If-Modified-Since'] + '\n'
                  + string_params['If-Match'] + '\n'
                  + string_params['If-None-Match'] + '\n'
                  + string_params['If-Unmodified-Since'] + '\n'
                  + string_params['Range'] + '\n'
                  + string_params['CanonicalizedHeaders']+'\n'
                  + string_params['CanonicalizedResource'])

signed_string = base64.b64encode(hmac.new(base64.b64decode(storage_account_key), msg=string_to_sign.encode('utf-8'), digestmod=hashlib.sha256).digest()).decode()

#print out the datetime
print(request_time)
#print out the Authorization
print('SharedKey ' + storage_account_name + ':' + signed_string)

headers = {
    'x-ms-date' : request_time,
    'x-ms-version' : api_version,
    'Authorization' : ('SharedKey ' + storage_account_name + ':' + signed_string)
}
url = ('https://' + storage_account_name + '.dfs.core.windows.net/'+FILE_SYSTEM_NAME)
#print out the url
print(url)
r = requests.get(url, headers = headers)

#print out the file content
print(r.text)
运行代码后,将获取文件内容:

您还可以在上述代码中的邮递员中使用生成的值,如authorization/date:


正如您可能知道的,SDK还没有为azure data lake gen 2做好准备,因此到目前为止,解决方案正在使用

检索文件内容后,可以保存它


您可以自己进行身份验证。如果您对如何使用ADLS Gen 2 api进行阅读有任何疑问,请随时通知我。

ADLS Gen2
$logs
现在在ADLS Gen2中注册多协议访问时可用。有关多协议访问的博客,请访问。你可以在这里注册

当前不支持在Azure门户中启用日志。下面是一个如何使用PowerShell启用日志的示例

$storageAccount = Get-AzStorageAccount -ResourceGroupName <resourceGroup> -Name <storageAccountName>

Set-AzStorageServiceLoggingProperty -Context $storageAccount.Context -ServiceType Blob -LoggingOperations read,write,delete -RetentionDays <days>. 
$storageAccount=Get-AzStorageAccount-ResourceGroupName-Name
设置AzStorageServiceLoggingProperty-Context$storageAccount.Context-ServiceType Blob-LoggingOperations读取、写入、删除-保留天数。

要使用日志,您现在可以使用AzCopy和SDK。您暂时无法在Azure Storage Explorer中查看
$logs

ADLS Gen2
$logs
现在在ADLS Gen2中注册多协议访问时可用。有关多协议访问的博客,请访问。你可以在这里注册

当前不支持在Azure门户中启用日志。下面是一个如何使用PowerShell启用日志的示例

$storageAccount = Get-AzStorageAccount -ResourceGroupName <resourceGroup> -Name <storageAccountName>

Set-AzStorageServiceLoggingProperty -Context $storageAccount.Context -ServiceType Blob -LoggingOperations read,write,delete -RetentionDays <days>. 
$storageAccount=Get-AzStorageAccount-ResourceGroupName-Name
设置AzStorageServiceLoggingProperty-Context$storageAccount.Context-ServiceType Blob-LoggingOperations读取、写入、删除-保留天数。

要使用日志,您现在可以使用AzCopy和SDK。您暂时无法在Azure Storage Explorer中查看
$logs

随着2019年11月(1.11.1版)Azure Storage Explorer的发布,现在可以在2019年11月(1.11.1版)的Azure Storage Explorer中查看隐藏的容器,例如$logs

,现在可以查看隐藏的容器,如$logs

我们尝试使用ADL的读取API(Gen 2)读取数据,但在尝试从Postman API工具中点击URL后遇到了与上述相同的错误。从ADL(Gen 2)检索审计日志的任何其他建议或替代方法都会有所帮助。我们尝试使用ADL的读取API(Gen 2)读取数据,但在尝试从Postman API工具点击URL后遇到了与上述相同的错误。从ADL(Gen 2)检索审计日志的任何其他建议或替代方法都会有所帮助