FortiGate
FortiGate Next Generation Firewall utilizes purpose-built security processors and threat intelligence security services from FortiGuard labs to deliver top-rated protection and high performance, including encrypted traffic.
lpizziniaco
Staff
Staff
Article Id 279950
Description This article describes step-by-step instructions on how to use the SMC API to monitor Virtual IP (VIP) usage.
Scope FortiGate SMC API.
Solution

This article covers the use of the SMC API to monitor the usage and impact of a Virtual IP (VIP). This article does not delve into the configuration details for setting up a virtual IP on a FortiGate; for that information, refer to Technical Tip: Using Virtual IPs to configure port forwarding

In order to know how many time a VIP has been hit, two sequential steps are required. First, extract the UUID of the specific VIP of interest. This information will be used to retrieve relevant data. The following command demonstrates this process:

 

curl -sk -X GET https://<the_ip>/api/v2/cmdb/firewall/vip/?access_token=<token>&vdom==<the_vdom>

 

The system response will contain extensive data. For the purposes of this article, it is advised to use the `jq` command to filter the output, resulting in a more concise format:

 

curl -sk -X GET https://<the_ip>/api/v2/cmdb/firewall/vip/?access_token=<token>&vdom==<the_vdom> | jq -r '{"vips":[.results[] | {name, uuid, extip}]}'

 

The output will resemble the following:

 

{
"vips": [
{
"name": "theVIP",
"uuid": "1c2f9a1e-6e89-51ee-b26a-88e9a45178e2",
"extip": "10.5.53.46"
},
{
"name": "theOtherVIP",
"uuid": "749a56b6-6e8a-51ee-3ec4-47a89b397076",
"extip": "10.5.53.47"
}
]
}

 

Upon obtaining the UUID of interest, the next step involves making another API call using it, as illustrated below:

 

curl -sk -X GET 'https://<your_ip>/api/v2/monitor/firewall/dnat?access_token=<token>&vdom==<your_vdom>&uuid==<uuid_of_interest>'

 

Similar to the previous call, this will yield a detailed response, but the key piece of information for the purposes of this article is the `hit_count`. To filter out unnecessary details, use `jq` as shown below:

 

curl -sk -X GET 'https://<your_ip>/api/v2/monitor/firewall/dnat?access_token=<token>&vdom==<your_vdom>&uuid==<uuid_of_interest>' | jq -r '.results[] | .hit_count'

 

This will provide the specific hit count relevant to any unique VIP monitoring needs.