附註:
- 此教學課程需要存取 Oracle Cloud。若要註冊免費帳戶,請參閱 Oracle Cloud Infrastructure Free Tier 入門。
- 它使用 Oracle Cloud Infrastructure 證明資料、租用戶及區間的範例值。完成實驗室時,請將這些值取代為您雲端環境特定的值。
使用 Python 命令檔擷取 Oracle Cloud Guard 問題報表
簡介
隨著組織越來越將關鍵工作負載移轉至雲端,保護雲端基礎架構變得至關重要。Oracle Cloud Infrastructure (OCI) 提供一組全方位的安全服務來保護雲端環境,而 OCI 安全套件中的其中一個主要工具是 Oracle Cloud Guard。
Oracle Cloud Guard 提供對安全狀態、威脅偵測、漏洞管理和合規檢查的即時可見性,協助企業保護其 OCI 資源。Oracle Cloud Guard 的主要功能是產生問題報告的能力,這對於想要維持健全安全態勢的組織來說極為重要。
Oracle Cloud Guard 主控台目前不支援直接匯出問題報表。本教學課程提供 Python 命令檔,以 JSON 和 CSV 格式產生及下載這些報表。偵測到問題之後,Oracle Cloud Guard 便會產生一個問題報告,其中包含問題描述、風險等級、受影響的資源等詳細資訊。
透過使用此指令檔,客戶可以:
-
執行問題資料的離線分析。
-
特定上傳報告至安全資訊和事件管理 (SIEM) 解決方案,以增強威脅偵測和關聯性。
-
與分析儀表板或其他報表工具整合,以識別模式、趨勢及根本原因。
此方法不僅可確保營運效率,還能讓客戶獲得更深入的洞察力並維持健全的安全態勢。
目標
- 使用 Python 命令檔擷取 Oracle Cloud Guard 問題報表。
必要條件
-
存取 Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) 中的權限,以檢視 Oracle Cloud Guard。如需詳細資訊,請參閱啟用 Oracle Cloud Guard 。
-
存取 OCI Cloud Shell。如需詳細資訊,請參閱 OCI Cloud Shell 的必要 IAM 原則。
在 OCI Cloud Shell 中執行 Python 命令檔
-
登入 OCI 主控台。
-
按一下 Cloud Shell 以開啟 OCI Cloud Shell。
-
複製下列 Python 命令檔並將其儲存為
report.py
,以在 OCI Cloud Shell 中執行。import oci from datetime import datetime import json import csv config = oci.config.from_file() #print(config['tenancy']) #today = datetime.today() #print("Current date: ") #print(today) #firstdate = (today - timedelta(days=180)) #print("Time first detected is: ") #print(firstdate) cloud_guard_client = oci.cloud_guard.CloudGuardClient(config) list_problems_response = cloud_guard_client.list_problems( compartment_id=config['tenancy'], compartment_id_in_subtree=True, access_level="ACCESSIBLE", #time_first_detected_greater_than_or_equal_to=firstdate, limit=1000000) response = list_problems_response.data #print(response) string = str(response) res_data = json.loads(string) output_file = "problem_report.json" with open(output_file, 'w') as json_file: json.dump(res_data, json_file) with open('problem_report.json') as json_file: data = json.load(json_file) prob_data = data['items'] csv_file = open("problem_report.csv", "w", newline="") csv_writer = csv.writer(csv_file) count = 0 for res in prob_data: if count == 0: # Writing headers of CSV file header = res.keys() csv_writer.writerow(header) count += 1 # Writing data of CSV file csv_writer.writerow(res.values()) print("Script executed successfully") print("\nReports are generated and saved")
-
按一下設定值圖示並按一下上傳,即可從本機機器上傳 Python 命令檔檔案。
-
請使用下列命令執行 Python 命令檔。
python3 report.py
-
順利執行之後,您可以看到在名為
problem_report.json
和problem_report.csv
的資料夾中建立的兩個檔案。 -
若要下載報表,請按一下設定值圖示並下載。輸入報表的路徑和檔案名稱。
注意:命令檔將會執行並提供顯示過去 180 天發生之問題的報表。這會在根區間中執行。可見的子區間設為 true,會周遊區間階層並傳回租用戶中的所有區間和子區間。
接下來的步驟
對於使用 OCI 的組織而言,運用 Oracle Cloud Guard 問題報告應該是雲端安全策略不可或缺的一部分。定期檢閱並處理這些報告,可協助您保護 OCI 資源、確保符合規範,並保持客戶和利益相關者的信任。
相關連結
認可
- 作者 - Samratha S P (雲端資深工程師)
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Retrieve Oracle Cloud Guard Problem Reports using a Python Script
G23010-01
December 2024