你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DeviceManagementClient.GetHealthOfDevicesAsync(String, RequestContext) 方法

定义

获取设备运行状况列表。

public virtual Azure.AsyncPageable<BinaryData> GetHealthOfDevicesAsync (string filter, Azure.RequestContext context = default);
abstract member GetHealthOfDevicesAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
override this.GetHealthOfDevicesAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
Public Overridable Function GetHealthOfDevicesAsync (filter As String, Optional context As RequestContext = Nothing) As AsyncPageable(Of BinaryData)

参数

filter
String

限制为其返回设备运行状况的设备集。 可以筛选状态、设备 ID 和模块 ID。

context
RequestContext

请求上下文,它可以基于每个调用替代客户端管道的默认行为。

返回

AsyncPageable<T>包含对象列表的服务中的 BinaryData 。 集合中每个项目的正文架构的详细信息,请参阅下面的“备注”部分。

例外

filter 为 null。

服务返回了不成功状态代码。

示例

此示例演示如何使用所需参数调用 GetHealthOfDevicesAsync 并分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

await foreach (var data in client.GetHealthOfDevicesAsync("<filter>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceId").ToString());
    Console.WriteLine(result.GetProperty("moduleId").ToString());
    Console.WriteLine(result.GetProperty("state").ToString());
    Console.WriteLine(result.GetProperty("digitalTwinModelId").ToString());
    Console.WriteLine(result.GetProperty("healthChecks")[0].GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("healthChecks")[0].GetProperty("result").ToString());
}

注解

下面是可分页响应中一项的 JSON 架构。

响应正文:

DeviceHealthListValue架构:

{
              deviceId: string, # Required. Device id
              moduleId: string, # Optional. Module id
              state: "healthy" | "unhealthy", # Required. Aggregate device health state
              digitalTwinModelId: string, # Optional. Digital twin model Id
              healthChecks: [
                {
                  name: string, # Optional. Health check name
                  result: "success" | "userError", # Optional. Health check result
                }
              ], # Required. Array of health checks and their results
            }

适用于