Oct-16-2024, 03:05 PM
Hi
I'm very new to python
I found a python code on github to get information on crowdstrike but it happens that a value is null: “I think it is null” and it gives me errors, I want to tell it that if the condition is not null to do it otherwise to pass all rights
Here's the code in question
I'm very new to python
I found a python code on github to get information on crowdstrike but it happens that a value is null: “I think it is null” and it gives me errors, I want to tell it that if the condition is not null to do it otherwise to pass all rights
Here's the code in question
while total > 0: response = falcon.command("QueryDevicesByFilterScroll", offset=offset, limit=5000) print("Total Remaining: ",total) total = total - 5000 offset = response["body"]["meta"]["pagination"]["offset"] detail_response = falcon.command("GetDeviceDetails", ids=response["body"]["resources"]) for detail in detail_response["body"]["resources"]: hostname = get_detail(detail, "hostname") last_seen = get_detail(detail, "last_seen") first_seen = get_detail(detail, "first_seen") platform = get_detail(detail, "platform_name") os_version = get_detail(detail, "os_version") os_build = get_detail(detail, "os_build") os_product_name = get_detail(detail, "os_product_name") kernel_version = get_detail(detail, "kernel_version") model = get_detail(detail, "system_product_name").replace(",", " ") manufacturer = get_detail(detail, "system_manufacturer").replace(",", " ") type = get_detail(detail, "product_type_desc") chassis = get_detail(detail, "chassis_type_desc") #policy_id = detail['device_policies']['prevention']['policy_id'] last_reboot = get_detail(detail, "last_reboot") [b]if "device_policies" in detail and ['device_policies']['prevention']['policy_id'] in detail != None:[/b] prevention_policy = detail['device_policies']['prevention']['policy_id'] response_policy = detail['device_policies']['remote_response']['policy_id'] sensor_update_policy = detail['device_policies']['sensor_update']['policy_id'] if "usb_storage_control" in detail['device_policies']: usb_device_policy = detail['device_policies']['usb_storage_control']['policy_id'] else: usb_device_policy = "Not Found" else: prevention_policy = "Not Found" response_policy = "Not Found" sensor_update_policy = "Not Found" usb_device_policy = "Not Found" host_id = get_detail(detail, "device_id") mac_address = get_detail(detail, "mac_address") connection_mac_address = get_detail(detail, "connection_mac_address") status = get_detail(detail, "status") cpuid = get_detail(detail, "cpu_signature") serial_number = get_detail(detail, "serial_number") sensor_version = get_detail(detail, "agent_version") sensor_tags = (str(get_detail(detail, "tags")).replace(",", ";")) file_object.write(hostname+","+last_seen+","+first_seen+","+platform+","+os_version+","+os_build+","+os_product_name+","+kernel_version+","+model+","+manufacturer+","+type+","+chassis+","+last_reboot+","+prevention_policy+","+response_policy+","+sensor_update_policy+","+usb_device_policy+","+host_id+","+mac_address+","+connection_mac_address+","+status+","+cpuid+","+serial_number+","+sensor_version+","+sensor_tags+"\n")and here the error
Error:Exception has occurred: TypeError
list indices must be integers or slices, not str
File "C:\temp\python\scripts\hosts_report.py", line 98, in <module>
if "device_policies" in detail and ['device_policies']['prevention']['policy_id'] in detail != None:
I try to put into variable but the same append to the variableError:NameError("name 'policy_id' is not defined")