def dumptofile(f):
    # Authenticate with FMC
    access_token, domain_uuid = fmc_authenticate()

    output = fmc_get("devices/devicerecords")
    # So get the number of items in the list. I figure that this will be the number of sensors

    for i in range(len(output['items'])):
        #    print(output['items'][i-1]['id'])
        containerUUID.append(output['items'][i - 1]['id'])
    for i in containerUUID:
        output = fmc_get("devices/devicerecords/" + i +
                         "/routing/ipv4staticroutes")
        #print(output['items'][0]['id'])
        #print(len(output['items']))
        for i in range(len(output['items'])):
            objectid.append(output['items'][i - 1]['id'])

    for i in range(len(containerUUID)):
        for j in range(len(objectid)):
            output = "ContainerUUID " + containerUUID[
                i - 1] + " objectID " + objectid[j - 1]

    for i in containerUUID:
        for j in objectid:
            getRoutes(i, j, f)
Beispiel #2
0
def do_something(incoming_msg):
    """
    Sample function to do some action.
    :param incoming_msg: The incoming message object from Teams
    :return: A text or markdown based reply
    """
    guest_user = quick_guest(name)
    gu = guest_user.split(',')
    usr = gu[0].split(':')
    user = usr[1].replace('"', '')
    pswd = gu[1].split(':')
    passwd = pswd[1].replace('"', '')
    password = passwd.replace('}', '')
    fmc_policy = 0
    fmc_authenticate()
    test_fmc = fmc_get('policy/accesspolicies')
    for item in test_fmc['items']:
        if item['name'] == config['FMC']['POLICY_NAME']:
            fmc_policy = 1

    if fmc_policy == 0:
        os.system('python3 fmc_create_access_policy.py')
        os.system('rm *.log')
        return "I did what you said - {}".format(
            incoming_msg.text
        ) + "\n Username: "******"\nPassword: "******"I did what you said - {}".format(
            incoming_msg.text
        ) + "\n Username: "******"\nPassword: " + password
def getRoutes(containerUUID, objectid, f):
    #access_token, domain_uuid = fmc_authenticate()
    output = fmc_get("devices/devicerecords/" + containerUUID +
                     "/routing/ipv4staticroutes/" + objectid)
    myoutput = dict(itertools.islice(output.items(), 2, None))
    #print(str(myoutput).replace("'", '"').replace('"overridable": False,', ''))
    f.write(
        str(myoutput).replace("'", '"').replace(
            '"overridable": False,', '').replace('"isTunneled": False,', '') +
        "\n")
sys.path.insert(0, str(here))
import os
import configparser
from fmc_requests import fmc_authenticate, fmc_get, fmc_delete  # noqa

config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), 'volume', 'config.cfg'))

# Authenticate with FMC
fmc_authenticate()


# Get the configured access policies
print(blue("\n==> Retrieving the configured access policies"))

configured_policies = fmc_get("policy/accesspolicies")

print(
    green("Successfully retrieved the list of configured access policies"),
    f"Retrieved {len(configured_policies['items'])} policies",
    sep="\n"
)


# Look for a policy named "DNE Security Access Control Policy"
print(blue("\n==> Looking for the 'DNE Security Access Control Policy'"))

for policy in configured_policies["items"]:
    if policy["name"] == config['FMC']['POLICY_NAME']:
        print("Policy found")
Beispiel #5
0
# Authenticate with FMC
fmc_authenticate()


# Create an Access Policy
print(blue("\n==> Creating a new Access Policy on FMC"))

access_policy = {
    "type": "AccessPolicy",
    "name": config['FMC']['POLICY_NAME'],
    "description":"DevNet Race policy",
    "defaultAction":{"action": "BLOCK"},
}
created_policy = ''
policy_exist = ''
policycheck = fmc_get("policy/accesspolicies")
for item in policycheck['items']:
    if item['name'] == config['FMC']['POLICY_NAME']:
      policy_exist = item['name']
      policy_id = item['id']
      created_policy == fmc_get("policy/accesspolicies")['items']
            

if policy_exist == '':      
  created_policy = fmc_post("policy/accesspolicies", access_policy)

policy = fmc_get("policy/accesspolicies")
policy_id = ''
IN_zone_id = ''
OU_zone_id = ''
for item in policy['items']:
Beispiel #6
0
import sys

# Locate the directory containing this file and the repository root.
# Temporarily add these directories to the system path so that we can import
# local files.
here = os.path.abspath(os.path.dirname(__file__))
repository_root = os.path.abspath(os.path.join(here, ".."))
sys.path.insert(0, repository_root)
sys.path.insert(0, here)

from fmc_requests import fmc_authenticate, fmc_get, fmc_delete  # noqa

# Authenticate with FMC
fmc_authenticate()

# Get the configured access policies
configured_policies = fmc_get("policy/accesspolicies")

# Look for a policy named `DNE Security Access Control Policy`
for policy in configured_policies["items"]:
    if policy["name"] == "DNE Security Access Control Policy":
        print("Policy `DNE Security Access Control Policy` found; deleting")
        deleted_policy = fmc_delete("policy/accesspolicies/{}".format(
            policy["id"]))
        print("Policy deleted")
        break

else:
    print("The `DNE Security Access Control Policy` doesn't exist; "
          "you are good to go!")