다음을 통해 공유


DeviceManagementClient.GetHealthOfDevicesAsync(String, RequestContext) Method

Definition

Get list of device health.

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)

Parameters

filter
String

Restricts the set of devices for which device health is returned. You can filter on status, device id and module id.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The AsyncPageable<T> from the service containing a list of BinaryData objects. Details of the body schema for each item in the collection are in the Remarks section below.

Exceptions

filter is null.

Service returned a non-success status code.

Examples

This sample shows how to call GetHealthOfDevicesAsync with required parameters and parse the result.

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());
}

Remarks

Below is the JSON schema for one item in the pageable response.

Response Body:

Schema for 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
            }

Applies to