附註:
- 此教學課程需要存取 Oracle Cloud。若要註冊免費帳戶,請參閱 Oracle Cloud Infrastructure Free Tier 入門。
- 它使用 Oracle Cloud Infrastructure 證明資料、租用戶及區間的範例值。完成實驗室時,請將這些值取代為您雲端環境特定的值。
將 Oracle Cloud Guard 事件擷取至 Oracle Analytics Cloud
簡介
本教學課程逐步介紹如何將 Oracle Cloud Guard 事件轉送至 Oracle Autonomous JSON Database (AJD) 並在 Oracle Analytics Cloud 中擷取這些事件。我們將提供後續教學課程,以分析及顯示 Oracle Analytics Cloud 中的雲端保全活動。
-
Oracle Cloud Guard:Oracle Cloud Guard 是一項原生 Oracle Cloud Infrastructure (OCI) 服務,可協助客戶監控及偵測跨區域的資源,進而維持雲端安全狀態,確保 OCI 租用戶的安全。如需詳細資訊,請參閱 Oracle Cloud Guard 。
-
Oracle Analytics Cloud:Oracle Analytics Cloud 是一個完全受管理的雲端商業智慧 (BI) 和分析平台,其設計作為一個完整的平台,可讓業務使用者和分析師發掘洞察和趨勢,以做出資料導向的決策。如需詳細資訊,請參閱 Oracle Analytics Cloud 。
高層級架構
目標
- 將 Oracle Cloud Guard 事件擷取至 Oracle Analytics Cloud。
必要條件
-
深入瞭解 OCI、OCI Events Service 和 Oracle Cloud Guard。
-
佈建 Oracle Autonomous Database 和 Oracle REST Data Services (ORDS) 的知識。
-
OCI 函數和安全性的基本知識。
作業 1:設定 Oracle Cloud Guard 以觸發雲端事件
設定 Oracle Cloud Guard 以回應偵測器處方。回應器規則應確定 Oracle Cloud Guard 事件的狀態已設為已啟用,如下列影像所示。
作業 2:建立 OCI 事件服務規則以偵測 Oracle Cloud Guard 問題並呼叫 OCI 函數
-
OCI 事件服務可讓您根據整個租用戶的資源狀態變更建立自動化。透過使用事件,開發團隊可以在資源變更其狀態時自動回應。
若要取得事件,請瀏覽至可觀察性與管理,然後按一下事件服務。建立新規則並設定將寫入函數的事件類型,如下圖所示。
-
按一下省略符號圖示 (三個垂直點) 即可編輯 Oracle Cloud Guard 事件,並將其傳送到函數,如下列影像所示。
新增動作以將雲端保全事件轉送至函數,如下所示。
設定事件類型。
作業 3:建立將事件轉送至 AJD 的函數
-
前往 OCI 主控台,瀏覽至開發人員服務,然後按一下函數。
-
選取現有的應用程式,或按一下建立應用程式。在您的應用程式內建立新的 OCI 函數。如需詳細資訊,請參閱 Cloud Shell 上的 Functions QuickStart 。
注意:假設您已順利完成先決條件。
-
執行下列命令,在應用程式清單中查看您的應用程式。
fn ls apps
-
建議先建立樣板 Python 函數。
fn init – runtime oci-event-to-db
命令將產生名為oci-event-to-db
的資料夾,其中包含三個名為func.py
、func.yaml
及requirements.txt
的檔案。 -
AJD 表格必須存在且已啟用 REST。如下圖所示。
-
使用下列程式碼更新
func.py
檔案內容。import io import json import re import requests eventTable="https://mrj6p3vkk4ramuu-cgdata.adb.us-ashburn-1.oraclecloudapps.com/ords/cguser/event/" from fdk import response def handler(ctx, data: io.BytesIO=None): try: bodytxt = data.getvalue() body = json.loads(bodytxt) # print("event type: " + body["eventType"]) # print("compartment name: " + body["data"]["compartmentName"]) headers = {'Content-type': 'application/json', 'accept': 'application/json'} req = requests.post(eventTable, json={ "event": body }, headers=headers) except (Exception, ValueError) as ex: print('ERROR:', ex, flush=True) raise return response.Response( ctx, response_data=[ json.loads(req.text)["id"] ], # response_data=json.loads(req.text), headers={"Content-Type": "application/json"} )
-
使用下列程式碼更新
func.yaml
檔案內容。schema_version: 20180708 name: oci-event-to-db version: 0.0.44 runtime: python build_image: fnproject/python:3.11-dev run_image: fnproject/python:3.11 entrypoint: /python/bin/fdk /function/func.py handler memory: 256
-
使用下列程式碼更新
requirements.txt
檔案內容。Requests oci fdk
-
執行下列命令以部署您的函數。
fn -v deploy -app oci-event-to-db
作業 4:使用 ORDS 將資料庫展開
-
將 Oracle Cloud Guard 事件儲存在 AJD 之後,請檢查事件表格,查看 Oracle Cloud Guard 活動的資料庫。執行下列 SQL 敘述句。
SELECT * FROM EVENTS
-
由於 Oracle Cloud Guard 事件是以 Java Script Object Notation (JSON) 格式儲存,因此必須將它扁平化或轉換成關聯式格式,Oracle Analytics Cloud 才能分析資料。
若要均一化資料庫,請依照下列步驟進行:
-
在 Events 表格上建立索引,並執行下列 SQL 陳述式加以均一化。
Create search index event_idx on event (event) for JSON parameters ('DATAGUIDE ON');
-
建立檢視。
exec dbms_json.create_view_on_path('flat_event', 'event', 'event', '$’);
-
-
執行下列 SQL 敘述句,檢查在上述步驟中建立的資料欄。
SELECT COLUMN_NAME,DATA_TYPE FROM all_tab_columns where table_name ='FLAT_EVENT' order BY column_id;
您應該會看到資料欄以及資料類型,如下圖所示。
作業 5:連線至 Oracle Analytics Cloud
-
資料庫從 JSON 轉換成關聯式格式之後,請連線至 Oracle Analytics Cloud。前往 OCI 主控台並瀏覽至 AJD 執行處理,按一下資料庫連線即可提供證明資料並下載公事包,如以下影像所示。
-
登入 Oracle Analytics Cloud,按一下建立新連線,然後按一下 Oracle Autonomous Data Warehouse ,然後選取在步驟 1 中下載的公事包。
-
建立連線之後,OAC 會在「連線」底下顯示,如下所示。
-
按兩下連線以在 OAC 中建立新資料集,展開綱要並拖曳表格至工作區。
認可
-
作者 - Murtuza Madarwala (雲端解決方案工程師),Phil Dolbow (雲端解決方案工程師)
-
貢獻者 - Kevin Colwell (雲端解決方案工程師)
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Capture Oracle Cloud Guard Events into Oracle Analytics Cloud
G27477-01
February 2025
Copyright ©2025, Oracle and/or its affiliates.