Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_system_snmp_user.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_system_snmp_user
15 short_description: SNMP user configuration.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 system_snmp_user:
22 description: The top level parameters set.
23 required: false
24 type: dict
25 suboptions:
26 auth_proto:
27 aliases: ['auth-proto']
28 type: str
29 description:
30 - Authentication protocol.
31 - md5 - HMAC-MD5-96 authentication protocol.
32 - sha - HMAC-SHA-96 authentication protocol.
33 choices: ['md5', 'sha', 'sha224', 'sha256', 'sha384', 'sha512']
34 auth_pwd:
35 aliases: ['auth-pwd']
36 type: raw
37 description: (list) Password for authentication protocol.
38 events:
39 type: list
40 elements: str
41 description:
42 - SNMP notifications
43 - disk_low - Disk usage too high.
44 - ha_switch - HA switch.
45 - intf_ip_chg - Interface IP address changed.
46 - sys_reboot - System reboot.
47 - cpu_high - CPU usage too high.
48 - mem_low - Available memory is low.
49 - log-alert - Log base alert message.
50 - log-rate - High incoming log rate detected.
51 - log-data-rate - High incoming log data rate detected.
52 - lic-gbday - High licensed log GB/day detected.
53 - lic-dev-quota - High licensed device quota detected.
54 - cpu-high-exclude-nice - CPU usage exclude NICE threshold.
55 choices: ['disk_low', 'ha_switch', 'intf_ip_chg', 'sys_reboot', 'cpu_high',
56 'mem_low', 'log-alert', 'log-rate', 'log-data-rate', 'lic-gbday',
57 'lic-dev-quota', 'cpu-high-exclude-nice']
58 name:
59 type: str
60 description: SNMP user name.
61 required: true
62 notify_hosts:
63 aliases: ['notify-hosts']
64 type: str
65 description: Hosts to send notifications
66 notify_hosts6:
67 aliases: ['notify-hosts6']
68 type: str
69 description: IPv6 hosts to send notifications
70 priv_proto:
71 aliases: ['priv-proto']
72 type: str
73 description:
74 - Privacy
75 - aes - CFB128-AES-128 symmetric encryption protocol.
76 - des - CBC-DES symmetric encryption protocol.
77 choices: ['aes', 'des', 'aes256', 'aes256cisco']
78 priv_pwd:
79 aliases: ['priv-pwd']
80 type: raw
81 description: (list) Password for privacy
82 queries:
83 type: str
84 description:
85 - Enable/disable queries for this user.
86 - disable - Disable setting.
87 - enable - Enable setting.
88 choices: ['disable', 'enable']
89 query_port:
90 aliases: ['query-port']
91 type: int
92 description: SNMPv3 query port.
93 security_level:
94 aliases: ['security-level']
95 type: str
96 description:
97 - Security level for message authentication and encryption.
98 - no-auth-no-priv - Message with no authentication and no privacy
99 - auth-no-priv - Message with authentication but no privacy
100 - auth-priv - Message with authentication and privacy
101 choices: ['no-auth-no-priv', 'auth-no-priv', 'auth-priv']
102 notify_port:
103 aliases: ['notify-port']
104 type: int
105 description: Notify port.
106 '''
107
108 EXAMPLES = '''
109 - name: Example playbook
110 hosts: fortimanagers
111 gather_facts: false
112 connection: httpapi
113 vars:
114 ansible_httpapi_use_ssl: true
115 ansible_httpapi_validate_certs: false
116 ansible_httpapi_port: 443
117 tasks:
118 - name: SNMP user configuration.
119 fortinet.fortimanager.fmgr_system_snmp_user:
120 bypass_validation: false
121 state: present
122 system_snmp_user:
123 auth_proto: md5 # <value in [md5, sha]>
124 auth_pwd: fortinet
125 events:
126 - disk_low
127 - ha_switch
128 - intf_ip_chg
129 - sys_reboot
130 - cpu_high
131 - mem_low
132 - log-alert
133 - log-rate
134 - log-data-rate
135 - lic-gbday
136 - lic-dev-quota
137 - cpu-high-exclude-nice
138 name: ansible-test-snmpuser
139 queries: disable
140 security_level: no-auth-no-priv # <value in [no-auth-no-priv, auth-no-priv, auth-priv]>
141
142 - name: Gathering fortimanager facts
143 hosts: fortimanagers
144 gather_facts: false
145 connection: httpapi
146 vars:
147 ansible_httpapi_use_ssl: true
148 ansible_httpapi_validate_certs: false
149 ansible_httpapi_port: 443
150 tasks:
151 - name: Retrieve all the SNMP users
152 fortinet.fortimanager.fmgr_fact:
153 facts:
154 selector: "system_snmp_user"
155 params:
156 user: "your_value"
157 '''
158
159 RETURN = '''
160 meta:
161 description: The result of the request.
162 type: dict
163 returned: always
164 contains:
165 request_url:
166 description: The full url requested.
167 returned: always
168 type: str
169 sample: /sys/login/user
170 response_code:
171 description: The status of api request.
172 returned: always
173 type: int
174 sample: 0
175 response_data:
176 description: The api response.
177 type: list
178 returned: always
179 response_message:
180 description: The descriptive message of the api response.
181 type: str
182 returned: always
183 sample: OK.
184 system_information:
185 description: The information of the target system.
186 type: dict
187 returned: always
188 rc:
189 description: The status the request.
190 type: int
191 returned: always
192 sample: 0
193 version_check_warning:
194 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
195 type: list
196 returned: complex
197 '''
198 from ansible.module_utils.basic import AnsibleModule
199 from ansible.module_utils.connection import Connection
200 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
201 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
202
203
204 def main():
205 urls_list = [
206 '/cli/global/system/snmp/user'
207 ]
208 module_arg_spec = {
209 'system_snmp_user': {
210 'type': 'dict', 'v_range': [['6.0.0', '']],
211 'options': {
212 'auth-proto': {'choices': ['md5', 'sha', 'sha224', 'sha256', 'sha384', 'sha512'], 'type': 'str'},
213 'auth-pwd': {'type': 'raw'},
214 'events': {
215 'type': 'list',
216 'choices': [
217 'disk_low', 'ha_switch', 'intf_ip_chg', 'sys_reboot', 'cpu_high', 'mem_low', 'log-alert', 'log-rate', 'log-data-rate',
218 'lic-gbday', 'lic-dev-quota', 'cpu-high-exclude-nice'
219 ],
220 'elements': 'str'
221 },
222 'name': {'required': True, 'type': 'str'},
223 'notify-hosts': {'type': 'str'},
224 'notify-hosts6': {'type': 'str'},
225 'priv-proto': {'choices': ['aes', 'des', 'aes256', 'aes256cisco'], 'type': 'str'},
226 'priv-pwd': {'type': 'raw'},
227 'queries': {'choices': ['disable', 'enable'], 'type': 'str'},
228 'query-port': {'type': 'int'},
229 'security-level': {'choices': ['no-auth-no-priv', 'auth-no-priv', 'auth-priv'], 'type': 'str'},
230 'notify-port': {'v_range': [['7.2.10', '7.2.12'], ['7.4.6', '7.4.10'], ['7.6.2', '']], 'type': 'int'}
231 }
232 }
233 }
234
235 module_option_spec = get_module_arg_spec('full crud')
236 module_arg_spec.update(module_option_spec)
237 check_galaxy_version(module_arg_spec)
238 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_snmp_user'),
239 supports_check_mode=True)
240 if not module._socket_path:
241 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
242 connection = Connection(module._socket_path)
243 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
244 'name', 'data', module, connection)
245 fmgr.process_crud()
246 module.exit_json(meta=module.params)
247
248
249 if __name__ == '__main__':
250 main()