File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ """api/v2/cmdb/firewall/policy.
2+
3+ - Get all firewall policies, to be sure that we have some policies
4+ - Get policies by an exact source address using Extended-filter parameter
5+ - Get policies by an exact source address using filter parameter
6+ """
7+
8+ from fortigate_api import FortiGateAPI
9+
10+ HOST = "host"
11+ USERNAME = "username"
12+ PASSWORD = "password"
13+
14+ api = FortiGateAPI (
15+ host = HOST ,
16+ username = USERNAME ,
17+ password = PASSWORD ,
18+ )
19+
20+ # Get all firewall policies, to be sure that we have some policies
21+ policies_all = api .cmdb .firewall .policy .get ()
22+ print (f"{ len (policies_all )= } " ) # len(policies_all)=245
23+
24+ # Get policies by an exact source address using Extended-filter parameter
25+ policies_efilter = api .cmdb .firewall .policy .get (efilter = ["srcaddr==1.1.1.1/32" ])
26+ print (f"{ len (policies_efilter )= } " ) # len(policies_efilter)=1
27+
28+ # Get policies by an exact source address using filter parameter
29+ policies_filter = []
30+ addresses = api .cmdb .firewall .address .get (filter = "subnet==1.1.1.1 255.255.255.255" )
31+ for item in api .cmdb .firewall .policy .get ():
32+ dstaddr = [d ["name" ] for d in item ["srcaddr" ]]
33+ for address in addresses :
34+ if address ["name" ] in dstaddr :
35+ policies_filter .append (item )
36+ print (f"{ len (policies_filter )= } " ) # len(policies_filter)=1
37+
38+ api .logout ()
You can’t perform that action at this time.
0 commit comments