Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add services support #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,34 @@ This function leverages **_create_script()_** and **_run_script_on_single_device
* :param device_name: Specify the name of the device
* :param vdom: Specify the Vdom

# User Operations : Working with services

### 43) Get all services

```python
>>> fortimngr.get_services()
```

### 44) Get single service by name

```python
>>> fortimngr.get_service("RDP")
```

# User Operations : Working with service groups

### 45) Get all service groups

```python
>>> fortimngr.get_service_groups()
```

### 46) Get single service group by name

```python
>>> fortimngr.get_service_group("Web Access")
```

## Contributing
- Being new to Python and this being my first publish, to get this module fully working for all of us, the Pull requests are welcome.

Expand Down
39 changes: 33 additions & 6 deletions src/pyFortiManagerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,22 +1004,21 @@ def get_interface(self, device, interface):
# Services
def get_services(self):
"""
Get interface details from the devices.
:param device: Specify name of the device.
"""
Get Services from FortiManager
"""
session = self.login()
payload = \
{"method": "get",
"params": [{"url": f"pm/config/adom/{self.adom}/obj/firewall/service/custom/Custom_Service_1"}]}
"params": [{"url": f"pm/config/adom/{self.adom}/obj/firewall/service/custom"}]}

payload.update(session=self.sessionid)
services = session.post(url=self.base_url, json=payload, verify=self.verify)
return services.json()["result"]

def get_service(self, name):
"""
Get interface details from the devices.
:param name: Specify name of the device.
Get a single services from FortiManager
:param name: Specify name of the service.
"""
session = self.login()
payload = \
Expand All @@ -1029,6 +1028,34 @@ def get_service(self, name):
service = session.post(url=self.base_url, json=payload, verify=self.verify)
return service.json()["result"]

# Service Groups
def get_service_groups(self):
"""
Retrieve all service groups
"""
session = self.login()
payload = \
{"method": "get",
"params": [{"url": f"pm/config/adom/{self.adom}/obj/firewall/service/group"}]}

payload.update(session=self.sessionid)
services = session.post(url=self.base_url, json=payload, verify=self.verify)
return services.json()["result"]

def get_service_group(self, name):
"""
Retrieve a single service group by name
:param name: Specify name of the service group.
"""
session = self.login()
payload = \
{"method": "get",
"params": [{"url": f"pm/config/adom/{self.adom}/obj/firewall/service/group/{name}"}]}

payload.update(session=self.sessionid)
services = session.post(url=self.base_url, json=payload, verify=self.verify)
return services.json()["result"]

# Firewall Policies Methods
def get_firewall_policies(self, policy_package_name="default", policyid=False):
"""
Expand Down