FortiGateAPI.cmdb.system.external_resource

class fortigate_api.cmdb.system.ExternalResourceSC(fortigate: FortiGate, **kwargs)

Web UI

https://172.16.177.65/ng/external-connector

API

https://172.16.177.65/api/v2/cmdb/system/external-resource

Data

cmdb/system/external-resource

uid: str = 'name'

Unique identifier of fortigate-object.

create(data: Dict[str, Any]) Response

Create the fortigate-object in the Fortigate.

Parameters:

data (dict) – Data of the fortigate-object. More details can be found at https://fndn.fortinet.net for related POST method.

Returns:

Session response.

  • <Response [200]> Object successfully created,

  • <Response [500]> Object already exists.

Return type:

Response

delete(uid: str | int = '', filter: str | Sequence[str] = '', **kwargs) Response

Delete the fortigate-object from the Fortigate.

Parameters:
  • uid (str or int) – Identifier of the fortigate-object. Used to delete a single object.

  • filter (str or List[str]) – Filter fortigate-objects by one or multiple Filtering conditions. Used to delete multiple objects.

  • kwargs – Fortigate REST API parameters. More details can be found at https://fndn.fortinet.net for related DELETE method.

Returns:

Session response.

  • <Response [200]> Object successfully deleted,

  • <Response [404]> Object not found in the Fortigate.

Return type:

Response

get(**kwargs) List[Dict[str, Any]]

Get fortigate-objects, all or filtered by some parameters.

Parameters:

kwargs – Fortigate REST API parameters. filter - Filter fortigate-objects by one or multiple Filtering conditions. More details can be found at https://fndn.fortinet.net for related GET method.

Returns:

List of the fortigate-objects.

Return type:

List[dict]

is_exist(uid: str | int) bool

Check if a fortigate-object exists in the Fortigate.

Parameters:

uid (str or int) – Identifier of the fortigate-object.

Returns:

True - object exists, False - object does not exist.

Return type:

bool

update(data: Dict[str, Any]) Response

Update fortigate-object on the Fortigate.

Parameters:

data (dict) – Data of the fortigate-object to update. More details can be found at https://fndn.fortinet.net for related PUT method.

Returns:

Session response.

  • <Response [200]> Object successfully updated,

  • <Response [404]> Object has not been updated.

Return type:

Response

property url: str

URL to the fortigate-object.

Usage

"""api/v2/cmdb/system/external-resource

- Create External Resources
- Gets all external-resources from the Fortigate
- Gets filtered external-resources by name (unique identifier)
- Updates external-resource data in the Fortigate
- Deletes external-resource from the Fortigate by name
- Checks for absence of external_resource in the Fortigate
"""

from fortigate_api import FortiGateAPI

HOST = "host"
USERNAME = "username"
PASSWORD = "password"

api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)

# Create External Resources
data = {"name": "RESOURCE_1", "resource": "https://domain.com/resource.txt", "type": "address"}
response = api.cmdb.system.external_resource.create(data)
print("external_resource.create", response)  # external_resource.create <Response [200]>

# Gets all external-resources from the Fortigate
items = api.cmdb.system.external_resource.get()
print(f"external-resources count={len(items)}")  # external-resources count=5

# Gets filtered external-resources by name (unique identifier)
items = api.cmdb.system.external_resource.get(name="RESOURCE_1")
print(f"external-resources count={len(items)}")  # external-resources count=1

# Updates external-resource data in the Fortigate
data = dict(name="RESOURCE_1", status="disable")
response = api.cmdb.system.external_resource.update(data)
print("external_resource.update", response)  # external_resource.update <Response [200]>

# Deletes external-resource from the Fortigate by name
response = api.cmdb.system.external_resource.delete("RESOURCE_1")
print("external_resource.delete", response)  # external_resource.delete <Response [200]>

# Checks for absence of external_resource in the Fortigate
response = api.cmdb.system.external_resource.is_exist("RESOURCE_1")
print("external_resource.is_exist", response)  # external_resource.is_exist False

api.logout()