-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to filter policies by multiple conditions #39
Comments
Links to some tutorials: |
How do I filter if there are multiple source-ip addresses? |
I want to find all policies whose source ip address contains 1.1.1.1, but I find that one of my policies whose source ip address is 1.1.1.0/24 is not matched. |
Please try this example to filter your source ip HOST = ""
USERNAME = ""
PASSWORD = ""
api = FortiGateAPI(
host=HOST,
username=USERNAME,
password=PASSWORD,
)
# Get all firewall policies and print the total count
policies_all = api.cmdb.firewall.policy.get()
print(f"{len(policies_all)=}") # len(policies_all)=245
# Get policies by an exact source address using Extended-filter parameter
policies_efilter = api.cmdb.firewall.policy.get(efilter=["srcaddr==1.1.1.1/32"])
print(f"{len(policies_efilter)=}") # len(policies_efilter)=1
# Get policies by an exact source address using filter parameter
policies_filter = []
addresses = api.cmdb.firewall.address.get(filter="subnet==1.1.1.1 255.255.255.255")
for item in api.cmdb.firewall.policy.get():
dstaddr = [d["name"] for d in item["srcaddr"]]
for address in addresses:
if address["name"] in dstaddr:
policies_filter.append(item)
print(f"{len(policies_filter)=}") # len(policies_filter)=1 |
its kind of you |
cmdb.firewall.policy.get(efilter=["dstaddr==2.2.2.2",'srcaddr==1.1.1.1'])
it does not work.
The text was updated successfully, but these errors were encountered: