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

Export ADOM and Device name from Fortimanager

Hello everybody,

 

I have a fortimanager with several ADOMs, and inside each ADOM there are devices that have a device name, what I would like to do is export the names of all the ADOMs and all the devices inside the ADOMs but I haven't found anything about it .

Do you happen to think of anything useful about it?

 

BR.

 

1 Solution
fredery
Staff
Staff

Hello GiuseppeB,

 

All the info you ask about is available in the cli with the output from the following command :

 

# diag dvm device list

 

You may need to do some manipulation to put it in the format you require with this data, should not be too hard !

View solution in original post

2 REPLIES 2
fredery
Staff
Staff

Hello GiuseppeB,

 

All the info you ask about is available in the cli with the output from the following command :

 

# diag dvm device list

 

You may need to do some manipulation to put it in the format you require with this data, should not be too hard !

GiuseppeB
New Contributor III

Hello Fredery,

 

the goal is do it with a call from API python, but im stuck to some error in the script, maybe you can give me some advise to repair the problem,

The script

 

import requests
import json
import urllib3

# Disable SSL verification warning
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# FortiManager API endpoint and credentials
url = "https://192.168.178.120/jsonrpc"
username = "admin"
password = "admin"

# FortiManager API method to get the list of devices
method = "getDeviceList"

# JSON-RPC request payload
payload = {
"id": 1,
"method": method,
"params": [{}],
"session": requests.session().headers.get("Cookie"),
}

# Send the JSON-RPC request to FortiManager API endpoint
response = requests.post(url, json=payload, auth=(username, password), verify=False)

# Parse the JSON response
response_json = json.loads(response.text)

if isinstance(response_json, list): # response is a list of JSON objects
devices = []
for obj in response_json:
devices.append(obj.get("name"))
else: # response is a single JSON object
devices = response_json.get("result", {}).get("data", [])

# Print the list of devices
for device in devices:
print(device)

 

And the error is

C:\Users\elimi\Python310>python fmg.py
Traceback (most recent call last):
File "C:\Users\elimi\Python310\fmg.py", line 35, in <module>
devices = response_json.get("result", {}).get("data", [])
AttributeError: 'list' object has no attribute 'get'

Labels
Top Kudoed Authors