-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Added:** example policy_filter_efilter.py
- Loading branch information
1 parent
42624b1
commit c44f138
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""api/v2/cmdb/firewall/policy. | ||
- Get all firewall policies, to be sure that we have some policies | ||
- Get policies by an exact source address using Extended-filter parameter | ||
- Get policies by an exact source address using filter parameter | ||
""" | ||
|
||
from fortigate_api import FortiGateAPI | ||
|
||
HOST = "host" | ||
USERNAME = "username" | ||
PASSWORD = "password" | ||
|
||
api = FortiGateAPI( | ||
host=HOST, | ||
username=USERNAME, | ||
password=PASSWORD, | ||
) | ||
|
||
# Get all firewall policies, to be sure that we have some policies | ||
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 | ||
|
||
api.logout() |