【Azure Developer】使用REST API获取Activity Logs、传入Data Lake的数据格式问题

简介: 【Azure Developer】使用REST API获取Activity Logs、传入Data Lake的数据格式问题

问题一:.  如何在用REST API获取活动日志时,控制输出的项?

【答】参考REST API对于获取活动日志的说明接口,在参数是$filter$select中可以分别控制过滤条件输出项

GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter={$filter}&$select={$select}

注:management.chinacloudapi.cn为中国区Azure的管理终结点,management.azure.com为全球Azure的管理终结点

URI Parameters

Name Description

$filter

Reduces the set of data collected.

This argument is required and it also requires at least the start date/time.

The $filter argument is very restricted and allows only the following patterns.

- List events for a resource group:

$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceGroupName eq 'resourceGroupName'.

- List events for resource:

$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceUri eq 'resourceURI'.

- List events for a subscription in a time range:

$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z'.

- List events for a resource provider:

$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceProvider eq 'resourceProviderName'.

- List events for a correlation Id:

$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and correlationId eq 'correlationID'.


NOTE: No other syntax is allowed.

$select

Used to fetch events with only the given properties.

The $select argument is a comma separated list of property names to be returned.

Possible values are: 

authorization, claims, correlationId, description, eventDataId

eventName, eventTimestamp, httpRequest, level, operationId

operationName, properties, resourceGroupName, resourceProviderName

resourceId, status, submissionTimestamp, subStatus, subscriptionId

在Filter和select可以配置的每一项说明,请查看文末的附录一

 

问题二:是否可以往Data Lake中注入Json格式文件?

【答】根据官方文档示例,如果使用Databricks进行(SQL查询语句)进行数据分析,是支持Json格式的数据,示例中使用的Json格式如下图所示:

参考使用 Databricks 分析数据一文: https://docs.azure.cn/zh-cn/storage/blobs/data-lake-storage-quickstart-create-databricks-account#ingest-sample-data

 

问题三:如何用C#向Data Lake中插入数据文件?

【答】可以,需要先安装 Azure.Storage.Files.DataLake NuGet 包。然后添加如下引用

using Azure.Storage.Files.DataLake;

using Azure.Storage.Files.DataLake.Models;

using Azure.Storage;

using System.IO;

using Azure;

将文件上传到目录,则参考以下代码即可:

public async Task UploadFile(DataLakeFileSystemClient fileSystemClient)
{
    DataLakeDirectoryClient directoryClient =
        fileSystemClient.GetDirectoryClient("my-directory");
    DataLakeFileClient fileClient = await directoryClient.CreateFileAsync("uploaded-file.txt");
    FileStream fileStream = 
        File.OpenRead("C:\\file-to-upload.txt");
    long fileSize = fileStream.Length;
    await fileClient.AppendAsync(fileStream, offset: 0);
    await fileClient.FlushAsync(position: fileSize);
}

完整实例参考使用 .NET 管理 Azure Data Lake Storage Gen2https://docs.azure.cn/zh-cn/storage/blobs/data-lake-storage-directory-file-acl-dotnet#upload-a-file-to-a-directory

 

 

附录一:在和和Filter和select可配置的选择项的EventData属性

The Azure event log entries are of type EventData

Name Type Description
authorization

The sender authorization information.

caller
  • string

the email address of the user who has performed the operation,

the UPN claim or SPN claim based on availability.

category

the event category.

claims
  • object

key value pairs to identify ARM permissions.

correlationId
  • string

the correlation Id, usually a GUID in the string format.

The correlation Id is shared among the events that belong to the same uber operation.

description
  • string

the description of the event.

eventDataId
  • string

the event data Id. This is a unique identifier for an event.

eventName

the event name. This value should not be confused with OperationName.

For practical purposes, OperationName might be more appealing to end users.

eventTimestamp
  • string

the timestamp of when the event was generated by the Azure service processing the

request corresponding the event. It in ISO 8601 format.

httpRequest

the HTTP request info. Usually includes the 'clientRequestId', 'clientIpAddress'

(IP address of the user who initiated the event) and 'method' (HTTP method e.g. PUT).

id
  • string

the Id of this event as required by ARM for RBAC. It contains the EventDataID

and a timestamp information.

level

the event level

operationId
  • string

It is usually a GUID shared among the events corresponding to single operation.

This value should not be confused with EventName.

operationName

the operation name.

properties
  • object

the set of <Key, Value> pairs (usually a Dictionary<String, String>)

that includes details about the event.

resourceGroupName
  • string

the resource group name of the impacted resource.

resourceId
  • string

the resource uri that uniquely identifies the resource that caused this event.

resourceProviderName

the resource provider name of the impacted resource.

resourceType

the resource type

status

a string describing the status of the operation.

Some typical values are: Started, In progress, Succeeded, Failed, Resolved.

subStatus

the event sub status.

Most of the time, when included, this captures the HTTP status code of the REST call.

Common values are:

OK (HTTP Status Code: 200),

Created (HTTP Status Code: 201),

Accepted (HTTP Status Code: 202),

No Content (HTTP Status Code: 204),

Bad Request(HTTP Status Code: 400),

Not Found (HTTP Status Code: 404),

Conflict (HTTP Status Code: 409),

Internal Server Error (HTTP Status Code: 500),

Service Unavailable (HTTP Status Code:503),

Gateway Timeout (HTTP Status Code: 504)

submissionTimestamp
  • string

the timestamp of when the event became available for querying via this API.

It is in ISO 8601 format. This value should not be confused eventTimestamp.

As there might be a delay between the occurrence time of the event,

and the time that the event is submitted to the Azure logging infrastructure.

subscriptionId
  • string

the Azure subscription Id usually a GUID.

tenantId
  • string

the Azure tenant Id

 

相关文章
|
27天前
|
安全 API 网络安全
【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)
【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)
|
27天前
|
API 开发工具 网络架构
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
|
21天前
|
XML 安全 API
REST 和 SOAP API 有什么区别?
【8月更文挑战第31天】
23 0
|
21天前
|
JSON API 数据安全/隐私保护
哇塞!Django REST framework 太逆天啦!构建 API 服务从未如此轻松,你还不来试试?
【8月更文挑战第31天】Django REST framework(DRF)是基于Django框架的高效Web API开发工具,提供序列化、视图集、路由等功能,简化API构建流程。使用DRF可轻松实现数据的序列化与反序列化,并支持权限管理和认证机制以保障API安全。安装DRF只需通过`pip install djangorestframework`命令。要创建基本项目,先安装Django并创建新应用,定义模型、序列化器及视图集,最后配置路由。测试API时,可通过Postman发送HTTP请求验证功能。无论项目大小,DRF均能提供强大支持。
23 0
|
26天前
|
中间件 API 网络架构
Django后端架构开发:从匿名用户API节流到REST自定义认证
Django后端架构开发:从匿名用户API节流到REST自定义认证
13 0
|
27天前
|
存储 Kubernetes API
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
【APIM】Azure API Management Self-Host Gateway是否可以把请求的日志发送到Application Insights呢?让它和使用Azure上托管的 Gateway一样呢?
|
27天前
|
API 网络架构 C++
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
【Azure Key Vault】使用REST API调用Azure Key Vault Secret的示例步骤
|
1月前
|
机器人 API Python
智能对话机器人(通义版)会话接口API使用Quick Start
本文主要演示了如何使用python脚本快速调用智能对话机器人API接口,在参数获取的部分给出了具体的获取位置截图,这部分容易出错,第一次使用务必仔细参考接入参数获取的位置。
100 1
|
22天前
|
存储 JSON API
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
——在成长的路上,我们都是同行者。这篇关于商品详情API接口的文章,希望能帮助到您。期待与您继续分享更多API接口的知识,请记得关注Anzexi58哦! 淘宝API接口(如淘宝开放平台提供的API)允许开发者获取淘宝商品的各种信息,包括商品详情。然而,需要注意的是,直接访问淘宝的商品数据API通常需要商家身份或开发者权限,并且需要遵循淘宝的API使用协议。
淘系API接口(解析返回的json数据)商品详情数据解析助力开发者
|
1月前
|
SQL 存储 数据处理