Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
ToddS
New Contributor II

FortiSwitch using FortiManager API

 

Hi all -

 

I have been fighting with the FortiManager API for a while now.  With a Python script, I've been able to:

  • Authenticate to Fortimanager
  • Query all Fortigates in FortiManage
    • Loop through the devices to find a specific Fortigate
  • Collect details from any individual or all Fortigates including
    • Interface Status, IP address, subnet, vlan and description
    • Grab the Switch Hostname, Serial Number and number of ports

I am struggling with figuring out how to pull the switch details for:

  • Mgmt IP address
  • Model Number (It appears to part of the start of the serial number)

I'm pretty sure I can get it pretty easy from the FortiOS directly, but I'm really hoping to pull the details from FortiManager with the same "connection".  I can see the details in FortiManager under FortiSwitches.

 

Any ideas anyone?

 

Thanks,

-Todd

 

1 Solution
ToddS
New Contributor II

I think I found the issue... The only thing that I changed was:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"
        
        # If we want to filter by a specific device, we can add scope
        data = None
        if device_name:
            print(f"Filtering switches for device: {device_name}")
            data = {
                "scope member": {
                    "name": device_name
                }
            }
        
        response = self._make_request(url_path, method="get", data=data, verbose=True)

 

"verbose=True"

View solution in original post

5 REPLIES 5
Richie_C
Staff
Staff

Hi Todd 

 

From the docs, it looks like you should be targetting:

 

/pm/config/adom/<ADOM_NAME>/obj/fsp/managed-switch

The table returns platform and vlan interface. 

 

Regards

 

Take a backup before making any changes
ToddS
New Contributor II

Thanks for the reply Richie. 

 

I have been fighting with "/pm/config/device/{device}/vdom/{vdom}/switch-controller/managed-switch/{switch-id}"  thinking the data should be there, but never got the results I expected.

 

I thought the "/pm/config/adom/<ADOM_NAME>/obj/fsp/managed-switch" was for FortiOS as I was reading through the docs.  I do see that it is recognized by FortiManager.  I'm still working on the details... Currently trying:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"
        
        data = None
        if device_name:
            print(f"Filtering switches for device: {device_name}")
            data = {
                "scope member": [
                    {
                        "name": device_name,
                        "vdom": "root"
                    }
                ]
            }

 

Output is not working... yet...

{'id': 1,
 'result': [{'data': [],
             'status': {'code': 0, 'message': 'OK'},
             'url': '/pm/config/adom/{redacted adom}/obj/fsp/managed-switch'}]}

 

I'm not giving up yet. 

 

Thanks,

-Todd

ToddS
New Contributor II

I think I found the issue... The only thing that I changed was:

 

        url_path = f"/pm/config/adom/{adom_name}/obj/fsp/managed-switch"
        
        # If we want to filter by a specific device, we can add scope
        data = None
        if device_name:
            print(f"Filtering switches for device: {device_name}")
            data = {
                "scope member": {
                    "name": device_name
                }
            }
        
        response = self._make_request(url_path, method="get", data=data, verbose=True)

 

"verbose=True"

filiaks1
Contributor II

The API preview option may help FortiManager 7.6 Features - Preview configuration changes in JSON API and CLI format | Fortinet Vide... also CLI scripts | FortiManager 7.6.3 | Fortinet Document Library are there is anything is not supported.

 

Outside of that Fortinet Developer Network is for API but for some reason Fortinet wants 2 employees to approve this so see with your sales/account.

ToddS
New Contributor II

Good idea.  Thanks @filiaks1 

 

-Todd

 

Announcements
Check out our Community Chatter Blog! Click here to get involved
Labels
Top Kudoed Authors