Beispiel #1
0
def create_csv_file(csv_file_name,rl_settings):
  print(rl_settings['apiBase'])
  rl_settings = rl_lib_api.rl_jwt_get(rl_settings)
  print(rl_settings)
  rl_settings, response_package = rl_lib_api.alltime_alert_list_get(rl_settings)
  alertdata = response_package['data']
  print(alertdata)
  masterlist=[]
  for each in alertdata:
    list=[]
    list.append(each['status'])
    list.append(each['policy']['name'])
    list.append(each['resource']['name'])
    list.append(each['resource']['accountId'])
    list.append(each['resource']['region'])
    list.append(each['resource']['account'])
    list.append(each['policy']['severity'])
    try:
        each['resource']['id']
    except KeyError:
        list.append('None')
    else:
      list.append(each['resource']['id'])
    try:
        each['id']
    except KeyError:
        list.append('None')
    else:
        list.append(each['id'])
    try:
        each['alertTime']
    except KeyError:
        list.append('None')
    else:
        try:
            formattedtime = datetime.datetime.fromtimestamp(each['alertTime']/1000).strftime('%Y-%m-%d %H:%M:%S')
        except ValueError:
            list.append('None')
        else:
            list.append(formattedtime)
    masterlist.append(list)


  with open(csv_file_name, "w") as f:
  	writer = csv.writer(f)
  	writer.writerow(["Status", "Policy Name", "Resource Name", "Account ID", "Region", "Account Name", "Severity", "Resource ID", "Alert ID", "Alert Time"])
  	writer.writerows(masterlist)
# Verification (override with -y)
if not args.yes:
    print()
    print('Ready to excute commands aginst your Prisma Cloud tenant.')
    verification_response = str(
        input('Would you like to continue (y or yes to continue)?'))
    continue_response = {'yes', 'y'}
    print()
    if verification_response not in continue_response:
        rl_lib_general.rl_exit_error(
            400, 'Verification failed due to user response.  Exiting...')

# Sort out API Login
print('API - Getting authentication token...', end='')
rl_settings = rl_lib_api.rl_jwt_get(rl_settings)
print('Done.')

## Compliance Copy ##
wait_timer = 5
# Check the compliance standard and get the JSON information
print('API - Getting the Compliance Standards list...', end='')
rl_settings, response_package = rl_lib_api.api_compliance_standard_list_get(
    rl_settings)
compliance_standard_list_temp = response_package['data']
compliance_standard_original = search_list_object_lower(
    compliance_standard_list_temp, 'name',
    args.source_compliance_standard_name)
if compliance_standard_original is None:
    rl_lib_general.rl_exit_error(
        400,