Technical Tip: How to get device status on FortiManager via API
Description
This article describes how to retrieve device status (Config Status & Policy Package) information from FortiManager using the JSON RPC API.
Scope
FortiManager.
Solution
FortiManager provides device status information through the dvmdb (Device Manager database) API endpoints.
In the GUI, the Device Manager dashboard summarizes device health and status, including configuration synchronization and policy package state.
Using the API, the same information can be retrieved programmatically. Review Technical Tip: Using FortiManager/FortiAnalyzer API to understand how to use the API on FortiManager.
To get the device config status:
Request:
{ "id": 3, "method": "get", "params": [ { "fields": [ "conf_status" ], "url": "/dvmdb/device/fortigate1" } ], "session": "sessionid", "verbose": 1 }
As specified in the 'fields', the 'conf_status' field will show device config status. FortiManager can return various information about the device when the 'fields' are removed.
Response:
{ "cid": 50, "id": 3, "result": [ { "data": { "conf_status": "insync", "ha_slave": null, "name": "fortigate1", "oid": 182, "onboard_rule": null, "vdom": [ { "comments": "", "devid": "fortigate1", "ext_flags": 1, "flags": null, "name": "root", "node_flags": 65536, "oid": 3, "opmode": "nat", "rtm_prof_id": 0, "status": null, "tab_status": null, "vdom_type": "traffic", "vpn_id": 0 } ] }, "status": { "code": 0, "message": "OK" }, "url": "/dvmdb/device/fortigate1" } ] }
The following URL can be used with the same API call above to get the VDOM status of the managed device:
"url": "/dvmdb/device/fortigate1/vdom/vdom1"
The following URL can be used with the same API call above to get all the managed device statuses:
"url": "/dvmdb/device"
To get the Policy Package status:
Request:
{ "id": 1, "method": "get", "params": [ { "url": "/pm/config/adom/root/_package/status/fortigate1/root" } ], "session": "{{session}}", "verbose": 1 }
Response:
{ "cid": 51, "id": 1, "result": [ { "data": { "dev": "fortigate1", "flags": 0, "pkg": "Main_PP", "status": "modified", "stype": 0, "type": 1, "vdom": "root" }, "status": { "code": 0, "message": "OK" }, "url": "/pm/config/adom/root/_package/status/fortigate1/root" } ] }
Policy Package status for the defined device can be easily seen from the 'status' field.
Troubleshooting:
The following commands can be used on the FortiManager CLI to debug the API Calls:
diagnose debug service httpd 255
diagnose debug service main 255