Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryanmerolle/0cd953004777e23d4da23048396d4d4f to your computer and use it in GitHub Desktop.
Save ryanmerolle/0cd953004777e23d4da23048396d4d4f to your computer and use it in GitHub Desktop.
batfish_audit.py
#!/usr/bin/env python
from pybatfish.client.session import Session
# Step 1: Set up Pybatfish
bf = Session(host="localhost")
bf.set_network("backup_configs")
# Step 2: Load configurations
SNAPSHOT_DIR = "tests/data/inputs"
bf.init_snapshot(SNAPSHOT_DIR, name="backups", overwrite=True)
# Step 3: Analyze configurations
# a. Undefined References
undefined_references = bf.q.undefinedReferences().answer().frame()
# b. Unused Structures
unused_config = bf.q.unusedStructures().answer().frame()
# c. Duplicate Router IDs
# duplicate_router_ids = bf.q.duplicateRouterIds().answer().frame()
# Step 4: Export findings to CSV
# Make sure you have write permission to the target directory or change the paths accordingly.
undefined_references.to_csv("undefinedReferences.csv", index=False)
unused_config.to_csv("unusedConfig.csv", index=False)
# duplicate_router_ids.to_csv("duplicate_router_ids.csv", index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment