查看 OS 資產資料

支援的作業系統

如需支援 OS Inventory Management 的作業系統和版本完整清單,請參閱「作業系統詳細資料」。

必要角色和權限

如要取得列出及說明產品目錄資料所需的權限,請要求管理員為您授予專案的 OS 產品目錄檢視者(roles/osconfig.inventoryViewer) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

您或許還可透過自訂角色或其他預先定義的角色取得必要權限。

設定 VM

您必須先把 VM 設定為會使用 OS Inventory Management,才能讓您使用該功能。如要將 VM 設為使用 OS Inventory Management,請設定 VM 管理員

在 VM 上設定 VM 管理員後,您就能查看 OS 庫存資料和安全漏洞報告。

查看 OS 資產資料

查看 VM 的 OS 資產資料

您可以使用 Google Cloud 控制台、gcloud CLI 或 OS Config API 查看特定 VM 的 OS 資訊。

主控台

如要使用 Google Cloud 控制台查看 VM 上的 OS 漏洞和已安裝套件的相關資訊,請執行下列步驟:

  1. 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面

    前往 VM 執行個體

  2. 按一下要查看 OS 資訊的執行個體名稱。「Instance details」(執行個體詳細資料) 頁面隨即顯示。
  3. 按一下「OS 資訊」分頁標籤。
    如要查看 OS 庫存資料,您必須啟用 VM 管理工具。如果 Google Cloud 控制台提示您啟用 VM Manager,請選取下列任一選項:
    • 為目前專案啟用:為所選專案中的所有 VM 啟用 VM 管理員
    • 為此 VM 啟用:僅為所選 VM 啟用 VM 管理員
  4. 在「OS info」分頁中查看 OS 安全漏洞和已安裝套件的清單。
  5. 選用:如果任何已安裝的套件有可用的更新,請選取套件名稱,然後按一下「Apply updates」
    「Patch」頁面隨即顯示。如要進一步瞭解如何在 VM 管理員中使用「修補」功能,請參閱「建立修補工作」。

gcloud

如要查看特定 VM 的庫存詳細資料,請執行 os-config inventories describe 指令

gcloud compute os-config inventories describe VM_NAME \
    --location=ZONE \
    --view=VIEW

更改下列內容:

  • VM_NAME:VM 名稱
  • ZONE:VM 執行個體所在的區域
  • VIEW:必要的輸出資訊類型。可用的檢視類型如下:

    • basic:只顯示 OS 資訊
    • full:顯示 OS 和套件相關資訊

      如未指定,則預設為 basic

    範例 (基本檢視畫面)

    gcloud compute os-config inventories describe vm1-centos \
       --location=us-central1-c
    

    輸出範例

    architecture: x86_64
    hostname: vm1-centos
    kernelRelease: 3.10.0-1160.92.1.el7.x86_64
    kernelVersion: '#1 SMP Tue Jun 20 11:48:01 UTC 2023'
    longName: CentOS Linux 7 (Core)
    osconfigAgentVersion: 20230504.00-g1.el7
    shortName: centos
    updateTime: '2023-07-26T17:03:50Z'
    version: '7'
    

    示例 (完整檢視畫面)

    gcloud compute os-config inventories describe vm1-centos \
       --location=us-central1-c \
       --view=full
    

    Linux 範例輸出內容

    ┌─────────────────────────────────────────────────────────────────────────────────────┐
    │                               Installed Packages (Yum)                              │
    ├─────────────────────────────────────┬──────────────┬────────────────────────────────┤
    │             PACKAGE_NAME            │ ARCHITECTURE │            VERSION             │
    ├─────────────────────────────────────┼──────────────┼────────────────────────────────┤
    │ GeoIP                               │ x86_64       │ 1.5.0-13.el7                   │
    │ NetworkManager                      │ x86_64       │ 1:1.12.0-8.el7_6               │
    │ NetworkManager-libnm                │ x86_64       │ 1:1.12.0-8.el7_6               │
    │ NetworkManager-team                 │ x86_64       │ 1:1.12.0-8.el7_6               │
    │ NetworkManager-tui                  │ x86_64       │ 1:1.12.0-8.el7_6               │
    │ acl                                 │ x86_64       │ 2.2.51-14.el7                  │
    │ yum-cron                            │ all          │ 3.4.3-161.el7.centos           │
    │ yum-metadata-parser                 │ x86_64       │ 1.1.4-10.el7                   │
    │ yum-plugin-fastestmirror            │ all          │ 1.1.31-50.el7                  │
    │ zlib                                │ x86_64       │ 1.2.7-18.el7                   │
    └─────────────────────────────────────┴──────────────┴────────────────────────────────┘
    ┌───────────────────────────────────────────────────────────────────────────────┐
    │                        Package Updates Available (Yum)                        │
    ├───────────────────────────────┬──────────────┬────────────────────────────────┤
    │          PACKAGE_NAME         │ ARCHITECTURE │            VERSION             │
    ├───────────────────────────────┼──────────────┼────────────────────────────────┤
    │ GeoIP                         │ x86_64       │ 1.5.0-14.el7                   │
    │ NetworkManager                │ x86_64       │ 1:1.18.8-2.el7_9               │
    │ NetworkManager-libnm          │ x86_64       │ 1:1.18.8-2.el7_9               │
    │ NetworkManager-team           │ x86_64       │ 1:1.18.8-2.el7_9               │
    │ yum-cron                      │ all          │ 3.4.3-168.el7.centos           │
    │ yum-plugin-fastestmirror      │ all          │ 1.1.31-54.el7_8                │
    │ zlib                          │ x86_64       │ 1.2.7-19.el7_9                 │
    └───────────────────────────────┴──────────────┴────────────────────────────────┘
    architecture: x86_64
    hostname: vm1-centos
    kernelRelease: 3.10.0-957.1.3.el7.x86_64
    kernelVersion: '#1 SMP Thu Nov 29 14:49:43 UTC 2018'
    longName: CentOS Linux 7 (Core)
    osconfigAgentVersion: 20230504.00-g1.el7
    shortName: centos
    updateTime: '2021-05-11T22:21:52.323Z'
    version: '7'
    

    Windows 輸出內容範例

    ┌───────────────────────────────────────────────────────────┐
    │                Installed Packages (GooGet)                │
    ├───────────────────────┬──────────────┬────────────────────┤
    │      PACKAGE_NAME     │ ARCHITECTURE │      VERSION       │
    ├───────────────────────┼──────────────┼────────────────────┤
    │ google-osconfig-agent │ x86_64       │ 20210415.4.0+win@1 │
    └───────────────────────┴──────────────┴────────────────────┘
    ┌───────────────────────────────────────────────────┐
    │     Installed Packages (Windows Update Agent)     │
    ├───────┬────────────┬────────────────┬─────────────┤
    │ TITLE │ CATEGORIES │ KB_ARTICLE_IDS │ SUPPORT_URL │
    ├───────┼────────────┼────────────────┼─────────────┤
    │ title │ C1, C2     │ 4589208        │ url.com     │
    └───────┴────────────┴────────────────┴─────────────┘
    ┌───────────────────────────────────────────────────────────────┐
    │           Installed Packages (Quick Fix Engineering)          │
    ├─────────┬─────────────────┬────────────┬──────────────────────┤
    │ CAPTION │   DESCRIPTION   │ HOT_FIX_ID │     INSTALL_TIME     │
    ├─────────┼─────────────────┼────────────┼──────────────────────┤
    │ caption │ Security Update │ KB4470788  │ 2019-03-12T00:00:00Z │
    └─────────┴─────────────────┴────────────┴──────────────────────┘
    ┌───────────────────────────────────────────────────────────────────────────┐
    │                  Installed Packages (Windows Application)                 │
    ├──────────────────┬─────────────────┬───────────────────────┬──────────────┤
    │   DISPLAY_NAME   │ DISPLAY_VERSION │       PUBLISHER       │ INSTALL_DATE │
    ├──────────────────┼─────────────────┼───────────────────────┼──────────────┤
    │ PowerShell 7-x64 │ 7.0.2.0         │ Microsoft Corporation │ 2021-06-08   │
    └──────────────────┴─────────────────┴───────────────────────┴──────────────┘
    ┌───────────────────────────────────────────────────────────┐
    │             Package Updates Available (GooGet)            │
    ├───────────────────────┬──────────────┬────────────────────┤
    │      PACKAGE_NAME     │ ARCHITECTURE │      VERSION       │
    ├───────────────────────┼──────────────┼────────────────────┤
    │ google-osconfig-agent │ x86_64       │ 20210415.4.0+win@1 │
    └───────────────────────┴──────────────┴────────────────────┘
    ┌───────────────────────────────────────────────────┐
    │  Package Updates Available (Windows Update Agent) │
    ├───────┬────────────┬────────────────┬─────────────┤
    │ TITLE │ CATEGORIES │ KB_ARTICLE_IDS │ SUPPORT_URL │
    ├───────┼────────────┼────────────────┼─────────────┤
    │ title │ C1, C2     │ 4589208        │ url.com     │
    └───────┴────────────┴────────────────┴─────────────┘
    ┌───────────────────────────────────────────────────────────────┐
    │       Package Updates Available (Quick Fix Engineering)       │
    ├─────────┬─────────────────┬────────────┬──────────────────────┤
    │ CAPTION │   DESCRIPTION   │ HOT_FIX_ID │     INSTALL_TIME     │
    ├─────────┼─────────────────┼────────────┼──────────────────────┤
    │ caption │ Security Update │ KB4470788  │ 2019-03-12T00:00:00Z │
    └─────────┴─────────────────┴────────────┴──────────────────────┘
    architecture: x86_64
    hostname: vm3-windows
    kernelRelease: 10.0.17763.1817
    kernelVersion: 10.0.17763.1817 (WinBuild.160101.0800)
    longName: Microsoft Windows Server 2019 Datacenter
    osconfigAgentVersion: 20210901.00.0+win@1
    shortName: windows
    updateTime: '2021-09-12T22:14:35Z'
    version: 10.0.17763
    

REST

如要查看特定 VM 的廣告空間詳細資料,請建立 GET 要求,並傳送至 projects.locations.instances.inventories.get 方法

   GET https://osconfig.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/instances/INSTANCE/inventory
   

更改下列內容:

  • PROJECT_ID:您的專案 ID
  • ZONE:VM 執行個體所在的區域
  • INSTANCE:指定 VM 的執行個體 ID 或名稱

查看特定可用區中 VM 的 OS 資產資料

您可以使用 gcloud CLI 或 OS Config API 查看特定區域中 VM 的 OS 資訊。

gcloud

如要查看特定區域中 VM 的庫存資料清單,請執行 os-config inventories list 指令

gcloud compute os-config inventories list \
    --location=ZONE \
    --view=VIEW

更改下列內容:

  • ZONE:VM 所在區域
  • VIEW:必要的輸出資訊類型。可用的檢視類型如下:

    • basic:只顯示 OS 資訊
    • full:顯示 OS 和套件相關資訊

      如未指定,則預設為 basic

    範例 (基本檢視畫面)

    gcloud compute os-config inventories list \
       --location=us-central1-c
    

    輸出結果會與下列內容相似:

    INSTANCE_ID          INSTANCE_NAME     OS                                         OSCONFIG_AGENT_VERSION       UPDATE_TIME
    29255009728795105    vm1-centos        CentOS Linux 7 (Core)                      20230504.00-g1.el7           2023-07-26T16:53:49Z
    5138980234596718741  vm2-rhel8         Red Hat Enterprise Linux 8.8 (Ootpa)       20230504.00-g1.el8           2023-07-26T16:55:33Z
    7127836223366142250  vm3-windows       Microsoft Windows Server 2022 Datacenter   20230403.00.0+win@1          2023-07-26T16:49:16Z
    

    示例 (完整檢視畫面)

    gcloud compute os-config inventories list \
       --location=us-central1-c \
       --view=full
    

    輸出結果會與下列內容相似:

    INSTANCE_ID          INSTANCE_NAME     OS                                       INSTALLED_PACKAGES   AVAILABLE_PACKAGES  OSCONFIG_AGENT_VERSION       UPDATE_TIME
    29255009728795105    vm1-centos        CentOS Linux 7 (Core)                    334                    2                 20230504.00-g1.el7           2023-07-26T16:53:49Z
    5932621394110773366  vm2-rhel8         Red Hat Enterprise Linux 8.8 (Ootpa)     410                  138                 20230504.00-g1.el8           2023-07-26T16:55:33Z
    7127836223366142250  vm3-windows       Microsoft Windows Server 2022 Datacenter  36                    6                 20230403.00.0+win@1          2023-07-26T16:49:16Z
    

REST

如要查看特定區域中 VM 的清單資料,請建立對 projects.locations.instances.inventories.list 方法GET 要求。

   GET https://osconfig.googleapis.com/v1/projects/PROJECT_ID/locations/ZONE/instances/–/inventories
   

更改下列內容:

  • PROJECT_ID:您的專案 ID
  • ZONE:VM 所在的可用區

查看 Cloud Asset Inventory 中的 OS 資產資料

OS 庫存管理服務會儲存及轉送庫存和漏洞報告資料至 Cloud Asset Inventory。Cloud Asset Inventory 是一種中繼資料儲存庫服務,可讓您檢視、監控及分析各項 Google Cloud中的資產。您可以透過 Cloud Asset Inventory 擷取資訊,並查看資料變更。

如要透過 Cloud Asset Inventory 存取 OS 庫存和漏洞報告資料,您必須完成下列設定:

詳情請參閱「查看 VM 管理員資料」。

OS 庫存管理服務 (舊版)

如果您仍在使用舊版 OS 庫存管理服務,請展開下列章節,查看 Google Cloud CLI 的操作說明。

OS 庫存管理服務 (舊版)

列出 VM

如要查看已設定 OS Inventory Management 的 VM 清單,請執行 instances os-inventory list-instances 指令。

舉例來說,如要列出有庫存資料的所有 VM,請執行下列指令:

gcloud compute instances os-inventory list-instances

輸出結果會與下列內容相似:

  NAME                 ZONE          MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP STATUS
  inventory-instance   us-east1-b    e2-standard-2               192.0.2.1    RUNNING
  instance-inventory1  us-west1-b    e2-standard-2               192.0.2.2    RUNNING
  instance-inventory2  asia-east2-b  e2-standard-2               192.0.2.3    RUNNING
  

您也可以使用篩選器來縮小搜尋結果範圍。舉例來說,您可以執行下列指令,列出已設定 OS Inventory Management,且主機名稱符合規則運算式 instance-* 的所有 VM:

gcloud compute instances os-inventory list-instances
      --inventory-filter="Hostname~instance-*"

輸出結果會與下列內容相似:

  NAME                 ZONE         MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP STATUS
  inventory-instance   us-east1-b   e2-standard-2               192.0.2.1    RUNNING
  instance-inventory1  us-west1-b   e2-standard-2               192.0.2.2    RUNNING
  instance-inventory2  asia-east2-b e2-standard-2               192.0.2.3    RUNNING
  
查看商品目錄資料

如要查看 VM 的庫存資料,請使用 instances os-inventory describe 指令。

如要查看系統針對特定 VM 收集的庫存資料,請執行下列指令:

gcloud compute instances os-inventory describe VM_NAME \
      --zone=ZONE

更改下列內容:

  • VM_NAME:VM 名稱
  • ZONE:VM 所在區域

如要查看該指令傳回的輸出類型詳細資料,請查看 OS Inventory Management 提供的資訊

後續步驟