This script automates the process of managing unused objects in Cisco Firepower Management Center (FMC). It allows users to generate reports of unused objects and optionally delete those unused objects across various object types. The script is designed with error handling, including token expiration and undeletable (read-only) objects, and provides progress feedback during the deletion process.
unused_objects_report.txt
: Contains a list of unused objects.deleted_objects_report.txt
: Lists objects that were successfully deleted.undeletable_objects_report.txt
: Logs objects that could not be deleted, typically due to being read-only.requests
library (pip install requests
)Clone or Download the Script:
object_cleanup.py
file in your working directory.Install Required Python Libraries:
requests
library installed. You can install it using:
pip install requests
Run the Script:
python3 object_cleanup.py
Provide FMC Credentials:
Select Object Types:
1: networks
2: protocolportobjects
3: hosts
4: networkgroups
5: portgroups
6: addressranges
7: securityzones
8: fqdn
9: dnsservergroups
Choose an Action:
Monitor Progress:
Review Reports:
unused_objects_report.txt
: Report of all unused objects.deleted_objects_report.txt
: Report of objects that were successfully deleted.undeletable_objects_report.txt
: Report of objects that could not be deleted due to being read-only.undeletable_objects_report.txt
.python3 object_cleanup.py
Enter FMC IP address: 10.127.212.234
Enter FMC Username: admin
Enter FMC Password:
Select the object types you want to manage (comma-separated list):
1: networks
2: protocolportobjects
3: hosts
4: networkgroups
5: portgroups
6: addressranges
7: securityzones
8: fqdn
9: dnsservergroups
Enter your choice(s): 1,3
What would you like to do?
1: Generate a report of unused objects
2: Delete unused objects and generate a report
Enter your choice (1 or 2): 2
Security Warning: The script disables SSL verification (verify=False
) for HTTPS requests. This is not recommended for production environments as it can expose you to security risks. If you are running this script in a production environment, ensure that SSL verification is enabled, or use a properly configured SSL certificate.
Disclaimer: Use this script at your own risk. Ensure you have a backup of your FMC configuration before running any scripts that delete objects.
This script is provided "as-is" without any warranties or guarantees. The author is not responsible for any damage or data loss resulting from the use of this script.
Owner
Contributors
Categories
Products
Secure FirewallProgramming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community