giip
合作夥伴SES 商機登記
6分鐘閱讀

網路拓撲 (Net3D) Azure 資源匯入指南

本指南說明如何把 Azure 訂閱的資源清單及資源之間的連線做成 JSON,並作為單獨的圖層疊加顯示在網路拓撲介面上。只要遵循本文件的架構,用任何工具(包括 AI)產生的 JSON 都可以直接匯入。

🚀 前往網路拓撲頁面 →

⚠️ 目前前提——請先閱讀

  • 僅支援手動匯入。 giip 伺服器不保存 Azure 憑證,也不在伺服器上執行 az(多租戶隔離原則)。JSON 由運營者(或代運營者行事的 AI)在自己的環境中產生,並在介面上直接匯入。
  • 不保存在伺服器上。 匯入的資料僅保留在瀏覽器工作階段(sessionStorage)中,不會傳送到伺服器。工作階段結束即消失,再次匯入會被替換。目前沒有定期/自動刷新的路徑。
  • 禁止秘密值。 JSON 中只放資源中繼資料和連線(邊)。切勿放入金鑰、連線字串、密碼等秘密值。本流程中的 az 命令在設計上不會回傳秘密值。

📋 概述

Azure 匯入圖層是與代理收集的伺服器/DB 圖(Net3D 主圖)相互獨立的疊加圖層。

  • 所有節點都繪製為球體,並按 Azure 資源類型使用固定顏色(圖例顯示在匯入面板中)。
  • 該圖層是可選開關(預設關閉)。關閉時只顯示主圖。
  • 像 App Service 這類無法安裝代理的 PaaS 資源,也可以透過該圖層出現在配置中。但它展示的是配置關係(哪個資源屬於哪裡、與什麼相連),而不是即時流量。

🚀 快速開始

  1. 在自己的 PC 上執行 az login 並選擇目標訂閱。
  2. 用下面的方法 1(export 腳本)或方法 2(按架構直接撰寫)產生匯入 JSON。
  3. 在拓撲介面開啟匯入 Azure 資源,上傳檔案或貼上 JSON。
  4. 開啟圖層開關,Azure 節點和連線就會疊加顯示在主圖之上。

方法 1:用 export 腳本產生

giipv3 倉庫中的輔助腳本會從 az 輸出組裝節點和邊。需要 az 和 jq。

az login
az account set --subscription <訂閱名稱或 ID>
./scripts/net3d-azure/export-azure-topology.sh > azure-topology.json
# 或把訂閱作為參數:./scripts/net3d-azure/export-azure-topology.sh "giip" > azure-topology.json

腳本收集的內容:

材料az 命令產生內容
資源清單az resource list全部 nodes(id·name·type·location·resourceGroup·kind)
站點 → 計劃az webapp list、az functionapp list 的 serverFarmIdhostedOn 邊
SQL DB → SQL 伺服器資源 id 的層級(/databases/ 之前的部分)childOf 邊
子網 → VNet資源 id 的層級(/subnets/ 之前的部分)childOf 邊
私人端點 → 目標az network private-endpoint list 的 privateLinkServiceIdprivateEndpoint 邊

az resource list 的 properties.serverFarmId 可能回傳為空,因此站點→計劃的連線必須從 az webapp list/az functionapp list 取得(腳本正是這樣做的)。

方法 2:按架構直接撰寫

頂層結構

{
  "schemaVersion": "1.0",                 // 可選。目前為 "1.0"
  "generatedAt": "2026-10-09T02:35:29Z",  // 可選。ISO8601 UTC
  "subscriptionName": "example-sub",      // 可選。僅用於顯示
  "subscriptionId": "00000000-0000-0000-0000-000000000000", // 可選。僅用於顯示
  "nodes": [ /* AzureImportNode[] */ ],   // 必填。為空會報錯
  "edges": [ /* AzureImportEdge[] */ ]    // 可選。可以缺失或為空
}

nodes[] —— 必填

欄位類型必填說明
idstring✅Azure resourceId(全域唯一)。是邊引用的鍵
namestring✅資源名稱(顯示用)。缺失時用 id 代替
typestring✅資源類型(例如 Microsoft.Web/sites)。用於圖例顏色分類
locationstring | null—區域(例如 japaneast)
resourceGroupstring | null—資源群組名稱
kindstring | null—kind(例如 functionapp、StorageV2)
  • 沒有 id 或 type 的節點會被排除在對應之外。id 重複時只保留第一項。

edges[] —— 可選

欄位類型必填說明
sourcestring✅起點節點的 resourceId
targetstring✅終點節點的 resourceId
relationstring—連線種類。預設值為 related

relation 標準值:

值含義依據
hostedOn站點(App Service/Function App)→ App Service 計劃serverFarmId
childOfSQL Database → SQL Server、子網 → VNetresourceId 層級
privateEndpointPrivate Endpoint → 目標資源privateLinkServiceId
  • 只有當邊的兩端節點都存在於 nodes[] 中時才會繪製(否則跳過)。
  • resourceId 可能大小寫混雜(例如 serverFarms 與 serverfarms),比對時先規範化為小寫再比較。
  • 指向自身的邊和重複邊會被排除。

完整的最小範例

{
  "schemaVersion": "1.0",
  "generatedAt": "2026-11-24T00:00:00Z",
  "subscriptionName": "example-sub",
  "subscriptionId": "00000000-0000-0000-0000-000000000000",
  "nodes": [
    {
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/serverfarms/example-plan",
      "name": "example-plan",
      "type": "Microsoft.Web/serverfarms",
      "location": "japaneast",
      "resourceGroup": "example-rg",
      "kind": null
    },
    {
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-app",
      "name": "example-app",
      "type": "Microsoft.Web/sites",
      "location": "japaneast",
      "resourceGroup": "example-rg",
      "kind": "app"
    },
    {
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Sql/servers/example-sql",
      "name": "example-sql",
      "type": "Microsoft.Sql/servers",
      "location": "japaneast",
      "resourceGroup": "example-rg",
      "kind": null
    },
    {
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Sql/servers/example-sql/databases/example-db",
      "name": "example-db",
      "type": "Microsoft.Sql/servers/databases",
      "location": "japaneast",
      "resourceGroup": "example-rg",
      "kind": null
    }
  ],
  "edges": [
    {
      "source": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/sites/example-app",
      "target": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Web/serverfarms/example-plan",
      "relation": "hostedOn"
    },
    {
      "source": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Sql/servers/example-sql/databases/example-db",
      "target": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Sql/servers/example-sql",
      "relation": "childOf"
    }
  ]
}

從 az 輸出直接建構的步驟

  1. 收集節點:把 az resource list --query "[].{id:id, name:name, type:type, location:location, resourceGroup:resourceGroup, kind:kind}" -o json 的輸出原樣用作 nodes。
  2. hostedOn:用 az webapp list --query "[].{id:id, serverFarmId:serverFarmId}" -o json 以及 az functionapp list 的相同查詢,為每個帶 serverFarmId 的項產生 {source: id, target: serverFarmId, relation: "hostedOn"}。
  3. childOf:type 為 Microsoft.Sql/servers/databases 的節點,其 id 在 /databases/ 之前的部分就是 SQL 伺服器 id;Microsoft.Network/virtualNetworks/subnets 的節點,其 /subnets/ 之前的部分就是 VNet id。
  4. privateEndpoint:用 az network private-endpoint list --query "[].{id:id, targets:privateLinkServiceConnections[].privateLinkServiceId}" -o json,為每個 target 產生 {source: id, target: target, relation: "privateEndpoint"}。
  5. 清理:刪除兩端不在 nodes 中的邊、自環邊和重複邊。比較以小寫規範化為準。
  6. 檢查秘密值:確認輸出 JSON 中沒有混入金鑰或連線字串。上述查詢在設計上不會回傳秘密值。

輸入驗證與上限

匯入時適配器會驗證輸入。介面不會損壞,只會顯示錯誤訊息。

項目上限超過時的錯誤鍵
原始文字大小5 MBnet3d.azure.error.tooLarge
節點數量3000net3d.azure.error.tooManyNodes
邊數量6000net3d.azure.error.tooManyEdges

其他錯誤鍵:輸入為空(emptyInput)、JSON 解析失敗(invalidJson)、頂層不是物件(invalidRoot)、缺少 nodes(missingNodes)、空陣列(emptyNodes)、有效節點為 0(noValidNodes)。

在介面上匯入的步驟

  1. 開啟 /zh-TW/network-topology。
  2. 點擊匯入 Azure 資源,透過上傳檔案或貼上 JSON 匯入。成功後會顯示匯入的節點/邊數量摘要。
  3. 開啟圖層開關進行顯示。在圖例中可以查看各類型的顏色。
  4. 如需移除,使用清除匯入(清空圖層)。工作階段結束後資料也不會保留。

疑難排解

症狀原因解決方法
tooManyNodes / tooManyEdges 錯誤超過上限縮小訂閱/資源群組範圍後重新產生
noValidNodes 錯誤所有節點都缺少 id/type按架構填寫節點欄位
邊沒有繪製出來邊的某一端不在 nodes 中把被引用的資源包含進 nodes。id 的大小寫會被忽略
沒有站點→計劃的邊使用了 az resource list 的 serverFarmId從 az webapp list/az functionapp list 取得
重新整理後圖層消失保存在 sessionStorage 中,工作階段結束即消失保存好 JSON 檔案,重新匯入
想定期自動刷新在目前前提(手動匯入)下沒有路徑只自動化 JSON 的產生,匯入仍在介面上進行

相關文件


版本:1.0 最後更新:2026-11-24 源文件:giipv3/public/help/api-network-topology-azure.zh-TW.md