使用 API 來收集 伺服器與工作負載保護 所保護電腦的安全狀態資訊。例如,若要建立每月的安全狀態報告,您需要收集有關安全模組的資訊,例如它們的運行狀態(開啟或關閉),以及是否已分配最新的規則。
您還可以發現您是否受到特定安全威脅的保護。例如,當針對零日弱點發布CVE時,您可以找到該CVE的入侵防護規則並將其應用到您的電腦上。
發現未受保護的電腦
根據代理程式或設備的即時狀態,或根據保護模組的狀態,發現未受保護的電腦:
- 電腦防護未安裝代理程式或設備,或代理程式或設備未啟動
- 保護模組未開啟,或已開啟但未啟動
對於虛擬機,您還可以獲取機器狀態和其他資訊,這對疑難排解很有幫助。
如需有關電腦防護狀態的背景資訊,請參閱 電腦防護和代理程式狀態
根據代理狀態查找電腦
未安裝代理程式的電腦不受 伺服器與工作負載保護 保護。當代理程式或設備出現問題時,電腦也可能不受保護。
要確定代理程式或設備是否已安裝,請檢查代理程式和設備的指紋。沒有指紋表示未安裝代理程式或設備,因此電腦防護未啟用。當代理程式或設備已安裝時,也請檢查其狀態。例如,狀態為
active表示代理程式或設備運行正常。其他狀態,如error或inactive,表示存在問題,您應該進行調查。以下範例 JSON 代表電腦防護物件的資料結構(為了使範例更簡潔,省略了一些項目)。
agentFingerPrint 顯示已安裝代理程式,computerStatus 顯示其為啟用狀態。{
"hostName": "laptop_adaggs",
...
"policyID": 34,
"agentFingerPrint": "71:3E:81:64:65:EB:34:78:FC:72:C2:CB:37:6B:1D:F0:8C:D1:9B:1E",
"agentVersion": "11.3.2.883",
"computerStatus": {
"agentStatus": "active",
"agentStatusMessages": [
"Managed (Online)"
]
},
"computerSettings": {...},
"ID": 48,
"antiMalware": {...},
...
}
秘訣離線狀態可能表示伺服器與工作負載保護無法與電腦防護進行通信。在此狀態下,代理或設備可以正常運行並提供保護。然而,伺服器與工作負載保護無法將組件更新發送到代理或設備。 |
使用以下一般程序來發現未受保護的電腦:
步驟
- 使用
ComputersApi來獲取電腦防護物件。 - 檢查電腦防護的
AgentFingerPrint和ApplianceFingerPrint屬性。 - 從
電腦防護物件中獲取ComputerStatus物件,並檢查AgentStatus屬性。任何值不是ACTIVE都可能表示有問題。 - 可選擇性地獲取
AgentStatusMessages物件的ComputerStatus和Computer物件的AgentTasks屬性以獲取有用資訊。
後續步驟
秘訣由於電腦的
computerStatus 欄位的值是一個物件 (ComputerStatus),因此您無法在此欄位上進行搜尋。 |
要檢查所有電腦的狀態,首先使用
ComputersApi類別列出所有電腦:computers_api = api.ComputersApi(api.ApiClient(configuration)) computers = computers_api.list_computers(api_version, expand=expand.list(), overrides=False)
對於每台電腦防護,檢查代理程式和設備指紋。沒有指紋表示沒有安裝代理程式或設備,且電腦防護未受保護。請注意,一台電腦防護可以同時安裝代理程式和設備。您需要檢查兩個指紋的值。
if computer.agent_finger_print == None and computer.appliance_finger_print == None:
如果發現指紋,請獲取代理或設備狀態以確定其是否處於活動狀態。任何非活動狀態都可能表示代理或設備存在問題。
agent_status = computer.computer_status.agent_status
if computer.agent_finger_print != None and agent_status != "active":
...
appliance_status = computer.computer_status.appliance_status
if computer.appliance_finger_print != None and appliance_status != "active":
...
當狀態不活動時,獲取代理或設備的狀態訊息和任務。以下範例顯示如何獲取代理的資訊。
if computer.computer_status.agent_status_messages != None:
computer_info.append(str(computer.computer_status.agent_status_messages))
else:
computer_info.append("")
if computer.tasks != None:
computer_info.append(str(computer.tasks.agent_tasks))
else:
computer_info.append("")
以下範例會找到未安裝代理程式或設備的電腦,或代理程式和/或設備的狀態不活躍。在完整的源代碼範例中,結果會以可保存為 CSV 檔案的格式編譯,以便作為試算表打開。
# Include computer status information in the returned Computer objects
expand = api.Expand(api.Expand.computer_status)
# Get all computers
computers_api = api.ComputersApi(api.ApiClient(configuration))
computers = computers_api.list_computers(api_version, expand=expand.list(), overrides=False)
for computer in computers.computers:
computer_info = []
# Report on computers with no agent or appliance
if computer.agent_finger_print is None and computer.appliance_finger_print is None:
# Hostname and protection type
computer_info.append(computer.host_name)
computer_info.append("None")
# Agent/appliance status and status messages
computer_info.append("No agent/appliance")
status_messages = ""
if computer.computer_status is not None and computer.computer_status.agent_status is not None:
status_messages = str(computer.computer_status.agent_status_messages)
computer_info.append(status_messages)
else:
# Report on problem agents and appliances
agent_status = computer.computer_status.agent_status
appliance_status = computer.computer_status.appliance_status
# Agent is installed but is not active
if computer.agent_finger_print is not None and agent_status != "active":
# Hostname and protection type
computer_info.append(computer.host_name)
computer_info.append("Agent")
# Agent status, status messages, and tasks
if computer.computer_status.agent_status is not None:
computer_info.append(computer.computer_status.agent_status)
else:
computer_info.append("")
if computer.computer_status.agent_status_messages is not None:
computer_info.append(str(computer.computer_status.agent_status_messages))
else:
computer_info.append("")
if computer.tasks is not None:
computer_info.append(str(computer.tasks.agent_tasks))
else:
computer_info.append("")
# Appliance is installed but is not active
if computer.appliance_finger_print is not None and appliance_status != "active":
# Hostname and protection type
computer_info.append(computer.host_name)
computer_info.append("Appliance")
# Appliance status, status messages, and tasks
if computer.computer_status.appliance_status is not None:
computer_info.append(computer.computer_status.appliance_status)
else:
computer_info.append("")
if computer.computer_status.appliance_status_messages is not None:
computer_info.append(str(computer.computer_status.appliance_status_messages))
else:
computer_info.append("")
if computer.tasks is not None:
computer_info.append(str(computer.tasks.appliance_tasks))
else:
computer_info.append("")
根據模組狀態查找電腦
當保護模組關閉或問題阻止代理程式或設備正確運行模組時,電腦防護會變得脆弱。要檢查電腦防護是否受到保護模組的保護,請檢查模組狀態(開啟或關閉)。當狀態為開啟時,還需檢查模組狀態,這表示代理程式和/或設備運行模組的能力。任何狀態不是
active都可能表示需要您注意的問題。您還可以獲取狀態訊息,以深入了解狀態。以下範例 JSON 代表電腦防護物件的資料結構(為了使範例更簡潔,省略了一些項目)。惡意程式防護模組是
開啟的,但該模組的代理狀態顯示警告。{
"hostName": "192.168.60.128",
...
"policyID": 9,
"agentFingerPrint": "76:C8:CE:B3:70:61:A3:BE:84:A2:2A:5D:1F:3A:29:8A:DC:7A:70:6C",
"agentVersion": "11.2.0.147",
"computerStatus": {...},
"computerSettings": {...},
...
"ID": 2,
"antiMalware": {
"state": "on",
"moduleStatus": {
"agentStatus": "warning",
"agentStatusMessage": "Software Update: Anti-Malware Module Installation Failed"
},
"realTimeScanConfigurationID": 1,
"realTimeScanScheduleID": 4,
"manualScanConfigurationID": 2,
"scheduledScanConfigurationID": 3
},
"webReputation": {...},
"firewall": {...},
"intrusionPrevention": {...},
"integrityMonitoring": {...},
"logInspection": {...},
"applicationControl": {...}
}
使用以下一般程序來使用模組狀態發現未受保護的電腦:
步驟
- 使用
ComputersApi來獲取電腦防護物件。 - 獲取您感興趣的防護模組的電腦防護擴展對象,例如
AntiMalwareComputerExtension或IntrusonPreventionComputerExtension。 - 從電腦防護擴展物件中,獲取模組狀態的值以查看模組是開啟還是關閉。
- 同樣從電腦防護擴展對象中,獲取
ModuleStatus對象,並獲取代理和設備狀態及狀態消息。
後續步驟
秘訣由於電腦防護擴展的
moduleStatus 欄位的值是一個物件 (ModuleStatus),因此您無法在此欄位上進行搜尋。 |
要檢查所有電腦的模組狀態,首先使用
ComputersApi 類別來列出所有電腦:computers_api = api.ComputersApi(api.ApiClient(configuration)) computers = computers_api.list_computers(api_version, expand=expand.list(), overrides=False)
對於每台電腦防護,獲取您感興趣的保護模組的代理狀態。獲取模組狀態,然後檢查其代理或設備狀態。任何非活動狀態都可能表示代理或設備存在問題。請注意,如果未安裝代理,則沒有代理狀態。同樣,如果未安裝設備,則沒有設備狀態。
if computer.anti_malware.module_status:
agent_status = computer.anti_malware.module_status.agent_status
appliance_status = computer.anti_malware.module_status.appliance_status
else:
agent_status = None
appliance_status = None
if agent_status and agent_status != "active":
...
if appliance_status and appliance_status != "active":
...
對於非活動狀態,獲取模組的代理或設備狀態訊息:
module_info.append(computer.anti_malware.module_status.agent_status_message)
module_info.append(computer.anti_malware.module_status.appliance_status_message)
以下範例會找到已關閉惡意程式防護模組或模組狀態未啟用的電腦。在完整的源代碼範例中,結果會以可儲存為 CSV 檔案的格式返回,以便作為試算表打開。
computers_api = api.ComputersApi(api.ApiClient(configuration))
computers = computers_api.list_computers(api_version, expand=expand.list(), overrides=False)
# Get the list of computers and iterate over it
for computer in computers.computers:
# Module information to add to the CSV string
module_info = []
# Check that the computer has a an agent or appliance status
if computer.anti_malware.module_status:
agent_status = computer.anti_malware.module_status.agent_status
appliance_status = computer.anti_malware.module_status.appliance_status
else:
agent_status = None
appliance_status = None
# Agents that are not active for the module
if agent_status and agent_status != "active":
# Host name
module_info.append(computer.host_name)
# Module state
module_info.append(computer.anti_malware.state)
# Agent status and status message
module_info.append("Agent")
module_info.append(agent_status)
module_info.append(computer.anti_malware.module_status.agent_status_message)
# Appliances that are not active for the module
if appliance_status and appliance_status != "active":
# Host name
module_info.append(computer.host_name)
# Module state
module_info.append(computer.anti_malware.state)
# Appliance status and status message
module_info.append("Appliance")
module_info.append(appliance_status)
module_info.append(computer.anti_malware.module_status.appliance_status_message)
查看虛擬機的狀態
當電腦防護是虛擬機器時,您可以獲取虛擬機器的多個屬性,包括狀態(由虛擬機器供應商定義)。
Computer 類提供對多個虛擬機器摘要物件的訪問,例如 azureARMVirtualMachineSummary、ec2VirtualMachineSummary 和 vmwareVMVirtualMachineSummary。(完整列表請參見 API 參考。)您可以獲取電腦防護的虛擬機摘要,並使用它來檢查虛擬機的屬性,例如狀態。
取得電腦防護配置
電腦防護 物件包含電腦的配置資訊。要獲取 電腦防護 物件,請建立一個 ComputersApi 物件,然後通過 ID 獲取特定電腦,按其他屬性搜尋,或列出所有電腦並逐一遍歷。
秘訣當您獲取電腦防護時,您可以選擇是否包含所有屬性或僅包含在該電腦防護上設定的覆蓋屬性:
|
要存取電腦防護的當前配置,您可以使用
Computer 物件來獲取保護模組的電腦擴展物件。例如,要獲取有關電腦的惡意程式防護配置或狀態的信息,您可以獲取 AntiMalwareComputerExtension 物件。使用 expand 參數來檢索您所需的電腦信息。# Include Anti-Malware information in the returned Computer object
expand = api.Expand(api.Expand.anti_malware, api.Expand.computer_settings)
# Get the computer object from 伺服器與工作負載保護
computers_api = api.ComputersApi(api.ApiClient(configuration))
computer = computers_api.describe_computer(computer_id, api_version, expand=expand.list(), overrides=False)
# Get the Anti-Malware scan configuration id for the computer
real_time_scan_configuration_id = computer.anti_malware.real_time_scan_configuration_id
# Get the Anti-Malware properties for the computer
am_configs_api = api.AntiMalwareConfigurationsApi(api.ApiClient(configuration))
return am_configs_api.describe_anti_malware(real_time_scan_configuration_id, api_version)
發現電腦防護的惡意程式防護設定
AntiMalwareComputerExtension 物件提供對電腦防護的惡意程式防護配置中以下項目的存取:- 惡意程式防護模組運行狀態(開啟或關閉)
- 惡意程式掃瞄設定
請使用以下一般步驟來獲取您電腦的惡意程式防護配置:
步驟
- 使用
ComputersApi物件來獲取電腦防護物件。 - 使用
電腦防護物件來獲取AntiMalwareComputerExtension物件。 - 獲取惡意程式防護模組狀態。
- 取得掃瞄配置。
後續步驟
以下範例取得電腦防護的惡意程式防護配置的某些屬性
# Get the anti-malware scan configuration id for the computer real_time_scan_configuration_id = computer.anti_malware.real_time_scan_configuration_id # Get the anti-malware properties for the computer am_configs_api = api.AntiMalwareConfigurationsApi(api.ApiClient(configuration)) return am_configs_api.describe_anti_malware(real_time_scan_configuration_id, api_version)
取得已套用的入侵防護規則
確定應用於您電腦的入侵防護規則,以確保所需的保護措施到位。
步驟
- 使用
ComputersApi物件來獲取電腦防護物件。 - 對於每個
電腦防護對象,獲取IntrusionPreventionComputerExtension對象。 - 獲取入侵防護規則列表。
後續步驟
以下範例檢索應用於電腦的入侵防護規則。
# Extract intrusion prevention rules from the computers
im_rules = {}
for computer in computers_list.computers:
im_rules[computer.host_name] = computer.intrusion_prevention.rule_ids
return im_rules
