This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for email profiles (#389)
- Loading branch information
Showing
2 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
# Copyright 2019 Palo Alto Networks, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'community'} | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: panos_email_profile | ||
short_description: Manage email server profiles. | ||
description: | ||
- Manages email server profiles. | ||
author: "Garfield Lee Freeman (@shinmog)" | ||
version_added: "2.8" | ||
requirements: | ||
- pan-python | ||
- pandevice >= 0.11.1 | ||
notes: | ||
- Panorama is supported. | ||
- Check mode is supported. | ||
extends_documentation_fragment: | ||
- panos.transitional_provider | ||
- panos.vsys_shared | ||
- panos.device_group | ||
options: | ||
name: | ||
description: | ||
- Name of the profile. | ||
required: true | ||
config: | ||
description: | ||
- Custom config log format. | ||
system: | ||
description: | ||
- Custom system log format. | ||
threat: | ||
description: | ||
- Custom threat log format. | ||
traffic: | ||
description: | ||
- Custom traffic log format. | ||
hip_match: | ||
description: | ||
- Custom HIP match log format. | ||
url: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom url log format. | ||
data: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom data log format. | ||
wildfire: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom wildfire log format. | ||
tunnel: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom tunnel log format. | ||
user_id: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom user-ID log format. | ||
gtp: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom GTP log format. | ||
auth: | ||
description: | ||
- PAN-OS 8.0+ | ||
- Custom auth log format. | ||
sctp: | ||
description: | ||
- PAN-OS 8.1+ | ||
- Custom SCTP log format. | ||
iptag: | ||
description: | ||
- PAN-OS 9.0+ | ||
- Custom Iptag log format. | ||
escaped_characters: | ||
description: | ||
- Characters to be escaped. | ||
escape_character: | ||
description: | ||
- Escape character | ||
''' | ||
|
||
EXAMPLES = ''' | ||
# Create a profile | ||
- name: Create email profile | ||
panos_email_profile: | ||
provider: '{{ provider }}' | ||
name: 'my-profile' | ||
''' | ||
|
||
RETURN = ''' | ||
# Default return values | ||
''' | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network.panos.panos import get_connection | ||
|
||
|
||
try: | ||
from pandevice.device import EmailServerProfile | ||
from pandevice.errors import PanDeviceError | ||
except ImportError: | ||
pass | ||
|
||
|
||
def main(): | ||
helper = get_connection( | ||
vsys_shared=True, | ||
device_group=True, | ||
with_state=True, | ||
with_classic_provider_spec=True, | ||
min_pandevice_version=(0, 11, 1), | ||
min_panos_version=(7, 1, 0), | ||
argument_spec=dict( | ||
name=dict(required=True), | ||
config=dict(), | ||
system=dict(), | ||
threat=dict(), | ||
traffic=dict(), | ||
hip_match=dict(), | ||
url=dict(), | ||
data=dict(), | ||
wildfire=dict(), | ||
tunnel=dict(), | ||
user_id=dict(), | ||
gtp=dict(), | ||
auth=dict(), | ||
sctp=dict(), | ||
iptag=dict(), | ||
escaped_characters=dict(), | ||
escape_character=dict(), | ||
), | ||
) | ||
module = AnsibleModule( | ||
argument_spec=helper.argument_spec, | ||
supports_check_mode=True, | ||
required_one_of=helper.required_one_of, | ||
) | ||
|
||
# Verify imports, build pandevice object tree. | ||
parent = helper.get_pandevice_parent(module) | ||
|
||
try: | ||
listing = EmailServerProfile.refreshall(parent) | ||
except PanDeviceError as e: | ||
module.fail_json(msg='Failed refresh: {0}'.format(e)) | ||
|
||
spec = { | ||
'name': module.params['name'], | ||
'config': module.params['config'], | ||
'system': module.params['system'], | ||
'threat': module.params['threat'], | ||
'traffic': module.params['traffic'], | ||
'hip_match': module.params['hip_match'], | ||
'url': module.params['url'], | ||
'data': module.params['data'], | ||
'wildfire': module.params['wildfire'], | ||
'tunnel': module.params['tunnel'], | ||
'user_id': module.params['user_id'], | ||
'gtp': module.params['gtp'], | ||
'auth': module.params['auth'], | ||
'sctp': module.params['sctp'], | ||
'iptag': module.params['iptag'], | ||
'escaped_characters': module.params['escaped_characters'], | ||
'escape_character': module.params['escape_character'], | ||
} | ||
obj = EmailServerProfile(**spec) | ||
parent.add(obj) | ||
|
||
changed = helper.apply_state(obj, listing, module) | ||
module.exit_json(changed=changed, msg='Done') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
# Copyright 2019 Palo Alto Networks, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'community'} | ||
|
||
DOCUMENTATION = ''' | ||
--- | ||
module: panos_email_server | ||
short_description: Manage email servers in an email profile. | ||
description: | ||
- Manages email servers in an email server profile. | ||
author: "Garfield Lee Freeman (@shinmog)" | ||
version_added: "2.8" | ||
requirements: | ||
- pan-python | ||
- pandevice >= 0.11.1 | ||
notes: | ||
- Panorama is supported. | ||
- Check mode is supported. | ||
extends_documentation_fragment: | ||
- panos.transitional_provider | ||
- panos.vsys_shared | ||
- panos.device_group | ||
options: | ||
email_profile: | ||
description: | ||
- Name of the email server profile. | ||
required: True | ||
name: | ||
description: | ||
- Server name. | ||
required: True | ||
display_name: | ||
description: | ||
- Display name | ||
from_email: | ||
description: | ||
- From email address | ||
to_email: | ||
description: | ||
- Destination email address. | ||
also_to_email: | ||
description: | ||
- Additional destination email address | ||
email_gateway: | ||
description: | ||
- IP address or FQDN of email gateway to use. | ||
''' | ||
|
||
EXAMPLES = ''' | ||
# Create a profile | ||
- name: Create email server in an email profile | ||
panos_email_server: | ||
provider: '{{ provider }}' | ||
email_profile: 'my-profile' | ||
name: 'my-email-server' | ||
from_email: 'alerts@example.com' | ||
to_email: 'notify@example.com' | ||
email_gateway: 'smtp.example.com' | ||
''' | ||
|
||
RETURN = ''' | ||
# Default return values | ||
''' | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network.panos.panos import get_connection | ||
|
||
|
||
try: | ||
from pandevice.device import EmailServerProfile | ||
from pandevice.device import EmailServer | ||
from pandevice.errors import PanDeviceError | ||
except ImportError: | ||
pass | ||
|
||
|
||
def main(): | ||
helper = get_connection( | ||
vsys_shared=True, | ||
device_group=True, | ||
with_state=True, | ||
with_classic_provider_spec=True, | ||
min_pandevice_version=(0, 11, 1), | ||
min_panos_version=(7, 1, 0), | ||
argument_spec=dict( | ||
email_profile=dict(required=True), | ||
name=dict(required=True), | ||
display_name=dict(), | ||
from_email=dict(), | ||
to_email=dict(), | ||
also_to_email=dict(), | ||
email_gateway=dict(), | ||
), | ||
) | ||
module = AnsibleModule( | ||
argument_spec=helper.argument_spec, | ||
supports_check_mode=True, | ||
required_one_of=helper.required_one_of, | ||
) | ||
|
||
# Verify imports, build pandevice object tree. | ||
parent = helper.get_pandevice_parent(module) | ||
|
||
sp = EmailServerProfile(module.params['email_profile']) | ||
parent.add(sp) | ||
try: | ||
sp.refresh() | ||
except PanDeviceError as e: | ||
module.fail_json(msg='Failed refresh: {0}'.format(e)) | ||
|
||
listing = sp.findall(EmailServer) | ||
|
||
spec = { | ||
'name': module.params['name'], | ||
'display_name': module.params['display_name'], | ||
'from': module.params['from_email'], | ||
'to': module.params['to_email'], | ||
'also_to': module.params['also_to_email'], | ||
'email_gateway': module.params['email_gateway'], | ||
} | ||
obj = EmailServer(**spec) | ||
sp.add(obj) | ||
|
||
changed = helper.apply_state(obj, listing, module) | ||
module.exit_json(changed=changed, msg='Done') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |