FortiGateAPI.cmdb.system_snmp.community
- class fortigate_api.cmdb.system_snmp.CommunitySsC(fortigate: FortiGate, **kwargs)
Web UI
API
Data
- uid: str = 'id'
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
POSTmethod.- 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
DELETEmethod.
- 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 relatedGETmethod.- 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
PUTmethod.- 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.snmp/community
- Creates snmp-community
- Get all snmp-community
- Filter snmp-community by operator equals `==`
- Filter snmp-community by id (unique identifier)
- Filter snmp-community by multiple conditions
- Update snmp-community data in the Fortigate
- Delete snmp-community from the Fortigate by name
- Delete snmp-community from the Fortigate by filter
- Check for presence of snmp-community in the Fortigate
"""
from fortigate_api import FortiGateAPI
HOST = "host"
USERNAME = "username"
PASSWORD = "password"
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)
# Creates snmp-community
data = {"name": "SNMP_COMMUNITY", "hosts": [{"id": 1, "ip": "10.0.0.0 255.0.0.0"}]}
response = api.cmdb.system_snmp.community.create(data=data)
print("community.create", response) # community.create <Response [200]>
# Get all snmp-community
items = api.cmdb.system_snmp.community.get()
print(f"community count={len(items)}") # community count=3
# Filter snmp-community by operator equals `==`
items = api.cmdb.system_snmp.community.get(filter="name==SNMP_COMMUNITY")
print(f"community count={len(items)}") # community count=1
# Filter snmp-community by id (unique identifier)
uid = items[-1]["id"]
items = api.cmdb.system_snmp.community.get(id=uid)
print(f"community count={len(items)}") # community count=1
# Filter snmp-community by multiple conditions
filters = ["name==SNMP_COMMUNITY", "query-v2c-status==enable"]
items = api.cmdb.system_snmp.community.get(filter=filters)
print(f"community count={len(items)}") # community count=1
# Update snmp-community data in the Fortigate
data = {"id": uid, "query-v2c-status": "disable"}
response = api.cmdb.system_snmp.community.update(data)
print("community.update", response) # community.update <Response [200]>
# Delete snmp-community from the Fortigate by name
response = api.cmdb.system_snmp.community.delete(uid)
print("community.delete", response) # community.delete <Response [200]>
# Delete snmp-community from the Fortigate by filter
response = api.cmdb.system_snmp.community.delete(filter="name=@SNMP_")
print("community.delete", response) # community.delete <Response [404]>
# Check for presence of snmp-community in the Fortigate
response = api.cmdb.system_snmp.community.is_exist(uid)
print("community.is_exist", response) # community.is_exist False
api.logout()