FortiManager
FortiManager supports network operations use cases for centralized management, best practices compliance, and workflow automation to provide better protection against breaches.
farhanahmed
Staff
Staff
Article Id 411703
Description This article describes how to fetch IP address of a specific Interface from all managed FortiGates using ForiManager JSON API and Postman.
Scope FortiManager, FortiGate, JSON API, Postman.
Solution

The FortiManager proxy API can be used to query interface information from multiple managed FortiGate devices simultaneously. This method is particularly useful in environments with a large number of FortiGates, where manual targeting is impractical.

 

Step 1: Retrieve Device Names from FortiManager:

To obtain the list of all managed devices, the following API request can be used:

 

{

  "method": "get",

  "params": [

    {

      "url": "/dvmdb/device"

    }

  ],

  "session": "{{session}}",

  "verbose": 1,

  "id": 1

}

 

Using Postman, in the Scripts -> Post-res section of this request, JavaScript can be used to extract the 'name' field from each device in the response. Each name should be formatted as 'device/<Device_Name>' and stored in a collection variable (e.g., device_targets), which will be referenced in the subsequent API call.

 

get_dev_list.gif

 

Step 2: Fetch Interface Details Using Device List:

With the device list prepared, the following API request can be used to query a specific interface (e.g., wan1) from all devices:

 

{

    "id": "2",

    "method": "exec",

    "params": [

        {

            "url": "sys/proxy/json",

            "data": {

                "target": {{device_targets}},

               

                "action": "get",

                "resource": "/api/v2/cmdb/system/interface/{{DESIRED_INTERFACE}}"

            }

        }

    ],

    "session": "{{session}}"

}

 

Note:

  • The device_targets variable (created in Step1) will include the device name in the format 'device/<Device_Name>' (created in Step1).
  • The DESIRED_INTERFACE variable should be set to the name of the interface to be queried (e.g., wan1).

 

Example of the 'device_targets' variable.Example of the 'device_targets' variable.

 

The API response contains interface details for each specified device. To present a clean summary of the results, JavaScript can be used in the Scripts -> Post-res section of the request in Postman to extract and display the following fields under the Visualization tab:

  • Device Name
  • Interface
  • IP Address

 

fetch_intf_ip.gif

 

Final Output:

 

final_output.png

 

 

  • Attached is the API collection that can be imported into Postman (tested with v11.63.6).
  • Under the 'Variables' tab of the collection, the following variables are required:
    • host: IP address of FortiManager.
    • ADMIN: FortiManager Admin user.
    • PASSWORD: Admin user password.
    • DESIRED_INTERFACE: Interface to fetch IP address from - e.g, wan1.

 

Related documents:

Postman Release Notes

Technical Tip: Using FortiManager API

Fortinet Development Network (FNDN) - FortiGate

Fortinet Development Network (FNDN) - FortiManager

Technical Tip: How to run a proxy API call from FortiManager to a managed FortiGate