marksull / fmcapi

A Python package designed to help users of Cisco's FMC interface with its API.
BSD 3-Clause "New" or "Revised" License
81 stars 57 forks source link

Audit documentation use case #46

Closed asrebroski closed 5 years ago

asrebroski commented 5 years ago

I am attempting to use the fmcapi to audit an FMC environment, specifically a way to programmatically output access control policy data in to a document. Is this a feasible use case and if so could you provide a code snippet to help me along?

marksull commented 5 years ago
from fmcapi import FMC
from fmcapi.api_objects import AccessPolicies, AccessRules

with FMC(
        host="hostname",
        username="username",
        password="password",
        limit=1000,
        autodeploy=False,
) as fmc_session:
    policy = AccessPolicies(fmc=fmc_session).get(name="name_of_the_policy")

    if not policy:
        print("Policy could not be found")
    else:
        rules = AccessRules(fmc=fmc_session).get(acp_id=policy["id"])

        if not rules:
            print("Rules could not be loaded")
        else:
            for rule in rules["items"]:
                print(f"Name: {rule['name']}: Dict: {rule}")
marksull commented 5 years ago

did that help @asrebroski ?

asrebroski commented 5 years ago

yes! Thank you so much. I very much appreciate it.