Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snc 39092 logging enhancement specific logging server attribute deletion #486

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- sonic_logging - Adding the ability to delete a specific attribute of a logging server into the logging module (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/486).
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, **kwargs):
'options': {
'host': {'required': True,
'type': 'str'},
'remote_port': {'type': 'int'},
'message_type': {'choices': ['log', 'event', 'audit', 'auditd-system'],
'type': 'str'},
'severity': {'choices': ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'],
'type': 'str'},
'remote_port': {'type': 'int'},
'source_interface': {'type': 'str'},
'vrf': {'type': 'str'},
'protocol': {'choices': ['TCP', 'UDP', 'TLS'],
'type': 'str'},
'source_interface': {'type': 'str'},
'vrf': {'type': 'str'}
},
'type': 'list'
}
Expand Down
47 changes: 26 additions & 21 deletions plugins/module_utils/network/sonic/config/logging/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
DEFAULT_REMOTE_PORT = 514
DEFAULT_LOG_TYPE = 'log'
DEFAULT_PROTOCOL = 'UDP'
DEFAULT_SEVERITY = 'notice'

TEST_KEYS = [
{
Expand Down Expand Up @@ -156,7 +157,6 @@ def set_state(self, want, have):
"""
state = self._module.params['state']

self.validate_want(want, state)
self.preprocess_want(want, state)

if state == 'deleted':
Expand Down Expand Up @@ -328,23 +328,6 @@ def get_replaced_config(self, have, want):
replaced_config['remote_servers'] = replaced_servers
return replaced_config

def validate_want(self, want, state):

if state == 'deleted':

if 'remote_servers' in want and want['remote_servers'] is not None:
for server in want['remote_servers']:
source_interface_config = server.get('source_interface', None)
remote_port_config = server.get('remote_port', None)
protocol_config = server.get('protocol', None)
severity_config = server.get('severity', None)
message_type_config = server.get('message_type', None)
vrf_config = server.get('vrf', None)
if source_interface_config or remote_port_config or \
message_type_config or vrf_config or protocol_config or severity_config:
err_msg = "Logging remote_server parameter(s) can not be deleted."
self._module.fail_json(msg=err_msg, code=405)

def preprocess_want(self, want, state):

if state == 'merged':
Expand Down Expand Up @@ -380,6 +363,8 @@ def preprocess_want(self, want, state):
server['message_type'] = DEFAULT_LOG_TYPE
if 'protocol' in server and not server['protocol']:
server['protocol'] = DEFAULT_PROTOCOL
if 'severity' in server and not server['severity']:
server['severity'] = DEFAULT_SEVERITY

def get_merge_requests(self, configs, have):

Expand Down Expand Up @@ -453,9 +438,29 @@ def get_delete_servers_requests(self, configs):
for config in configs:
server_host = config['host']
url = 'data/openconfig-system:system/logging/remote-servers/remote-server={0}'.format(server_host)
request = {"path": url, "method": method}
requests.append(request)

if not (config.get("vrf") or config.get("source_interface") or config.get("message_type") or
config.get("remote_port") or config.get("protocol") or config.get("severity")):
request = {"path": url, "method": method}
requests.append(request)
else:
if config.get('source_interface'):
request = {"path": "{}/config/openconfig-system-ext:source-interface".format(url), "method": method}
requests.append(request)
if config.get("message_type"):
request = {"path": "{}/config/openconfig-system-ext:message-type".format(url), "method": method}
requests.append(request)
if config.get("vrf"):
request = {"path": "{}/config/openconfig-system-ext:vrf-name".format(url), "method": method}
requests.append(request)
if config.get("remote_port"):
request = {"path": "{}/config/remote-port".format(url), "method": method}
requests.append(request)
if config.get("protocol"):
request = {"path": "{}/config/openconfig-system-ext:protocol".format(url), "method": method}
requests.append(request)
if config.get("severity"):
request = {"path": "{}/config/openconfig-system-ext:severity".format(url), "method": method}
requests.append(request)
return requests

def get_delete_all_servers_requests(self):
Expand Down
108 changes: 56 additions & 52 deletions plugins/modules/sonic_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@
type: int
description:
- Destination port number for logging messages sent to the server.
- remote_port can not be deleted.
source_interface:
type: str
description:
- Source interface used as source ip for sending logging packets.
- source_interface can not be deleted.
message_type:
type: str
description:
- Type of messages that remote server receives.
- message_type can not be deleted.
- Type of messages that remote server receives. Defaults to "log" value.
choices:
- log
- event
Expand All @@ -81,7 +78,7 @@
version_added: 3.1.0
type: str
description:
- The log severity filter for remote syslog server.
- The log severity filter for remote syslog server. Defaults to "notice" value.
choices:
- debug
- info
Expand All @@ -94,7 +91,7 @@
protocol:
type: str
description:
- Type of the protocol for sending the messages.
- Type of the protocol for sending the messages. Defaults to "UDP" value.
choices:
- TCP
- TLS
Expand All @@ -121,31 +118,36 @@
# -------------
#
#sonic# show logging servers
#---------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#---------------------------------------------------------------------------------------
#10.11.0.2 5 Ethernet24 - event udp
#10.11.1.1 616 Ethernet8 - log tcp
#log1.dell.com 6 Ethernet28 - audit udp
#10.11.1.2 116 Ethernet6 - log tls
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.0.2 5 Ethernet24 - event notice udp
#10.11.1.1 616 Ethernet8 - log alert tcp
#log1.dell.com 6 Ethernet28 - audit notice udp
#10.11.1.2 116 Ethernet6 - log notice tls
#
- name: Delete logging server configuration
sonic_logging:
config:
remote_servers:
- host: 10.11.0.2
- host: log1.dell.com
- host: 10.11.1.1
message_type: log
protocol: tcp
source_interface: Ethernet8
severity: alert
state: deleted

# After state:
# ------------
#
#sonic# show logging servers
#---------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#---------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log tcp
#10.11.1.2 116 Ethernet6 - log tls
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.1 616 - - log notice udp
#10.11.1.2 116 Ethernet6 - log notice tls
#
#
# Using merged
Expand All @@ -154,10 +156,10 @@
# -------------
#
#sonic# show logging servers
#--------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#--------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log tcp
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log notice tcp
#
- name: Merge logging server configuration
sonic_logging:
Expand All @@ -172,6 +174,8 @@
remote_port: 4
protocol: TLS
source_interface: Ethernet2
- host: 10.11.1.1
severity: error
- host: log1.dell.com
remote_port: 6
protocol: udp
Expand All @@ -181,15 +185,14 @@

# After state:
# ------------
#
#sonic# show logging servers
#-------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#-------------------------------------------------------------------------------------
#10.11.0.2 5 Ethernet24 - event udp
#10.11.0.1 4 Ethernet2 - log tls
#10.11.1.1 616 Ethernet8 - log tcp
#log1.dell.com 6 Ethernet28 - audit udp
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.0.2 5 Ethernet24 - event notice udp
#10.11.0.1 4 Ethernet2 - log notice tls
#10.11.1.1 616 Ethernet8 - log error tcp
#log1.dell.com 6 Ethernet28 - audit notice udp
#
#
# Using overridden
Expand All @@ -198,12 +201,12 @@
# -------------
#
#sonic# show logging servers
#--------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#--------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log tcp
#10.11.1.2 626 Ethernet16 - event udp
#10.11.1.3 626 Ethernet14 - log tls
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log notice tcp
#10.11.1.2 626 Ethernet16 - event emergency udp
#10.11.1.3 626 Ethernet14 - log notice tls
#
- name: Override logging server configuration
sonic_logging:
Expand All @@ -213,29 +216,29 @@
remote_port: 622
protocol: TCP
source_interface: Ethernet24
message_type: auditd-system
message_type: audit
severity: alert
state: overridden
#
# After state:
# ------------
#
#sonic# show logging servers
#--------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#--------------------------------------------------------------------------------------
#10.11.1.2 622 Ethernet24 - auditd-system tcp
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.2 622 Ethernet24 - audit alert tcp
#
# Using replaced
#
# Before state:
# -------------
#
#sonic# show logging servers
#--------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#--------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log tcp
#10.11.1.2 626 Ethernet16 - event udp
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log notice tcp
#10.11.1.2 626 Ethernet16 - event notice udp
#
- name: Replace logging server configuration
sonic_logging:
Expand All @@ -245,6 +248,7 @@
remote_port: 622
protocol: UDP
message_type: audit
severity: debug
state: replaced
#
# After state:
Expand All @@ -253,11 +257,11 @@
# "MESSAGE-TYPE" has default value of "log"
#
#sonic# show logging servers
#--------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE PROTOCOL
#--------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log tcp
#10.11.1.2 622 - - audit udp
#----------------------------------------------------------------------------------------------------------
#HOST PORT SOURCE-INTERFACE VRF MESSAGE-TYPE SEVERITY PROTOCOL
#----------------------------------------------------------------------------------------------------------
#10.11.1.1 616 Ethernet8 - log notice tcp
#10.11.1.2 622 - - audit debug udp
#
"""
RETURN = """
Expand Down
Loading
Loading