policy_lookup
Simulates a firewall policy lookup for a traffic 5-tuple against a managed device to show which currently installed policy would match the traffic right now.
Instructions
Simulate a firewall policy lookup for a traffic 5-tuple against a managed device.
Proxies FortiGate's policy-lookup monitor API through FortiManager to
ask "which policy would match this traffic right now" -- the same
operation the FortiManager UI's Policy Lookup dialog performs. This
queries the device's currently installed/active policy; it does not
take a policy-package argument (the documented endpoint has none -- see
module docstring).
Args:
adom: ADOM name
device: Managed device name (e.g. "FGT-HQ"). Accepts the
"device[vdom]" bracket suffix used elsewhere in this codebase
to target a specific VDOM.
dest: Destination IPv4 address to test (e.g. "8.8.8.8")
protocol: IP protocol number to test -- 6=TCP, 17=UDP, 1=ICMP,
47=GRE, 50=ESP, 51=AH, 58=ICMPv6, 132=SCTP.
Sent to the device as both the protocol and
protocol_number query fields, mirroring the one documented
request/response pair in the How-To Guide where both fields
carried the same value; the guide does not show a case where
they differ.
srcintf: Ingress interface name the traffic would arrive on (e.g.
"internal"). Optional -- omitted from the query when not given,
matching the FortiGate monitor API default.
sourceip: Source IPv4 address to test (optional; omitted from the
query when not given -- the How-To Guide's own example queried
with this field empty)
sourceport: Source port to test (optional; omitted when not given)
destport: Destination port to test (optional; 0 -- "any port",
per the How-To Guide example -- when not given)
package: Informational only, NOT sent to the device. The FortiGate
policy-lookup endpoint has no package selector; it always
reflects whatever package is currently installed. Pass this if
you want it echoed back (as package_hint) in the result to
cross-check against what you expect to be installed.
Returns:
dict: Lookup result with keys:
- status: "success" or "error"
- adom, device
- package_hint: the caller-supplied package argument, echoed
back unverified -- NOT confirmation that this package is what
actually matched (named package_hint, not package, so it
can't be misread as verified match data)
- query: the traffic-tuple fields actually sent to the device
- matched: bool from the device's results.success field
when present, else None (the How-To Guide only documents the
no-match case: {"success": false}; a positive match's
full field set is not documented here, so it is not
reshaped -- see result)
- result: the raw results payload returned by the device,
passed through unchanged
- message: Error message if failed
Example: >>> result = await policy_lookup( ... adom="root", ... device="branch1_fgt", ... srcintf="vl_lan", ... protocol=6, ... dest="8.8.8.8", ... ) >>> result["matched"] False
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| adom | Yes | ||
| dest | Yes | ||
| device | Yes | ||
| package | No | ||
| srcintf | No | ||
| destport | No | ||
| protocol | Yes | ||
| sourceip | No | ||
| sourceport | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||