cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Cisco Community Designated VIP Class of 2020

142
Views
0
Helpful
0
Replies
Beginner

FMC PreFilter via API (fmcapi)

Hi

I'm not a developer but I wan't to automate some tasks for my client.

We have a FMC 6.5.0.2 and I triy to create a PreFilter for all GRE Tunnels. So I downloaded the fmcapi. In general all things work fine. I can create objects and access rules. But if I try to create a PreFilter I get an unkown error.

My Code looks like:

 

# Import FMC API
import fmcapi

# Define config file
cfgfile = 'test.cfg'

# Read the config file for settings
cfg = configparser.ConfigParser()
cfg.read(cfgfile)

# Create FMC object
with fmcapi.FMC(host = cfg['FMC']['host'], username = cfg['FMC']['user'], password = cfg['FMC']['passwd'], autodeploy = False, file_logging = scriptlog)  as mstfmc:

# Create PreFilter Object prefilter_rule = fmcapi.PreFilterRules(fmc=mstfmc, prefilter_name=cfg['FMC']['prefilter']) # Set the PreFilter Values prefilter_rule.name = "Tunnel920" prefilter_rule.enabled = True prefilter_rule.rule_type = "TUNNEL" prefilter_rule.source_interface(action="add", name="inside_muenchenstein") prefilter_rule.destination_interface(action="add", name="outside_muenchenstein") prefilter_rule.action = "FASTPATH" prefilter_rule.destination_port(action="add", literal={"protocol": "47"}) # Post the Values to the FMC prefilter_rule.post(

And the log output looks like:

 

 

2020/01/02-12:12:35 - INFO:fmc.py:436 - Requesting new tokens from https://fmcurl/api/fmc_platform/v1/auth/generatetoken.
2020/01/02-12:12:39 - INFO:fmc.py:166 - Building base to URLs.
2020/01/02-12:12:39 - INFO:serverversion.py:42 - Populating vdbVersion, sruVersion, serverVersion, and geoVersion FMC instance variables.
2020/01/02-12:12:39 - INFO:fmc.py:138 - This FMC's version is 6.5.0.2 (build 57)
2020/01/02-12:12:39 - INFO:prefilterrules.py:115 - Searching ID for prefilter "default_sdag_prefilter"
2020/01/02-12:12:40 - INFO:apiclasstemplate.py:169 - GET success. Object with name: "default_sdag_prefilter" and id: "005056BE-875A-0ed3-0000-012884903880" fetched from FMC.
2020/01/02-12:12:40 - INFO:apiclasstemplate.py:169 - GET success. Object with name: "inside_muenchenstein" and id: "2e2333ea-2b9c-11ea-adf4-be47e6928388" fetched from FMC.
2020/01/02-12:12:41 - INFO:apiclasstemplate.py:169 - GET success. Object with name: "outside_muenchenstein" and id: "21587c74-2b9c-11ea-adf4-be47e6928388" fetched from FMC.
2020/01/02-12:12:49 - ERROR:fmc.py:257 - Error in POST operation --> 400 Client Error: Bad Request for url: https://fmcurl/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/policy/prefilterpolicies/005056BE-875A-0ed3-0000-012884903880/prefilterrules
2020/01/02-12:12:49 - ERROR:fmc.py:258 - json_response -->	{'error': {'category': 'FRAMEWORK', 'messages': [{}], 'severity': 'ERROR'}}
2020/01/02-12:12:49 - WARNING:apiclasstemplate.py:259 - POST failure.  No data in API response.
2020/01/02-12:12:49 - INFO:fmc.py:155 - Auto deploy changes set to False.  Use the Deploy button in FMC to push changes to FTDs.

 

 

Can you help me, how to create a PreFilter Rule like this:

 

PreFilter Example.PNG

 

Thanks a lot for any help.

 

Best Regards,

Daniel

Everyone's tags (3)
CreatePlease to create content
Content for Community-Ad
FusionCharts will render here