Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_system_snmp_community.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_community
15 short_description: SNMP community 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_community:
22 description: The top level parameters set.
23 required: false
24 type: dict
25 suboptions:
26 events:
27 type: list
28 elements: str
29 description:
30 - SNMP trap events.
31 - disk_low - Disk usage too high.
32 - ha_switch - HA switch.
33 - intf_ip_chg - Interface IP address changed.
34 - sys_reboot - System reboot.
35 - cpu_high - CPU usage too high.
36 - mem_low - Available memory is low.
37 - log-alert - Log base alert message.
38 - log-rate - High incoming log rate detected.
39 - log-data-rate - High incoming log data rate detected.
40 - lic-gbday - High licensed log GB/day detected.
41 - lic-dev-quota - High licensed device quota detected.
42 - cpu-high-exclude-nice - CPU usage exclude NICE threshold.
43 choices: ['disk_low', 'ha_switch', 'intf_ip_chg', 'sys_reboot', 'cpu_high',
44 'mem_low', 'log-alert', 'log-rate', 'log-data-rate', 'lic-gbday',
45 'lic-dev-quota', 'cpu-high-exclude-nice']
46 hosts:
47 type: list
48 elements: dict
49 description: Hosts.
50 suboptions:
51 id:
52 type: int
53 description: Host entry ID.
54 interface:
55 type: str
56 description: Allow interface name.
57 ip:
58 type: str
59 description: Allow host IP address.
60 hosts6:
61 type: list
62 elements: dict
63 description: Hosts6.
64 suboptions:
65 id:
66 type: int
67 description: Host entry ID.
68 interface:
69 type: str
70 description: Allow interface name.
71 ip:
72 type: str
73 description: Allow host IP address.
74 id:
75 type: int
76 description: Community ID.
77 required: true
78 name:
79 type: str
80 description: Community name.
81 query_v1_port:
82 type: int
83 description: SNMP v1 query port.
84 query_v1_status:
85 type: str
86 description:
87 - Enable/disable SNMP v1 query.
88 - disable - Disable setting.
89 - enable - Enable setting.
90 choices: ['disable', 'enable']
91 query_v2c_port:
92 type: int
93 description: SNMP v2c query port.
94 query_v2c_status:
95 type: str
96 description:
97 - Enable/disable SNMP v2c query.
98 - disable - Disable setting.
99 - enable - Enable setting.
100 choices: ['disable', 'enable']
101 status:
102 type: str
103 description:
104 - Enable/disable community.
105 - disable - Disable setting.
106 - enable - Enable setting.
107 choices: ['disable', 'enable']
108 trap_v1_rport:
109 type: int
110 description: SNMP v1 trap remote port.
111 trap_v1_status:
112 type: str
113 description:
114 - Enable/disable SNMP v1 trap.
115 - disable - Disable setting.
116 - enable - Enable setting.
117 choices: ['disable', 'enable']
118 trap_v2c_rport:
119 type: int
120 description: SNMP v2c trap remote port.
121 trap_v2c_status:
122 type: str
123 description:
124 - Enable/disable SNMP v2c trap.
125 - disable - Disable setting.
126 - enable - Enable setting.
127 choices: ['disable', 'enable']
128 '''
129
130 EXAMPLES = '''
131 - name: Example playbook
132 hosts: fortimanagers
133 gather_facts: false
134 connection: httpapi
135 vars:
136 ansible_httpapi_use_ssl: true
137 ansible_httpapi_validate_certs: false
138 ansible_httpapi_port: 443
139 tasks:
140 - name: SNMP community configuration.
141 fortinet.fortimanager.fmgr_system_snmp_community:
142 bypass_validation: false
143 state: present
144 system_snmp_community:
145 id: 1
146 name: ansible-test-snmp
147 status: disable
148
149 - name: Gathering fortimanager facts
150 hosts: fortimanagers
151 gather_facts: false
152 connection: httpapi
153 vars:
154 ansible_httpapi_use_ssl: true
155 ansible_httpapi_validate_certs: false
156 ansible_httpapi_port: 443
157 tasks:
158 - name: Retrieve all the SNMP communities
159 fortinet.fortimanager.fmgr_fact:
160 facts:
161 selector: "system_snmp_community"
162 params:
163 community: "your_value"
164 '''
165
166 RETURN = '''
167 meta:
168 description: The result of the request.
169 type: dict
170 returned: always
171 contains:
172 request_url:
173 description: The full url requested.
174 returned: always
175 type: str
176 sample: /sys/login/user
177 response_code:
178 description: The status of api request.
179 returned: always
180 type: int
181 sample: 0
182 response_data:
183 description: The api response.
184 type: list
185 returned: always
186 response_message:
187 description: The descriptive message of the api response.
188 type: str
189 returned: always
190 sample: OK.
191 system_information:
192 description: The information of the target system.
193 type: dict
194 returned: always
195 rc:
196 description: The status the request.
197 type: int
198 returned: always
199 sample: 0
200 version_check_warning:
201 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
202 type: list
203 returned: complex
204 '''
205 from ansible.module_utils.basic import AnsibleModule
206 from ansible.module_utils.connection import Connection
207 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
208 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
209
210
211 def main():
212 urls_list = [
213 '/cli/global/system/snmp/community'
214 ]
215 module_arg_spec = {
216 'system_snmp_community': {
217 'type': 'dict', 'v_range': [['6.0.0', '']],
218 'options': {
219 'events': {
220 'type': 'list',
221 'choices': [
222 'disk_low', 'ha_switch', 'intf_ip_chg', 'sys_reboot', 'cpu_high', 'mem_low', 'log-alert', 'log-rate', 'log-data-rate',
223 'lic-gbday', 'lic-dev-quota', 'cpu-high-exclude-nice'
224 ],
225 'elements': 'str'
226 },
227 'hosts': {'type': 'list', 'options': {'id': {'type': 'int'}, 'interface': {'type': 'str'}, 'ip': {'type': 'str'}}, 'elements': 'dict'},
228 'hosts6': {'type': 'list', 'options': {'id': {'type': 'int'}, 'interface': {'type': 'str'}, 'ip': {'type': 'str'}}, 'elements': 'dict'},
229 'id': {'required': True, 'type': 'int'},
230 'name': {'type': 'str'},
231 'query_v1_port': {'type': 'int'},
232 'query_v1_status': {'choices': ['disable', 'enable'], 'type': 'str'},
233 'query_v2c_port': {'type': 'int'},
234 'query_v2c_status': {'choices': ['disable', 'enable'], 'type': 'str'},
235 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
236 'trap_v1_rport': {'type': 'int'},
237 'trap_v1_status': {'choices': ['disable', 'enable'], 'type': 'str'},
238 'trap_v2c_rport': {'type': 'int'},
239 'trap_v2c_status': {'choices': ['disable', 'enable'], 'type': 'str'}
240 }
241 }
242 }
243
244 module_option_spec = get_module_arg_spec('full crud')
245 module_arg_spec.update(module_option_spec)
246 check_galaxy_version(module_arg_spec)
247 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_snmp_community'),
248 supports_check_mode=True)
249 if not module._socket_path:
250 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
251 connection = Connection(module._socket_path)
252 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
253 'id', 'data', module, connection)
254 fmgr.process_crud()
255 module.exit_json(meta=module.params)
256
257
258 if __name__ == '__main__':
259 main()