【问题标题】:MS Graph pagination in Logic App with result export in Azure Blob storage在 Azure Blob 存储中导出结果的逻辑应用程序中的 MS Graph 分页
【发布时间】:2020-12-28 21:47:28
【问题描述】:

我想做什么:

我正在尝试检索所有用户过去 24 小时的登录日志并将其保存在 blob 存储中。在第一个结果集创建 blob 后,下一个结果集将使用下一个剩余结果更新 blob 文件。

考虑使用 blob 存储和 MS Graph,因为 Graph 输出包含我想要的所有详细信息,而无需跳过 Powershell 中的各种箍来扩展某些属性,并且因为结果大小很大(通过 Export-CSV 超过 1GB在 PowerShell 中)。

我是怎么做到的

执行 HTTP 请求的计划运行,该请求使用过去 24 小时过滤的 Graph 查询创建一个以 HTTP 正文作为内容的块。创建 Blob 后,我添加了一个 (Do) Until 控件,该控件运行直到 HTTP 正文不包含 @odata.nextLink 并更新 blob 文件。

问题:

  1. 第一个问题是直到循环在 6 秒内完成。
  2. 第二个问题是 blob 文件只包含第一个结果集,大小通常为 9.3MB。这意味着下一个结果集不会被访问并附加到现有的 blob 文件中。

我的研究

我尝试启用和禁用分页、各种分页阈值、自定义函数,但没有任何意义(至少对我而言),我正在尝试遵循 KISS 模型。

我看了看并尝试以一种形状应用或从下面的 S.O. 中形成答案。问题: Graph Pagination in Logic Apps | Pagination with oauth azure data factory | Microsoft graph, batch request's nextLink | https://docs.microsoft.com/en-us/graph/paging;

我正在尝试的代码

{
"definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
        "Create_blob": {
            "inputs": {
                "body": "@body('fRequest')",
                "host": {
                    "connection": {
                        "name": "@parameters('$connections')['azureblob']['connectionId']"
                    }
                },
                "method": "post",
                "path": "/datasets/default/files",
                "queries": {
                    "folderPath": "/graph",
                    "name": "DoUntil",
                    "queryParametersSingleEncoded": true
                }
            },
            "runAfter": {
                "fRequest": [
                    "Succeeded"
                ]
            },
            "runtimeConfiguration": {
                "contentTransfer": {
                    "transferMode": "Chunked"
                }
            },
            "type": "ApiConnection"
        },
        "Until": {
            "actions": {
                "Update_blob": {
                    "inputs": {
                        "body": "@body('fRequest')",
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azureblob']['connectionId']"
                            }
                        },
                        "method": "put",
                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('/graph/DoUntil'))}"
                    },
                    "runAfter": {},
                    "type": "ApiConnection"
                }
            },
            "expression": "@not(contains(body('fRequest'), '@odata.nextLink'))",
            "limit": {
                "count": 60,
                "timeout": "PT1H"
            },
            "runAfter": {
                "Create_blob": [
                    "Succeeded"
                ]
            },
            "type": "Until"
        },
        "fRequest": {
            "inputs": {
                "authentication": {
                    "audience": "https://graph.microsoft.com",
                    "clientId": "registered_app",
                    "secret": "app_secret",
                    "tenant": "tenant_id",
                    "type": "ActiveDirectoryOAuth"
                },
                "method": "GET",
                "uri": "https://graph.microsoft.com/beta/auditLogs/signIns?$filter=createdDateTime gt @{addDays(utcNow(),-1)}"
            },
            "runAfter": {},
            "runtimeConfiguration": {
                "paginationPolicy": {
                    "minimumItemCount": 500
                }
            },
            "type": "Http"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    },
    "triggers": {
        "Recurrence": {
            "recurrence": {
                "frequency": "Week",
                "interval": 7,
                "schedule": {
                    "hours": [
                        "7"
                    ],
                    "minutes": [
                        0
                    ]
                }
            },
            "type": "Recurrence"
        }
    }
},
"parameters": {
    "$connections": {
        "value": {
            "azureblob": {
                "connectionId": "/subscriptions/subscription_id/resourceGroups/Apps/providers/Microsoft.Web/connections/azureblob",
                "connectionName": "azureblob",
                "id": "/subscriptions/subscription_id/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
            }
        }
    }
}

}

我做错了什么或错过了什么? 提前致谢!

【问题讨论】:

    标签: azure microsoft-graph-api azure-blob-storage azure-logic-apps


    【解决方案1】:

    我设法将分页阈值提高到 20000,现在我的文件不再是 9MB,它们的大小达到了 200MB。我还删除了“Do”循环。现在我只需要创建一个中断来避免阈值并继续收集剩余的结果页面。

    【讨论】:

      猜你喜欢
      • 2022-06-10
      • 1970-01-01
      • 2020-09-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 2020-02-14
      • 2021-05-06
      相关资源
      最近更新 更多