Example #1
0
def post_ac_rules(fmc_info, data):
    #Creating one list of FMC objects and groups for lookups of id and type from name
    fmc_object_list = get_names_and_ids(fmc_info,
                                        constants.OBJECT_NETWORK_ADDRESSES)
    fmc_object_list.extend(
        get_names_and_ids(fmc_info, constants.OBJECT_NETWORK_GROUPS))

    fmc_ac_policy_list = get_names_and_ids(fmc_info, constants.ACCESS_POLICIES)

    with open('Rules.csv', newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            print(row['AcPolicy'], row['name'], row['enabled'], row['type'])
            ac_policy = row['AcPolicy']
            is_policy_found = False
            for policy in fmc_ac_policy_list:
                if policy['name'] == ac_policy:
                    policy_id = policy['id']
                    is_policy_found = True
                    break
            if not is_policy_found:
                logging.error('AC policy not found: %s', ac_policy)
            row.pop('AcPolicy')
            if row['enabled'].lower() == 'true':
                row['enabled'] = True
            else:
                row['enabled'] = False
            print(row)
            logging.debug('Posting: %s', json.dumps(row))
            endpoint = constants.ACCESS_POLICIES + '/' + policy_id + '/' + constants.ACCESS_RULES
            post(fmc_info, endpoint, row)
Example #2
0
def post_network_groups(fmc_info, data):
    #Creating one list of FMC objects and groups for lookups of id and type from name
    fmc_object_list = get_names_and_ids(fmc_info, constants.OBJECT_NETWORK_ADDRESSES)
    fmc_object_list.extend(get_names_and_ids(fmc_info, constants.OBJECT_NETWORK_GROUPS))

    for row in data:
        post_data = {}
        object_name_list = []
        post_data['name'] = row[0]
        post_data['type'] = row[1]
        literals = row[2]
        objects = row[3]
        post_data['literals'] = create_literal_list(literals)
        post_data['objects'] = create_object_list(objects, fmc_object_list)
        logging.debug('Posting: %s', json.dumps(post_data))
        post(fmc_info, constants.OBJECT_NETWORK_GROUPS, post_data)
Example #3
0
def post_ac_rules(fmc_info, data):
    #Creating one list of FMC objects and groups for lookups of id and type from name
    fmc_object_list = get_names_and_ids(fmc_info, constants.OBJECT_NETWORK_ADDRESSES)
    fmc_object_list.extend(get_names_and_ids(fmc_info, constants.OBJECT_NETWORK_GROUPS))

    with open('Rule.csv', newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            print(row['AcPolicy'], row['name'], row['enabled'], row['type'])
            acPolicy = row['AcPolicy']
            row.pop('AcPolicy')
            if row['enabled'].lower() == 'true':
                row['enabled'] = True
            else:
                row['enabled'] = False
            print(row)
            logging.debug('Posting: %s', json.dumps(row))
            post(fmc_info, constants.ACCESS_POLICIES + '/005056A4-5126-0ed3-0000-025769803780/accessrules', row)
Example #4
0
def main():
    logging.basicConfig(filename='application.log', level=logging.DEBUG)
    logging.info('Starting the application.')

    fmc_info = get_fmc_information()
    arguments = get_arguments()
    if 'get' in arguments:
        fmc_endpoint = constants.OBJECT_MAP[arguments['get']]
        print_item_list(get_names_and_ids(fmc_info, endpoint=fmc_endpoint))
    if 'post' in arguments:
        post_from_file(fmc_info, arguments['post'])

    logging.info('Finished execution.')