Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_syslog_source.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Tim Cragg <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_syslog_source
16 short_description: Manage Syslog Source objects (syslog:Src)
17 description:
18 - Manage Syslog Source objects.
19 options:
20 name:
21 description:
22 - Name of the Syslog Source policy
23 type: str
24 aliases: [ syslog_src, syslog_source ]
25 include:
26 description:
27 - List of message types to include
28 - The APIC defaults to C(faults) when unset during creation.
29 type: list
30 elements: str
31 choices: [ audit, events, faults, session ]
32 min_severity:
33 description:
34 - Minimum Severity of message to include
35 type: str
36 choices: [ alerts, critical, debugging, emergencies, errors, information, notifications, warnings ]
37 destination_group:
38 description:
39 - Name of an existing syslog group
40 type: str
41 state:
42 description:
43 - Use C(present) or C(absent) for adding or removing.
44 - Use C(query) for listing an object or multiple objects.
45 type: str
46 default: present
47 choices: [ absent, present, query ]
48 extends_documentation_fragment:
49 - cisco.aci.aci
50 - cisco.aci.annotation
51
52 seealso:
53 - name: APIC Management Information Model reference
54 description: More information about the internal APIC class B(syslog:Src).
55 link: https://developer.cisco.com/docs/apic-mim-ref/
56 author:
57 - Tim Cragg (@timcragg)
58 """
59
60 EXAMPLES = r"""
61 - name: Add a new syslog source
62 cisco.aci.aci_syslog_source:
63 host: apic
64 username: admin
65 password: SomeSecretPassword
66 name: my_syslog_src
67 include:
68 - audit
69 - events
70 - faults
71 min_severity: errors
72 destination_group: my_syslog_group
73 state: present
74 delegate_to: localhost
75
76 - name: Remove an existing syslog source
77 cisco.aci.aci_syslog_source:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 name: my_syslog_src
82 state: absent
83 delegate_to: localhost
84
85 - name: Query all syslog sources
86 cisco.aci.aci_syslog_source:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 state: query
91 delegate_to: localhost
92 register: query_result
93
94 - name: Query a specific syslog source
95 cisco.aci.aci_syslog_source:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 name: my_syslog_src
100 state: query
101 delegate_to: localhost
102 register: query_result
103 """
104
105 RETURN = r"""
106 current:
107 description: The existing configuration from the APIC after the module has finished
108 returned: success
109 type: list
110 sample:
111 [
112 {
113 "fvTenant": {
114 "attributes": {
115 "descr": "Production environment",
116 "dn": "uni/tn-production",
117 "name": "production",
118 "nameAlias": "",
119 "ownerKey": "",
120 "ownerTag": ""
121 }
122 }
123 }
124 ]
125 error:
126 description: The error information as returned from the APIC
127 returned: failure
128 type: dict
129 sample:
130 {
131 "code": "122",
132 "text": "unknown managed object class foo"
133 }
134 raw:
135 description: The raw output returned by the APIC REST API (xml or json)
136 returned: parse error
137 type: str
138 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
139 sent:
140 description: The actual/minimal configuration pushed to the APIC
141 returned: info
142 type: list
143 sample:
144 {
145 "fvTenant": {
146 "attributes": {
147 "descr": "Production environment"
148 }
149 }
150 }
151 previous:
152 description: The original configuration from the APIC before the module has started
153 returned: info
154 type: list
155 sample:
156 [
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production",
161 "dn": "uni/tn-production",
162 "name": "production",
163 "nameAlias": "",
164 "ownerKey": "",
165 "ownerTag": ""
166 }
167 }
168 }
169 ]
170 proposed:
171 description: The assembled configuration from the user-provided parameters
172 returned: info
173 type: dict
174 sample:
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production environment",
179 "name": "production"
180 }
181 }
182 }
183 filter_string:
184 description: The filter string used for the request
185 returned: failure or debug
186 type: str
187 sample: ?rsp-prop-include=config-only
188 method:
189 description: The HTTP method used for the request to the APIC
190 returned: failure or debug
191 type: str
192 sample: POST
193 response:
194 description: The HTTP response from the APIC
195 returned: failure or debug
196 type: str
197 sample: OK (30 bytes)
198 status:
199 description: The HTTP status from the APIC
200 returned: failure or debug
201 type: int
202 sample: 200
203 url:
204 description: The HTTP url used for the request to the APIC
205 returned: failure or debug
206 type: str
207 sample: https://10.11.12.13/api/mo/uni/tn-production.json
208 """
209
210 from ansible.module_utils.basic import AnsibleModule
211 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
212
213
214 def main():
215 argument_spec = aci_argument_spec()
216 argument_spec.update(aci_annotation_spec())
217 argument_spec.update(
218 name=dict(type="str", aliases=["syslog_src", "syslog_source"]),
219 include=dict(type="list", elements="str", choices=["audit", "events", "faults", "session"]),
220 min_severity=dict(type="str", choices=["alerts", "critical", "debugging", "emergencies", "errors", "information", "notifications", "warnings"]),
221 destination_group=dict(type="str"),
222 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
223 )
224
225 module = AnsibleModule(
226 argument_spec=argument_spec,
227 supports_check_mode=True,
228 required_if=[
229 ["state", "absent", ["name"]],
230 ["state", "present", ["name"]],
231 ],
232 )
233
234 name = module.params.get("name")
235 include = module.params.get("include")
236 min_severity = module.params.get("min_severity")
237 destination_group = module.params.get("destination_group")
238 state = module.params.get("state")
239
240 aci = ACIModule(module)
241 aci.construct_url(
242 root_class=dict(
243 aci_class="syslogSrc",
244 aci_rn="fabric/moncommon/slsrc-{0}".format(name),
245 module_object=name,
246 target_filter={"name": name},
247 ),
248 child_classes=["syslogRsDestGroup"],
249 )
250
251 aci.get_existing()
252
253 if state == "present":
254 class_config = dict(name=name, minSev=min_severity)
255 if include:
256 class_config["incl"] = ",".join(include)
257
258 aci.payload(
259 aci_class="syslogSrc",
260 class_config=class_config,
261 child_configs=[
262 dict(
263 syslogRsDestGroup=dict(
264 attributes=dict(tDn=("uni/fabric/slgroup-{0}".format(destination_group))),
265 ),
266 ),
267 ],
268 )
269
270 aci.get_diff(aci_class="syslogSrc")
271
272 aci.post_config()
273
274 elif state == "absent":
275 aci.delete_config()
276
277 aci.exit_json()
278
279
280 if __name__ == "__main__":
281 main()