dns_gatways

The following methods allow for interaction with the ZIA DNS Gateways API endpoints.

Methods are accessible via zia.dns_gatways

Copyright (c) 2023, Zscaler Inc.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

class DNSGatewayAPI

Bases: APIClient

add_dns_gateway(**kwargs)

Creates a new ZIA DNS Gateway.

Parameters:

name (str) – Name of the DNS Gateway

Keyword Arguments:
  • primary_ip_or_fqdn (str) – IP address or FQDN of the primary DNS service provided by your DNS service provider

  • secondary_ip_or_fqdn (str) – IP address or FQDN of the secondary DNS service provided by your DNS service provider

  • primary_ports (list[int]) – Lists the ports for the primary DNS server based on the protocols selected.

  • secondary_ports (list[int]) – Lists the ports for the secondary DNS server based on the protocols selected.

  • failure_behavior (str) – Action that must be performed if the configured DNS service is unavailable or unhealthy.

  • protocols (list[str]) – Protocols that must be used to connect to the DNS service Supported Values: ANY, TCP, UDP, DOH

Returns:

A tuple containing the newly added DNS Gateway, response, and error.

Return type:

tuple

Examples

Add a new DNS Gateway:

>>> added_gw, _, error = client.zia.dns_gatways.add_dns_gateway(
...     name=f"DNS_GW01_{random.randint(1000, 10000)}",
...     primary_ip_or_fqdn='8.8.8.8',
...     secondary_ip_or_fqdn='4.4.4.4',
...     failure_behavior='FAIL_RET_ERR',
...     protocols=['TCP', 'UDP', 'DOH'],
...     primary_ports=['53', '53', '443'],
...     secondary_ports=['53', '53', '443']
... )
>>> if error:
...     print(f"Error adding dns gateway: {error}")
...     return
... print(f"DNS Gateway added successfully: {added_gw.as_dict()}")
delete_dns_gateway(gateway_id)

Deletes the specified DNS Gateway.

Parameters:

gateway_id (str) – The unique identifier of the DNS Gateway.

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Examples

Updating an existing DNS Gateway:

>>> _, _, error = client.zia.dns_gatways.delete_dns_gateway('778766')
>>> if error:
...     print(f"Error deleting dns gateway: {error}")
...     return
... print(f"DNS Gateway with ID '778766' deleted successfully.")
get_dns_gateways(gateway_id)

Retrieves a list of Proxy Gateways.

Returns:

A tuple containing:

N/A

Return type:

tuple

Examples

>>> fetched_gw, _, error = client.zia.dns_gatways.get_dns_gateways('87787')
>>> if error:
...     print(f"Error fetching dns gateway by ID: {error}")
...     return
... print(f"Fetched dns gateway  by ID: {fetched_gw.as_dict()}")
list_dns_gateways(query_params=None)

Returns a list of dns gateways.

Parameters:

query_params (dict) –

Map of query parameters for the request.

[query_params.page] (int): Specifies the page offset.

[query_params.page_size] (int): Specifies the page size. The default size is 255.

Returns:

List of configured dns gateways as (DNSGatways, Response, error).

Return type:

tuple

Examples

List all dns gateways

>>> gw_list, _, error = zia.dns_gateways.list_dns_gateways()
... if error:
...     print(f"Error listing gateways: {error}")
...     return
... print(f"Total gateways found: {len(gw_list)}")
... for gw in gw_list:
...     print(gw.as_dict())

List dns gateway that match the name ‘DNS_GW01’

>>> gw_list, _, error = zia.dns_gateways.list_dns_gateways(
... query_params={"search": 'DNS_GW01'})
... if error:
...     print(f"Error listing gateways: {error}")
...     return
... print(f"Total gateways found: {len(gw_list)}")
... for gw in gw_list:
...     print(gw.as_dict())
update_dns_gateway(gateway_id, **kwargs)

Updates information for the specified ZIA DNS Gateway.

Parameters:

gateway_id (int) – The unique ID for the DNS Gateway.

Keyword Arguments:
  • name (str) – Name of the rule, max 31 chars.

  • primary_ip_or_fqdn (str) – IP address or FQDN of the primary DNS service provided by your DNS service provider

  • secondary_ip_or_fqdn (str) – IP address or FQDN of the secondary DNS service provided by your DNS service provider

  • primary_ports (list[int]) – Lists the ports for the primary DNS server based on the protocols selected.

  • secondary_ports (list[int]) – Lists the ports for the secondary DNS server based on the protocols selected.

  • failure_behavior (str) – Action that must be performed if the configured DNS service is unavailable or unhealthy.

  • protocols (list[str]) – Protocols that must be used to connect to the DNS service Supported Values: ANY, TCP, UDP, DOH

Returns:

A tuple containing the updated DNS Gateway, response, and error.

Return type:

tuple

Examples

Updating an existing DNS Gateway:

>>> updated_gw, _, error = client.zia.dns_gatways.add_dns_gateway(
...     gateway_id='671763',
...     name=f"UpdateDNS_GW01_{random.randint(1000, 10000)}",
...     primary_ip_or_fqdn='8.8.8.8',
...     secondary_ip_or_fqdn='4.4.4.4',
...     failure_behavior='FAIL_RET_ERR',
...     protocols=['TCP', 'UDP', 'DOH'],
...     primary_ports=['53', '53', '443'],
...     secondary_ports=['53', '53', '443']
... )
>>> if error:
...     print(f"Error updating dns gateway: {error}")
...     return
... print(f"DNS Gateway updated successfully: {updated_gw.as_dict()}")