nw_service

The following methods allow for interaction with the ZTW Network Services API endpoints.

Methods are accessible via ztw.nw_service

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 NWServiceAPI

Bases: APIClient

add_network_service(ports=None, **kwargs)

Adds a new Network Service.

Parameters:
  • name – The name of the Network Service

  • ports (list) –

    A list of port protocol tuples. Tuples must follow the convention src/dest, protocol, start port, end port. If this is a single port and not a port range then end port can be omitted. E.g.

    ('src', 'tcp', '49152', '65535'),
    ('dest', 'tcp', '22),
    ('dest', 'tcp', '9010', '9012'),
    ('dest', 'udp', '9010', '9012')
    

  • **kwargs – Optional keyword args.

Keyword Arguments:

description (str) – Additional information on the Network Service.

Returns:

The newly created Network Service resource record.

Return type:

Tuple

Examples

Add Network Service for Microsoft Exchange:

>>> ztw.nw_service.add_network_service('MS LDAP',
...    description='Covers all ports used by MS LDAP',
...    ports=[
...        ('dest', 'tcp', '389'),
...        ('dest', 'udp', '389'),
...        ('dest', 'tcp', '636'),
...        ('dest', 'tcp', '3268', '3269')])

Add Network Service designed to match inbound SSH traffic:

>>> ztw.nw_service.add_network_service('Inbound SSH',
...    description='Inbound SSH',
...    ports=[
...        ('src', 'tcp', '22'),
...        ('dest', 'tcp', '1024', '65535')])
delete_network_service(service_id)

Deletes the specified Network Service.

Parameters:

service_id (str) – The unique ID for the Network Service.

Returns:

The status code for the operation.

Return type:

int

Examples

>>> _, response, error = client.ztw.nw_service.delete_network_service(updated_group.id)
... if error:
...     print(f"Error deleting group: {error}")
... return
list_network_services(query_params=None)

Lists network services in your organization with pagination. A subset of network services can be returned that match a supported filter expression or query.

Parameters:

{dict} (query_params) –

Map of query parameters for the request. [query_params.protocol] {str}: Filter based on the network service protocol. Supported Values: ICMP, TCP, UDP, GRE, ESP, OTHER,

[query_params.search] {str}: The search string used to match against

a service’s name or description attributes.

[query_params.locale] (str): When set to one of the supported locales (e.g., en-US, de-DE,

es-ES, fr-FR, ja-JP, zh-CN), the network application description is localized into the requested language.

Returns:

A tuple containing (list of network services instances, Response, error)

Return type:

tuple

Examples

Gets a list of all network services.

>>> service_list, response, error = ztw.nw_service.list_network_services():
... if error:
...     print(f"Error listing network services: {error}")
...     return
... print(f"Total network services found: {len(service_list)}")
... for service in service_list:
...     print(service.as_dict())

Gets a list of all network services.

>>> service_list, response, error = ztw.nw_service.list_network_services(query_params={"search": 'FTP'}):
... if error:
...     print(f"Error listing network services: {error}")
...     return
... print(f"Total services found: {len(service_list)}")
... for service in service_list:
...     print(service.as_dict())
update_network_service(service_id, ports=None, **kwargs)

Updates the specified Network Service.

If ports aren’t provided then no changes will be made to the ports already defined. If ports are provided then the existing ports will be overwritten.

Parameters:
  • service_id (str) – The unique ID for the Network Service.

  • ports (list) –

    A list of port protocol tuples. Tuples must follow the convention src/dest, protocol, start port, end port. If this is a single port and not a port range then end port can be omitted. E.g.

    ('src', 'tcp', '49152', '65535'),
    ('dest', 'tcp', '22),
    ('dest', 'tcp', '9010', '9012'),
    ('dest', 'udp', '9010', '9012')
    

  • **kwargs – Optional keyword args.

Keyword Arguments:

description (str) – Additional information on the Network Service.

Returns:

The updated Network Service resource record.

Return type:

dict

Examples

Update the name and description for a Network Service:

>>> ztw.nw_service.update_network_service('959093',
...    name='MS Exchange',
...    description='All ports related to the MS Exchange service.')

Updates the ports for a Network Service, leaving other fields intact:

>>> ztw.nw_service.update_network_service('959093',
...    ports=[
...        ('dest', 'tcp', '500', '510')])