| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage CheckPoint Firewall (c) 2019 |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
|
| 20 |
from __future__ import absolute_import, division, print_function |
| 21 |
|
| 22 |
__metaclass__ = type |
| 23 |
|
| 24 |
ANSIBLE_METADATA = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_show_logs |
| 33 |
short_description: Showing logs according to the given filter. |
| 34 |
description: |
| 35 |
- Showing logs according to the given filter. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R80.40 JHF management version. |
| 38 |
version_added: "2.0.0" |
| 39 |
author: "Or Soffer (@chkp-orso)" |
| 40 |
options: |
| 41 |
new_query: |
| 42 |
description: |
| 43 |
- Running a new query. |
| 44 |
type: dict |
| 45 |
suboptions: |
| 46 |
filter: |
| 47 |
description: |
| 48 |
- The filter as entered in SmartConsole/SmartView. |
| 49 |
type: str |
| 50 |
time_frame: |
| 51 |
description: |
| 52 |
- Specify the time frame to query logs. |
| 53 |
type: str |
| 54 |
choices: ['last-7-days', 'last-hour', 'today', 'last-24-hours', 'yesterday', 'this-week', 'this-month', 'last-30-days', 'all-time', 'custom'] |
| 55 |
custom_start: |
| 56 |
description: |
| 57 |
- This option is only applicable when using the custom time-frame option. |
| 58 |
type: str |
| 59 |
custom_end: |
| 60 |
description: |
| 61 |
- This option is only applicable when using the custom time-frame option. |
| 62 |
type: str |
| 63 |
max_logs_per_request: |
| 64 |
description: |
| 65 |
- Limit the number of logs to be retrieved. |
| 66 |
type: int |
| 67 |
top: |
| 68 |
description: |
| 69 |
- Top results configuration. |
| 70 |
type: dict |
| 71 |
suboptions: |
| 72 |
field: |
| 73 |
description: |
| 74 |
- The field on which the top command is executed. |
| 75 |
type: str |
| 76 |
choices: ['sources', 'destinations', 'services', 'actions', 'blades' , 'origins', 'users', 'applications'] |
| 77 |
count: |
| 78 |
description: |
| 79 |
- The number of results to retrieve. |
| 80 |
type: int |
| 81 |
type: |
| 82 |
description: |
| 83 |
- Type of logs to return. |
| 84 |
type: str |
| 85 |
choices: ['logs', 'audit'] |
| 86 |
log_servers: |
| 87 |
description: |
| 88 |
- List of IP's of logs servers to query. |
| 89 |
type: list |
| 90 |
elements: str |
| 91 |
query_id: |
| 92 |
description: |
| 93 |
- Get the next page of last run query with specified limit. |
| 94 |
type: str |
| 95 |
ignore_warnings: |
| 96 |
description: |
| 97 |
- Ignore warnings if exist. |
| 98 |
type: bool |
| 99 |
extends_documentation_fragment: check_point.mgmt.checkpoint_commands |
| 100 |
""" |
| 101 |
|
| 102 |
EXAMPLES = """ |
| 103 |
- name: show-logs |
| 104 |
cp_mgmt_show_logs: |
| 105 |
new_query: |
| 106 |
filter: blade:"Threat Emulation" |
| 107 |
max_logs_per_request: '2' |
| 108 |
time_frame: today |
| 109 |
""" |
| 110 |
|
| 111 |
RETURN = """ |
| 112 |
cp_mgmt_show_logs: |
| 113 |
description: The checkpoint show-logs output. |
| 114 |
returned: always. |
| 115 |
type: dict |
| 116 |
""" |
| 117 |
|
| 118 |
from ansible.module_utils.basic import AnsibleModule |
| 119 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 120 |
checkpoint_argument_spec_for_commands, |
| 121 |
api_command, |
| 122 |
) |
| 123 |
|
| 124 |
|
| 125 |
def main(): |
| 126 |
argument_spec = dict( |
| 127 |
new_query=dict( |
| 128 |
type="dict", |
| 129 |
options=dict( |
| 130 |
filter=dict(type="str"), |
| 131 |
time_frame=dict( |
| 132 |
type="str", |
| 133 |
choices=[ |
| 134 |
"last-7-days", |
| 135 |
"last-hour", |
| 136 |
"today", |
| 137 |
"last-24-hours", |
| 138 |
"yesterday", |
| 139 |
"this-week", |
| 140 |
"this-month", |
| 141 |
"last-30-days", |
| 142 |
"all-time", |
| 143 |
"custom", |
| 144 |
], |
| 145 |
), |
| 146 |
custom_start=dict(type="str"), |
| 147 |
custom_end=dict(type="str"), |
| 148 |
max_logs_per_request=dict(type="int"), |
| 149 |
top=dict( |
| 150 |
type="dict", |
| 151 |
options=dict( |
| 152 |
field=dict( |
| 153 |
type="str", |
| 154 |
choices=[ |
| 155 |
"sources", |
| 156 |
"destinations", |
| 157 |
"services", |
| 158 |
"actions", |
| 159 |
"blades", |
| 160 |
"origins", |
| 161 |
"users", |
| 162 |
"applications", |
| 163 |
], |
| 164 |
), |
| 165 |
count=dict(type="int"), |
| 166 |
), |
| 167 |
), |
| 168 |
type=dict(type="str", choices=["logs", "audit"]), |
| 169 |
log_servers=dict(type="list", elements="str"), |
| 170 |
), |
| 171 |
), |
| 172 |
query_id=dict(type="str"), |
| 173 |
ignore_warnings=dict(type="bool"), |
| 174 |
) |
| 175 |
argument_spec.update(checkpoint_argument_spec_for_commands) |
| 176 |
|
| 177 |
module = AnsibleModule(argument_spec=argument_spec) |
| 178 |
|
| 179 |
command = "show-logs" |
| 180 |
|
| 181 |
result = api_command(module, command) |
| 182 |
module.exit_json(**result) |
| 183 |
|
| 184 |
|
| 185 |
if __name__ == "__main__": |
| 186 |
main() |