A Python package designed to help users of Cisco's FMC interface with its API.

Overview

FMCAPI was originally developed by Dax Mickelson ([email protected]). Dax has moved on to other projects but has kindly transferred the ownership of this repo so that we can keep it current!

fmcapi

Provide an "easier to use" way of interacting with the Cisco FMC's API. There is a LOT that has yet to be done in order to make this project have "feature parity" with all that can be done with the FMC's API. That said, what is here works!

The fmcapi is published to PyPI. This means you can install it via pip (pip3 install fmcapi)

Features

  • Creation and maintenance of the connection with the FMC. This basically is care and feeding of the token.
  • Register devices with FMC.
  • Deploy changes to FMC managed devices.
  • Can access API REST methods for:
    • Host Objects
    • Network Objects
    • Range Objects
    • Port Objects
    • ICMPv4/ICMPv6 Objects
    • Security Zones Objects
    • Interface Group Objects
    • URL Objects
    • FQDNS Objects
    • IKEv1/IKEv1 IPsec Proposal and Policy Objects
    • DNS Server Groups
    • Access Control Policy (ACP)
    • ACP Rules
    • VLAN Tags
    • Devices/Device Groups/Device HA
    • FTD Device Interfaces
    • IPv4/IPv6 Static Routes
    • NAT Policy
    • and many more! (74 total by my last count.)
  • There is a "dry_run" feature where you can issue a get(), put(), post(), or delete() method call and, where supported you'll get output of what "would" have been sent to the FMC instead of actually issuing that method call. This is good for troubleshooting your scripts.
  • There is a 'show_json' method available to all fmcapi Classes that will just output the formatted data that is know in that instantiated class.

This is now an installable Python package via pip! I'm heavily developing this code so you might want to issue the command pip3 install -U fmcapi to update your installed version.

Quickstart on how to use this package

First install it with: pip3 install fmcapi Then to use the code best start a "with" statement that creates an instance of the FMC class like this: with fmcapi.FMC(host='192.168.11.15', username='admin', password='Admin123', autodeploy=False) as fmc:
Then either code away referencing the fmc variable to get to the internal methods of the FMC class or utilize the various class objects to ease your coding needs.

Building out an example network is in the "example" directory. This isn't fully completed but it should help you get an idea of what is possible.

I recorded a quick "howto" video which can be accessed via: (This is outdated and I need to make new videos.) https://www.youtube.com/watch?v=4NIe3T-HjDw

Using in the Docker container

There is a Docker image stored on DockerHub (dmickels/fmcapi) you can use to create Docker containers with. The syntax is as follows: docker run -i --name fmcapi --rm --name fmcapi -v 'local directory with scripts':/usr/src/app dmickels/fmcapi:latest

Notes

  • 1: Check out the example directory's scripts for ideas on how to use fmcapi.
  • 2: A lot of work has gone into making fmcapi easier to use and to develop on. Doing this has forced us to issue a deprecation notice on some of the original fmcapi Classes (so that our Class names align with Cisco's API call names). Take note of any deprecation warnings and move to the correct Class name in your scripts.
  • 3: You can directly send requests to the FMC via the send_to_api() method in the FMC class. This allows you to access any of the API features of the FMC.

ToDos

  • Write better how-to instructions. (Anyone willing to help?)
  • Finish adding all the FMC API calls as fmcapi Classes.
Comments
  • Adding accessrule based on application instead of destination port

    Adding accessrule based on application instead of destination port

    Hello

    I am trying to post/put the access rule to add the application ( eg. Facebook) instead of ports based rule.

    I checked the unit test script and don't see the option for the application.

    Would it be possible to add the access rule to reference the application instead of the destination port?

    Thanks for your help

    opened by MSD101 19
  • Update MissionStatement and Goals

    Update MissionStatement and Goals

    Looking for help in updating the Mission Statement and Goals for this project. I haven't updated them for a long time but I don't want to "push" any agenda on anyone helping with this project. So, I'd like to use this "issue" ticket to generate discussion on what we should do going forward. https://github.com/daxm/fmcapi/blob/master/docs/MissionStatement%20and%20Goals.md

    help wanted 
    opened by daxm 14
  • Factorial Duplication - Access Rules via post

    Factorial Duplication - Access Rules via post

    Describe the bug While using the same fmc object in a loop and posting a set new access rule, it will post every rule before it.

    If I am looping 6 new rules, it will post 1 - 12 -123 -1234 -12345 - 123456 for a total of 21 rules created.

    To Reproduce Loop creation of access rules while using a with statement of a fmc object.

    Expected behavior Only posting 6 rules when supplied 6 rules.

    import fmcapi
    
    class Connection(fmcapi.FMC):
        def __init__(
            self,
            host="fmc01",
            username="admin",
            password="Admin123",
            domain='test',
            autodeploy=False,
            file_logging=None,
            logging_level="INFO",
            debug=False,
            limit=1000,
            timeout=15):
            super().__init__(
                host, username, password,
                domain, autodeploy,
                file_logging, logging_level,
                debug, limit, timeout)
    
        def rule_add(self, rule_list):
            '''
            '''
            if not isinstance(rule_list, list):
                rule_list = [rule_list]
    
            rule_results = []
            for rule in rule_list:
                rule_details = fmcapi.AccessRules(
                    fmc=self, acp_name=rule.access_policy)
    
              # prep rules
    
                rule_results.append(rule_details.post())
                print('---')
    
            return rule_results
    

    Python environment

    asttokens==2.0.5
    autopep8==1.6.0
    backcall==0.2.0
    bcrypt==3.2.2
    Brotli==1.0.9
    certifi==2022.6.15
    cffi==1.15.0
    charset-normalizer==2.1.0
    click==8.1.3
    colorama==0.4.5
    cryptography==37.0.2
    dash==2.5.1
    dash-core-components==2.0.0
    dash-cytoscape==0.3.0
    dash-html-components==2.0.0
    dash-table==5.0.0
    DateTime==4.4
    decorator==5.1.1
    diffios==0.0.9
    executing==0.8.3
    flake8==4.0.1
    Flask==2.1.2
    Flask-Compress==1.12
    fmcapi==20220914.0
    future==0.18.2
    idna==3.3
    ipaddress==1.0.23
    ipython==8.4.0
    itsdangerous==2.1.2
    jedi==0.18.1
    Jinja2==3.1.2
    MarkupSafe==2.1.1
    matplotlib-inline==0.1.3
    mccabe==0.6.1
    netmiko==4.1.0
    networkx==2.8.4
    ntc-templates==3.0.0
    paramiko==2.11.0
    parso==0.8.3
    passlib==1.7.4
    pickleshare==0.7.5
    plotly==5.9.0
    prompt-toolkit==3.0.30
    pure-eval==0.2.2
    pycodestyle==2.8.0
    pycparser==2.21
    pycryptodome==3.15.0
    pyflakes==2.4.0
    Pygments==2.12.0
    PyNaCl==1.5.0
    pyserial==3.5
    pytz==2022.1
    PyYAML==6.0
    requests==2.28.1
    scp==0.14.4
    six==1.16.0
    stack-data==0.3.0
    tenacity==8.0.1
    textfsm==1.1.2
    toml==0.10.2
    traitlets==5.3.0
    urllib3==1.26.9
    wcwidth==0.2.5
    Werkzeug==2.1.2
    zope.interface==5.4.0
    

    Additional context Add any other context about the problem here.

    opened by Niltak 12
  • endless loop when 2 requests happens

    endless loop when 2 requests happens

    Is your feature request related to a problem? Please describe. I have a script to add hosts to the group. The script login, get the group, search in the response if the object is already in the group, if not add, if yes skip, finally verify. This involves several get/post/get operations. While executing the script, if another user tries to execute the script again, it will invalidate the first user token, and the first script will lock in an endless loop until the refresh timer.

    Describe the solution you'd like If there was a successful first login, then wait a few seconds and try to log in again.

    opened by aegiacometti 9
  • Add categories in access policy

    Add categories in access policy

    [**Is](url categories.zip )

    I made a script for the creation of category in the access policy, however being beginning in python, could check if everything is good (and publish if you want)

    Check with FMC 6.6 and 6.5

    Best regards

    opened by rnuyttens 9
  • Docmentation: List All NAT Rules

    Docmentation: List All NAT Rules

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    I'm trying to create a script to export all the NAT rules into a CSV, but I can't quite get it working the way I want so wondering if you had a working example that you could share?

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Working Example would be great, or a few pointers?

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    I've looked around and at the module, but can only get a list of the NAT Policies so far not the actual NAT rules. I may be missing something obvious.

    Additional context Add any other context or screenshots about the feature request here.

    opened by salsop 9
  • ACPRule.put() action not passing through well

    ACPRule.put() action not passing through well

    I'm trying to edit existing rules through the API. More specifically all I want to change is switching source and destination zone. I obtain them in following lines:

    `acprule = ACPRule(fmc=fmc1, acp_name=acpname) acprule.name = rule['name'] #rule has been obtained from a send_to_api function obtaining all policies in the ACP acprule.id = rule['id'] acprule.get()

                        acprule.sendEventsToFMC = True
                        acprule.logBegin = True
                        acprule.intrusion_policy(action='set', name='IPS-Balanced')
                        acprule.source_zone(action='clear')
                        acprule.destination_zone(action='add', name=src_zone)
    
                        print(acprule.format_data())
    
                        acprule.put()`
    

    The rule gets obtained just fine with all metadata in the get function. Printing the format_data also lists that all information from the obtained rule is still there, plus the changes made to the rule. However, when I then try to put the changes to the API, the format_data function called in the API changes "ALLOW" to "BLOCK". Even if I manually set the action to allow before calling the put function.

    Do you have any idea how the action-attribute gets lost the moment I call the put function? I'm still quite new to python, but have some experience in programming ... so I'm not sure if it's actually the fmcapi-module or not causing this.

    The output of formate_data looks like this:

    Before put:
    {'id': 'acp_id', 'name': 'ACL_1', 'action': 'ALLOW', 'enabled': True, 'sendEventsToFMC': True, 'logFiles': False, 'logBegin': True, 'logEnd': False, 'variableSet': {'name': 'Default-Set', 'id': 'set_id', 'type': 'VariableSet'}, 'type': 'AccessRule', 'vlanTags': {}, 'sourceNetworks': {'objects': [{'type': 'NetworkGroup', 'name': 'my_group', 'id': 'group_id'}]}, 'destinationNetworks': {'objects': [{'type': 'NetworkGroup', 'name': 'any', 'id': 'group_id'}]}, 'destinationPorts': {'objects': [{'type': 'ProtocolPortObject', 'protocol': 'UDP', 'name': 'my_port', 'id': 'port_id'}, {'type': 'ProtocolPortObject', 'protocol': 'TCP', 'name': 'my_port2', 'id': 'port_id2'}]}, 'ipsPolicy': {'name': 'IPS-Balanced', 'id': 'ips_id', 'type': 'intrusionpolicy'}, 'destinationZones': {'objects': [{'name': 'INTERNET', 'id': 'zone_id', 'type': 'SecurityZone'}]}}
    
    After put:
    {'id': 'acp_id', 'name': 'ACL_1', 'action': 'BLOCK', 'enabled': True, 'sendEventsToFMC': True, 'logFiles': False, 'logBegin': False, 'logEnd': False, 'variableSet': {'name': 'Default-Set', 'id': 'set_id', 'type': 'VariableSet'}, 'type': 'AccessRule', 'vlanTags': {}, 'sourceNetworks': {'objects': [{'type': 'NetworkGroup', 'name': 'my_group', 'id': 'group_id'}]}, 'destinationNetworks': {'objects': [{'type': 'NetworkGroup', 'name': 'any', 'id': 'group_id'}]}, 'destinationPorts': {'objects': [{'type': 'ProtocolPortObject', 'protocol': 'UDP', 'name': 'my_port', 'id': 'port_id'}, {'type': 'ProtocolPortObject', 'protocol': 'TCP', 'name': 'my_port2', 'id': 'port_id2'}]}, 'ipsPolicy': {'name': 'IPS-Balanced', 'id': 'ips_id', 'type': 'intrusionpolicy'}, 'destinationZones': {'objects': [{'name': 'INTERNET', 'id': 'zone_id', 'type': 'SecurityZone'}]}}
    
    bug 
    opened by brammeskens 8
  • Access Rule Comments

    Access Rule Comments

    I would like the ability to easily add/append "comments" to the access rules for each rule change. If this functionality is available, I'm not sure how to use it at the moment.

    https://github.com/daxm/fmcapi/blob/master/fmcapi/api_objects/policy_services/accessrules.py

    image

    image

    opened by Td3v 7
  • Documentation To Modify Existing objects

    Documentation To Modify Existing objects

    Is your feature request related to a problem? Please describe. I can't fine any documentation about using fmcapi to modify existing objects. I am trying to modify a network group object to add more ip addresses to it. I would also like to modify existing rules to add destination ports or destination addresses

    Describe the solution you'd like I would like update documentation with some examples of modifying objects.

    opened by rlc9090gmail 6
  • literals in portobjectgroups

    literals in portobjectgroups

    I successfully created literals in the networkobjectgroups but that option is missing in portobjectgroups. I see a comment "Technically you can have objects OR literals" but there is no "unnamed" section. I'm just not sure if you can have literals in the portobjectgroup or you just haven't got around to coding it yet. Thanks

    opened by jmattatall 5
  • Bulk Posts?

    Bulk Posts?

    I've been poking around with this module for a couple of days now and one thing I can't determine is if you have the ability to post objects in bulk?

    I.E. I need to post thousands of individual Hosts, and Networks objects and doing this 1 by 1 takes hour(s).

    I skimmed through the few examples but didn't notice any bulk posts, I didn't notice any in the YouTube video either, and VS Code intellisense isn't pointing me to a solution.

    Anyway, I love this module. Thank you for writing and maintaining it.

    opened by MysticRyuujin 5
  • Add Destination/Source Ports literals to Access Rules

    Add Destination/Source Ports literals to Access Rules

    Hello Guys,

    First of all, thanks for this

    It will be really great to have the ability to add port literals for Access Rules just like we can with source and destination networks. Having to create port objects for access rules has left us with a lot of duplicated port objects.

    Thanks.

    opened by dadelowo367 5
Releases(20200330.0)
  • 20200330.0(Mar 30, 2020)

  • 20200213.0(Feb 13, 2020)

  • 20191130.1(Nov 30, 2019)

  • 20191017.0(Oct 17, 2019)

    Bug fixes Improved debug outputs Added ability to add source_sgt into AccessRules but it appears the FMC isn't using it yet. Added access to defaultAction in AccessRules. Added access to IKESettings API Added access to IPsecSettings API Added access to AdvancedSettings API Added access to Endpoints API Expanded the Example to include an example of separation of user data and code. Added extendedACL support to EndPoints. Modified INFO logging. Move some messages into DEBUG/ERROR/WARNING levels instead.

    Source code(tar.gz)
    Source code(zip)
  • 20191002.0(Oct 2, 2019)

    There was a "bug" that caused fmcapi AccessRules to not put/post to FMC. Fixed. Alpha (untested) ability to add source_sgt to AccessRules.

    Source code(tar.gz)
    Source code(zip)
  • 20190923.0(Sep 24, 2019)

  • 20190915.1(Sep 15, 2019)

    This release has a drastic reorganization of the api_objects package into sub-packages that align with the Cisco FMC API Quick Start Guide organization of the API methods. This meant that some of the "old" names of some of the fmcapi classes needed to be changed. The old name will work for a while but you should get a deprecation warning if you use the old name. When the removal of the old names happens has yet to be determined... 2021'ish? Improvements to the token refresh/generation in this release too.

    Source code(tar.gz)
    Source code(zip)
  • 20190911.0(Sep 11, 2019)

    Added a "dry_run" feature. This will allow you to see what would have been sent to the FMC's API. Works for GET, POST, PUT. (I forgot to add it to DELETE. I'll fix that in the next release.)

    Fixed "enabled" always being False in PhysicalInterface Class.

    Adjusted, again, the token refresh logic.

    Source code(tar.gz)
    Source code(zip)
  • 20190910.1(Sep 10, 2019)

  • 20190910.0(Sep 10, 2019)

    The big new feature is the ability to use the bulk POST feature for ACPRules. Misc bug fixes too. Split TestingUserScript tests out into individual files (under unit_tests) directory.

    Source code(tar.gz)
    Source code(zip)
  • 20190908.0(Sep 8, 2019)

  • 20190828.0(Aug 29, 2019)

  • 20190824.0(Aug 24, 2019)

  • 20190819.0(Aug 19, 2019)

Owner
Mark Sullivan
Mark Sullivan
This Is Advanced Version Of Old Radio Player, An Telegram Bot to Play Radio/Music in Channel or Group Voice Chats.

Telegram Radio Player V2 An Telegram Bot to Play Radio/Music in Channel or Group Voice Chats. This is also the source code of the bot which is being u

SAF ONE 81 Dec 03, 2022
Ark API Wrapper in Python

Pythark Ark API Wrapper in Python. Built with Python Requests Installation Pythark uses Arky to create a new transaction, if you want to use this feat

Jolan 14 Mar 11, 2021
An API wrapper for convertio.co written in Python.

An API wrapper for convertio.co written in Python.

Moonrise 9 Sep 27, 2022
Basic query to access Traindex API

traindex-api-query Basic query to access Traindex API Please make sure to provide your Traindex API key to the line 8 in the script file. There are tw

Foretheta 1 Nov 11, 2021
Powerful and Advance Telegram Bot with soo many features😋🔥❤

Chat-Bot Reach this bot on Telegram Chat Bot New Features 🔥 ✨ Improved Chat Experience ✨ Removed Some Unnecessary Commands ✨ Added Facility to downlo

Sanila Ranatunga 10 Oct 21, 2022
SUPPORTS 500 GROUPS NO NEED OF BOT 😉

LOVELY RADIO SUPPORTS 500 GROUPS NO NEED OF BOT 😉 Requirements Telegram API_ID , API_HASH and SESSION_NAME HEROKU Get YouTube live stream link instal

6 Nov 24, 2021
Add Reactions to your Channel Posts!

• Shaaak - Post Reaction Bot Simple and Minimalistic telegram bot to add Reactions and Comments to your Channel Posts! - What's Unique About it?

Harsh Raj 4 Jan 31, 2022
GitGram Bot. Bot Then Message You Your Repo Starts, Forks, And Many More

Yet Another GitAlertBot Inspired From Dev-v2's GitGram Run Bot: Local Host Git Clone Repo : For Telethon Version : git clone https://github.com/TeamAl

Alina RoBot 2 Nov 24, 2021
PlexAutoSkip - Automatically skip content in Plex

PlexAutoSkip Automatically skip tagged content in Plex A background python scrip

Michael Higgins 97 Dec 21, 2022
Let your friends know when you are online and offline xD

Twitter Last Seen Activity Let your friends know when you are online and offline Laser-light eyes when online Last seen is mentioned in user bio Also

Kush Choudhary 12 Aug 16, 2021
Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & runs for 24x7 hours.

PowerfulBotStatus-IDN-C-X Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & ru

IDNCoderX 5 Oct 06, 2022
Get-Phone-Number-Details-using-Python - To get the details of any number, we can use an amazing Python module known as phonenumbers.

Get-Phone-Number-Details-using-Python To get the details of any number, we can use an amazing Python module known as phonenumbers. We can use the amaz

Coding Taggers 1 Jan 01, 2022
Fast discord token checker with high cpm

Discord-Token-checker Fast discord token checker with high cpm preivew Download git clone https://github.com/TusTusDev/Discord-Token-checker pip insta

Tustus 1 Oct 15, 2021
Moderation and Utility Discord bot.

Qrista An advanced Moderation and Utility Discord bot. Features Uses Hikari and Lightbulb as a command handler Advance Logging & Whole new enviroment

Blaze Camp 2 Jan 11, 2022
WhatsApp Status Tracker With Python

Warning!! This Repo is Purly educational purpose Don't use this to stalk on others, which is subjective to crime Pre-Req: Telegram bot of your own wit

Vignesh Karunagaran 10 Dec 09, 2022
Unofficial calendar integration with Gradescope

Gradescope-Calendar This script scrapes your Gradescope account for courses and assignment details. Assignment details currently can be transferred to

6 May 06, 2022
Projeto Informações Conta do Instagram - Instagram Account Information Project

VESTA-tools A collection of simple tools that proved to be needed for handling large periodic calculations with the VASP software package. distTotCalc

Thiago Souza 1 Dec 02, 2021
A ideia é fornecer uma base ampla de questões do ENEM como uma api REST

base10 "A ideia é fornecer uma base ampla de questões do ENEM como uma api REST" TODO Documentar a api com apifairy Criar testes Criar crawler para si

Wadson Garbes 4 Apr 24, 2022
A Recommendation System For Diabetes Detection And Treatment

Diabetes-detection-tg-bot A Recommendation System For Diabetes Detection And Treatment Данная система помогает определить наличие или отсутствие сахар

Alexander Kanonirov 1 Nov 22, 2021
Mini Tool to lovers of debe from eksisozluk (one of the most famous website -reffered as collaborative dictionary like reddit- in Turkey) for pushing debe (Most Liked Entries of Yesterday) to kindle every day via Github Actions.

debe to kindle Mini Tool to lovers of debe from eksisozluk (one of the most famous website -refered as collaborative dictionary like reddit- in Turkey

11 Oct 11, 2022