Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_logging.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_logging
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_logging
18 version_added: 2.1.0
19 notes:
20 - Supports C(check_mode).
21 short_description: Manage logging configuration on SONiC.
22 description:
23 - This module provides configuration management of logging for devices running SONiC.
24 author: "M. Zhang (@mingjunzhang2019)"
25 options:
26 config:
27 description:
28 - Specifies logging related configurations.
29 type: dict
30 suboptions:
31 remote_servers:
32 type: list
33 elements: dict
34 description:
35 - Remote logging sever configuration.
36 suboptions:
37 host:
38 type: str
39 description:
40 - IPv4/IPv6 address or host name of the remote logging server.
41 required: true
42 remote_port:
43 type: int
44 description:
45 - Destination port number for logging messages sent to the server.
46 source_interface:
47 type: str
48 description:
49 - Source interface used as source ip for sending logging packets.
50 message_type:
51 type: str
52 description:
53 - Type of messages that remote server receives. Defaults to "log" value.
54 choices:
55 - log
56 - event
57 - audit
58 - auditd-system
59 severity:
60 version_added: 3.1.0
61 type: str
62 description:
63 - The log severity filter for remote syslog server. Defaults to "notice" value.
64 choices:
65 - debug
66 - info
67 - notice
68 - warning
69 - error
70 - critical
71 - alert
72 - emergency
73 protocol:
74 type: str
75 description:
76 - Type of the protocol for sending the messages. Defaults to "UDP" value.
77 choices:
78 - TCP
79 - TLS
80 - UDP
81 vrf:
82 type: str
83 description:
84 - VRF name used by remote logging server.
85 security_profile:
86 type: str
87 version_added: 3.1.0
88 description:
89 - Specifies the security profile name for the global syslog settings.
90 state:
91 description:
92 - The state of the configuration after module completion.
93 type: str
94 choices:
95 - merged
96 - replaced
97 - overridden
98 - deleted
99 default: merged
100 """
101
102 EXAMPLES = """
103 # Using "deleted" state
104 #
105 # Before state:
106 # -------------
107 #
108 # sonic# show logging servers
109 # ----------------------------------------------------------------------------------------------------------
110 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
111 # ----------------------------------------------------------------------------------------------------------
112 # 10.11.0.2 5 Ethernet24 - event notice udp
113 # 10.11.1.1 616 Ethernet8 - log alert tcp
114 # log1.dell.com 6 Ethernet28 - audit notice udp
115 # 10.11.1.2 116 Ethernet6 - log notice tls
116 #
117 # sonic# show running-configuration | grep logging
118 # !
119 # logging security-profile default
120 # !
121
122 - name: Delete logging server configuration
123 sonic_logging:
124 config:
125 remote_servers:
126 - host: 10.11.0.2
127 - host: log1.dell.com
128 - host: 10.11.1.1
129 message_type: log
130 protocol: tcp
131 source_interface: Ethernet8
132 severity: alert
133 security_profile: "default"
134 state: deleted
135
136 # After state:
137 # ------------
138 #
139 # sonic# show logging servers
140 # ----------------------------------------------------------------------------------------------------------
141 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
142 # ----------------------------------------------------------------------------------------------------------
143 # 10.11.1.1 616 - - log notice udp
144 # 10.11.1.2 116 Ethernet6 - log notice tls
145 #
146 # sonic# show running-configuration | grep logging
147 # sonic#
148 #
149 # Using "merged" state
150 #
151 # Before state:
152 # -------------
153 #
154 # sonic# show logging servers
155 # ----------------------------------------------------------------------------------------------------------
156 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
157 # ----------------------------------------------------------------------------------------------------------
158 # 10.11.1.1 616 Ethernet8 - log notice tcp
159 #
160 # sonic# show running-configuration | grep logging
161 # sonic#
162 - name: Merge logging server configuration
163 sonic_logging:
164 config:
165 remote_servers:
166 - host: 10.11.0.2
167 remote_port: 5
168 protocol: TCP
169 source_interface: Ethernet24
170 message_type: event
171 - host: 10.11.0.1
172 remote_port: 4
173 protocol: TLS
174 source_interface: Ethernet2
175 - host: 10.11.1.1
176 severity: error
177 - host: log1.dell.com
178 remote_port: 6
179 protocol: udp
180 source_interface: Ethernet28
181 message_type: audit
182 security_profile: "default"
183 state: merged
184
185 # After state:
186 # ------------
187 # sonic# show logging servers
188 # ----------------------------------------------------------------------------------------------------------
189 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
190 # ----------------------------------------------------------------------------------------------------------
191 # 10.11.0.2 5 Ethernet24 - event notice udp
192 # 10.11.0.1 4 Ethernet2 - log notice tls
193 # 10.11.1.1 616 Ethernet8 - log error tcp
194 # log1.dell.com 6 Ethernet28 - audit notice udp
195 # sonic# show running-configuration | grep logging
196 # !
197 # logging security-profile default
198 # !
199 #
200 #
201 # Using "overridden" state
202 #
203 # Before state:
204 # -------------
205 #
206 # sonic# show logging servers
207 # ----------------------------------------------------------------------------------------------------------
208 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
209 # ----------------------------------------------------------------------------------------------------------
210 # 10.11.1.1 616 Ethernet8 - log notice tcp
211 # 10.11.1.2 626 Ethernet16 - event emergency udp
212 # 10.11.1.3 626 Ethernet14 - log notice tls
213 #
214 # sonic# show running-configuration | grep logging
215 # !
216 # logging security-profile default
217 # !
218 - name: Override logging server configuration
219 sonic_logging:
220 config:
221 remote_servers:
222 - host: 10.11.1.2
223 remote_port: 622
224 protocol: TCP
225 source_interface: Ethernet24
226 message_type: audit
227 severity: alert
228 state: overridden
229 #
230 # After state:
231 # ------------
232 # sonic# show logging servers
233 # ----------------------------------------------------------------------------------------------------------
234 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
235 # ----------------------------------------------------------------------------------------------------------
236 # 10.11.1.2 622 Ethernet24 - audit alert tcp
237 # sonic# show running-configuration | grep logging
238 # sonic#
239 #
240 # Using "replaced" state
241 #
242 # Before state:
243 # -------------
244 #
245 # sonic# show logging servers
246 # ----------------------------------------------------------------------------------------------------------
247 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
248 # ----------------------------------------------------------------------------------------------------------
249 # 10.11.1.1 616 Ethernet8 - log notice tcp
250 # 10.11.1.2 626 Ethernet16 - event notice udp
251 #
252 # sonic# show running-configuration | grep logging
253 # sonic#
254 - name: Replace logging server configuration
255 sonic_logging:
256 config:
257 remote_servers:
258 - host: 10.11.1.2
259 remote_port: 622
260 protocol: UDP
261 message_type: audit
262 severity: debug
263 security_profile: "default"
264 state: replaced
265 #
266 # After state:
267 # ------------
268 #
269 # "MESSAGE-TYPE" has default value of "log"
270 #
271 # ----------------------------------------------------------------------------------------------------------
272 # HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
273 # ----------------------------------------------------------------------------------------------------------
274 # 10.11.1.1 616 Ethernet8 - log notice tcp
275 # 10.11.1.2 622 - - audit debug udp
276 # sonic# show running-configuration | grep logging
277 # !
278 # logging security-profile default
279 # !
280 #
281 """
282
283 RETURN = """
284 before:
285 description: The configuration prior to the module invocation.
286 type: list
287 returned: always
288 sample: >
289 The configuration returned will always be in the same format
290 as the parameters above.
291 after:
292 description: The resulting configuration module invocation.
293 returned: when changed
294 type: list
295 sample: >
296 The configuration returned will always be in the same format
297 as the parameters above.
298 after_generated:
299 description: The generated configuration module invocation.
300 returned: when C(check_mode)
301 type: list
302 sample: >
303 The configuration returned will always be in the same format
304 as the parameters above.
305 commands:
306 description: The set of commands pushed to the remote device.
307 returned: always
308 type: list
309 sample: ['command 1', 'command 2', 'command 3']
310 """
311
312
313 from ansible.module_utils.basic import AnsibleModule
314 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.logging.logging import LoggingArgs
315 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.logging.logging import Logging
316
317
318 def main():
319 """
320 Main entry point for module execution
321
322 :returns: the result form module invocation
323 """
324 module = AnsibleModule(argument_spec=LoggingArgs.argument_spec,
325 supports_check_mode=True)
326
327 result = Logging(module).execute_module()
328 module.exit_json(**result)
329
330
331 if __name__ == '__main__':
332 main()