注意:
- 本教程需要访问 Oracle Cloud。要注册免费账户,请参阅开始使用 Oracle Cloud Infrastructure 免费套餐。
- 它对 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 将生成问题报告,其中包括问题说明、风险级别、受影响资源等详细信息。
通过使用此脚本,客户可以:
-
对问题数据执行脱机分析。
-
将报告临时上载到安全信息和事件管理 (Security Information and Event Management,SIEM) 解决方案,以增强威胁检测和相关性。
-
与分析仪表盘或其他报告工具集成,以识别模式、趋势和根本原因。
这种方法不仅可以确保运营效率,还可以帮助客户获得更深入的洞察并保持稳健的安全态势。
目标
- 使用 Python 脚本检索 Oracle Cloud Guard 问题报告。
先决条件
-
Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) 中用于查看 Oracle Cloud Guard 的访问权限。有关更多信息,请参见 Enable 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 帮助中心。
Retrieve Oracle Cloud Guard Problem Reports using a Python Script
G23009-01
December 2024