diff --git a/dockers/docker-dhcp-server/Dockerfile.j2 b/dockers/docker-dhcp-server/Dockerfile.j2 index 0b6244d32e4..6ecc8a05e74 100755 --- a/dockers/docker-dhcp-server/Dockerfile.j2 +++ b/dockers/docker-dhcp-server/Dockerfile.j2 @@ -3,7 +3,6 @@ FROM docker-config-engine-bullseye-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}} ARG docker_container_name ARG image_version -RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive @@ -50,8 +49,6 @@ RUN cd /usr/local/sbin && rm -f kea-admin kea-ctrl-agent kea-dhcp-ddns kea-dhcp6 # Remove hook lib we don't need RUN cd /usr/local/lib/kea/hooks && rm -f libdhcp_bootp.so libdhcp_flex_option.so libdhcp_stat_cmds.so RUN pip3 install psutil -# TODO issue on remote rsyslog server in non-host container -RUN rm -f /etc/supervisor/conf.d/containercfgd.conf {% if docker_dhcp_server_debs.strip() -%} # Copy locally-built Debian package dependencies @@ -86,11 +83,10 @@ RUN apt-get clean -y && \ COPY ["docker_init.sh", "start.sh", "/usr/bin/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] -COPY ["rsyslog/rsyslog.conf.j2", "kea-dhcp4.conf.j2", "/usr/share/sonic/templates/"] +COPY ["kea-dhcp4.conf.j2", "/usr/share/sonic/templates/"] COPY ["critical_processes", "/etc/supervisor/"] COPY ["lease_update.sh", "/etc/kea/"] COPY ["kea-dhcp4-init.conf", "/etc/kea/kea-dhcp4.conf"] COPY ["cli", "/cli/"] -COPY ["rsyslog/default.conf", "/etc/rsyslog.d"] ENTRYPOINT ["/usr/bin/docker_init.sh"] diff --git a/dockers/docker-dhcp-server/docker_init.sh b/dockers/docker-dhcp-server/docker_init.sh index 5220f9ffec4..a9ffc27354c 100755 --- a/dockers/docker-dhcp-server/docker_init.sh +++ b/dockers/docker-dhcp-server/docker_init.sh @@ -7,11 +7,6 @@ mkdir -p /etc/supervisor/conf.d/ mkdir -p /etc/kea/ udp_server_ip=$(ip -j -4 addr list lo scope host | jq -r -M '.[0].addr_info[0].local') hostname=$(hostname) -# Generate the following files from templates: -# port-to-alias name map -sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 \ - -a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\"}" \ - > /etc/rsyslog.conf # Make the script that waits for all interfaces to come up executable chmod +x /etc/kea/lease_update.sh /usr/bin/start.sh diff --git a/dockers/docker-dhcp-server/rsyslog/default.conf b/dockers/docker-dhcp-server/rsyslog/default.conf deleted file mode 100644 index 77609410c57..00000000000 --- a/dockers/docker-dhcp-server/rsyslog/default.conf +++ /dev/null @@ -1,27 +0,0 @@ -# -# First some standard log files. Log by facility. -# - -# Log all facilities to /var/log/syslog except cron, auth -# and authpriv. They are noisy - log them to their own files -*.*;cron,auth,authpriv.none -/var/log/syslog -auth,authpriv.* /var/log/auth.log -cron.* /var/log/cron.log - -# -# Emergencies are sent to everybody logged in. -# -*.emerg :omusrmsg:* - -# The named pipe /dev/xconsole is for the `xconsole' utility. To use it, -# you must invoke `xconsole' with the `-file' option: -# -# $ xconsole -file /dev/xconsole [...] -# -# NOTE: adjust the list below, or you'll go crazy if you have a reasonably -# busy site.. -# -#daemon.*;mail.*;\ -# news.err;\ -# *.=debug;*.=info;\ -# *.=notice;*.=warn |/dev/xconsole diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 4642764afcc..f8f04d68ebe 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -331,7 +331,11 @@ start() { fi # Default rsyslog target IP for single ASIC platform +{%- if docker_container_name == "dhcp_server" %} + SYSLOG_TARGET_IP=$(docker network inspect bridge --format={{ "'{{(index .IPAM.Config 0).Gateway}}'" }}) +{%- else %} SYSLOG_TARGET_IP=127.0.0.1 +{%- endif %} if [[ ($NUM_ASIC -gt 1) ]]; then SYSLOG_TARGET_IP=$(docker network inspect bridge --format={{ "'{{(index .IPAM.Config 0).Gateway}}'" }}) fi diff --git a/files/image_config/rsyslog/rsyslog-config.sh b/files/image_config/rsyslog/rsyslog-config.sh index 57635171136..5f28708216e 100755 --- a/files/image_config/rsyslog/rsyslog-config.sh +++ b/files/image_config/rsyslog/rsyslog-config.sh @@ -17,10 +17,16 @@ if [[ ($NUM_ASIC -gt 1) ]]; then else udp_server_ip=$(ip -j -4 addr list lo scope host | jq -r -M '.[0].addr_info[0].local') fi + +contain_dhcp_server=$(sonic-db-cli CONFIG_DB keys "FEATURE|dhcp_server") +if [ $contain_dhcp_server ]; then + docker0_ip=$(ip -o -4 addr list docker0 | awk '{print $4}' | cut -d/ -f1) +fi + hostname=$(hostname) sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 \ - -a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\"}" \ + -a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\", \"docker0_ip\": \"$docker0_ip\"}" \ > /etc/rsyslog.conf systemctl restart rsyslog diff --git a/files/image_config/rsyslog/rsyslog.conf.j2 b/files/image_config/rsyslog/rsyslog.conf.j2 index f6d48049409..4e812eb62ac 100644 --- a/files/image_config/rsyslog/rsyslog.conf.j2 +++ b/files/image_config/rsyslog/rsyslog.conf.j2 @@ -33,6 +33,10 @@ $ModLoad imklog # provides kernel logging support $ModLoad imudp $UDPServerAddress {{udp_server_ip}} #bind to localhost before udp server run $UDPServerRun 514 +{% if docker0_ip and docker0_ip != "" %} +$UDPServerAddress {{docker0_ip}} +$UDPServerRun 514 +{% endif%} # provides TCP syslog reception #$ModLoad imtcp diff --git a/src/sonic-config-engine/tests/data/rsyslog/config_db.json b/src/sonic-config-engine/tests/data/rsyslog/config_db.json new file mode 100644 index 00000000000..7cc58a13157 --- /dev/null +++ b/src/sonic-config-engine/tests/data/rsyslog/config_db.json @@ -0,0 +1,914 @@ +{ + "AUTO_TECHSUPPORT_FEATURE": { + "acms": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "bgp": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "database": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "dhcp_relay": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "lldp": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "macsec": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "mux": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "pmon": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "radv": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "restapi": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "snmp": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "swss": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "syncd": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "teamd": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "telemetry": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + }, + "vnet-monitor": { + "available_mem_threshold": "10.0", + "rate_limit_interval": "600", + "state": "enabled" + } + }, + "BGP_NEIGHBOR": { + "10.0.0.57": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "10.0.0.56", + "name": "ARISTA01T1", + "nhopself": "0", + "rrclient": "0" + }, + "10.0.0.59": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "10.0.0.58", + "name": "ARISTA02T1", + "nhopself": "0", + "rrclient": "0" + }, + "10.0.0.61": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "10.0.0.60", + "name": "ARISTA03T1", + "nhopself": "0", + "rrclient": "0" + }, + "10.0.0.63": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "10.0.0.62", + "name": "ARISTA04T1", + "nhopself": "0", + "rrclient": "0" + }, + "fc00::7a": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "fc00::79", + "name": "ARISTA03T1", + "nhopself": "0", + "rrclient": "0" + }, + "fc00::7e": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "fc00::7d", + "name": "ARISTA04T1", + "nhopself": "0", + "rrclient": "0" + }, + "fc00::72": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "fc00::71", + "name": "ARISTA01T1", + "nhopself": "0", + "rrclient": "0" + }, + "fc00::76": { + "admin_status": "up", + "asn": "64600", + "holdtime": "10", + "keepalive": "3", + "local_addr": "fc00::75", + "name": "ARISTA02T1", + "nhopself": "0", + "rrclient": "0" + } + }, + "CONSOLE_SWITCH": { + "console_mgmt": { + "enabled": "no" + } + }, + "DEVICE_METADATA": { + "localhost": { + "bgp_asn": "65100", + "buffer_model": "traditional", + "cloudtype": "Public", + "default_bgp_status": "down", + "default_pfcwd_status": "enable", + "deployment_id": "1", + "docker_routing_config_mode": "separated", + "hostname": "kvm-host", + "hwsku": "Mellanox-SN2700", + "mac": "98:03:9B:F6:02:80", + "platform": "x86_64-mlnx_msn2700-r0", + "region": "None", + "synchronous_mode": "enable", + "type": "ToRRouter" + } + }, + "DEVICE_NEIGHBOR": { + "Ethernet112": { + "name": "ARISTA01T1", + "port": "Ethernet1" + }, + "Ethernet116": { + "name": "ARISTA02T1", + "port": "Ethernet1" + }, + "Ethernet120": { + "name": "ARISTA03T1", + "port": "Ethernet1" + }, + "Ethernet124": { + "name": "ARISTA04T1", + "port": "Ethernet1" + } + }, + "DEVICE_NEIGHBOR_METADATA": { + "ARISTA01T1": { + "hwsku": "Arista-VM", + "mgmt_addr": "3.3.3.14", + "type": "LeafRouter" + }, + "ARISTA02T1": { + "hwsku": "Arista-VM", + "mgmt_addr": "3.3.3.15", + "type": "LeafRouter" + }, + "ARISTA03T1": { + "hwsku": "Arista-VM", + "mgmt_addr": "3.3.3.16", + "type": "LeafRouter" + }, + "ARISTA04T1": { + "hwsku": "Arista-VM", + "mgmt_addr": "3.3.3.17", + "type": "LeafRouter" + } + }, + "DHCP_RELAY": { + "Vlan1000": { + "dhcpv6_servers": [ + "fc02:2000::1", + "fc02:2000::2", + "fc02:2000::3", + "fc02:2000::4" + ] + } + }, + "DHCP_SERVER": { + "192.0.0.1": {}, + "192.0.0.2": {}, + "192.0.0.3": {}, + "192.0.0.4": {} + }, + "FEATURE": { + "acms": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "bgp": { + "auto_restart": "enabled", + "check_up_status": "false", + "has_global_scope": "False", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "database": { + "auto_restart": "always_enabled", + "has_global_scope": "True", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "always_enabled" + }, + "dhcp_relay": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "lldp": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "True", + "delayed": "True", + "high_mem_alert": "disabled", + "set_owner": "kube", + "state": "enabled" + }, + "macsec": { + "auto_restart": "enabled", + "has_global_scope": "False", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "disabled" + }, + "mux": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "always_disabled" + }, + "pmon": { + "auto_restart": "enabled", + "check_up_status": "false", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "True", + "high_mem_alert": "disabled", + "set_owner": "kube", + "state": "enabled" + }, + "radv": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "kube", + "state": "enabled" + }, + "restapi": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "snmp": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "True", + "high_mem_alert": "disabled", + "set_owner": "kube", + "state": "enabled" + }, + "swss": { + "auto_restart": "enabled", + "check_up_status": "false", + "has_global_scope": "False", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "syncd": { + "auto_restart": "enabled", + "has_global_scope": "False", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "teamd": { + "auto_restart": "enabled", + "has_global_scope": "False", + "has_per_asic_scope": "True", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "enabled" + }, + "telemetry": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "True", + "high_mem_alert": "disabled", + "set_owner": "kube", + "state": "enabled" + }, + "vnet-monitor": { + "auto_restart": "enabled", + "has_global_scope": "True", + "has_per_asic_scope": "False", + "delayed": "False", + "high_mem_alert": "disabled", + "set_owner": "local", + "state": "disabled" + } + }, + "FLEX_COUNTER_TABLE": { + "ACL": { + "FLEX_COUNTER_DELAY_STATUS": "false", + "FLEX_COUNTER_STATUS": "enable", + "POLL_INTERVAL": "10000" + } + }, + "KDUMP": { + "config": { + "enabled": "false", + "memory": "0M-2G:256M,2G-4G:320M,4G-8G:384M,8G-:448M", + "num_dumps": "3" + } + }, + "LOOPBACK_INTERFACE": { + "Loopback0": {}, + "Loopback0|10.1.0.32/32": {}, + "Loopback0|FC00:1::32/128": {} + }, + "MGMT_INTERFACE": { + "eth0|1.1.1.15/23": { + "gwaddr": "1.1.1.10" + }, + "eth0|2404:::2/64": { + "gwaddr": "2404::1" + } + }, + "MGMT_PORT": { + "eth0": { + "admin_status": "up", + "alias": "eth0" + } + }, + "PORT": { + "Ethernet0": { + "alias": "etp1", + "description": "etp1", + "fec": "rs", + "index": "1", + "lanes": "0,1,2,3", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet4": { + "admin_status": "up", + "alias": "etp2", + "description": "Servers0:eth0", + "fec": "rs", + "index": "2", + "lanes": "4,5,6,7", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet8": { + "admin_status": "up", + "alias": "etp3", + "description": "Servers1:eth0", + "fec": "rs", + "index": "3", + "lanes": "8,9,10,11", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet12": { + "admin_status": "up", + "alias": "etp4", + "description": "Servers2:eth0", + "fec": "rs", + "index": "4", + "lanes": "12,13,14,15", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet16": { + "admin_status": "up", + "alias": "etp5", + "description": "Servers3:eth0", + "fec": "rs", + "index": "5", + "lanes": "16,17,18,19", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet20": { + "admin_status": "up", + "alias": "etp6", + "description": "Servers4:eth0", + "fec": "rs", + "index": "6", + "lanes": "20,21,22,23", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet24": { + "admin_status": "up", + "alias": "etp7", + "description": "Servers5:eth0", + "fec": "rs", + "index": "7", + "lanes": "24,25,26,27", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet28": { + "admin_status": "up", + "alias": "etp8", + "description": "Servers6:eth0", + "fec": "rs", + "index": "8", + "lanes": "28,29,30,31", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet32": { + "admin_status": "up", + "alias": "etp9", + "description": "Servers7:eth0", + "fec": "rs", + "index": "9", + "lanes": "32,33,34,35", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet36": { + "admin_status": "up", + "alias": "etp10", + "description": "Servers8:eth0", + "fec": "rs", + "index": "10", + "lanes": "36,37,38,39", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet40": { + "admin_status": "up", + "alias": "etp11", + "description": "Servers9:eth0", + "fec": "rs", + "index": "11", + "lanes": "40,41,42,43", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet44": { + "admin_status": "up", + "alias": "etp12", + "description": "Servers10:eth0", + "fec": "rs", + "index": "12", + "lanes": "44,45,46,47", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet48": { + "admin_status": "up", + "alias": "etp13", + "description": "Servers11:eth0", + "fec": "rs", + "index": "13", + "lanes": "48,49,50,51", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet52": { + "admin_status": "up", + "alias": "etp14", + "description": "Servers12:eth0", + "fec": "rs", + "index": "14", + "lanes": "52,53,54,55", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet56": { + "admin_status": "up", + "alias": "etp15", + "description": "Servers13:eth0", + "fec": "rs", + "index": "15", + "lanes": "56,57,58,59", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet60": { + "admin_status": "up", + "alias": "etp16", + "description": "Servers14:eth0", + "fec": "rs", + "index": "16", + "lanes": "60,61,62,63", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet64": { + "admin_status": "up", + "alias": "etp17", + "description": "Servers15:eth0", + "fec": "rs", + "index": "17", + "lanes": "64,65,66,67", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet68": { + "admin_status": "up", + "alias": "etp18", + "description": "Servers16:eth0", + "fec": "rs", + "index": "18", + "lanes": "68,69,70,71", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet72": { + "admin_status": "up", + "alias": "etp19", + "description": "Servers17:eth0", + "fec": "rs", + "index": "19", + "lanes": "72,73,74,75", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet76": { + "admin_status": "up", + "alias": "etp20", + "description": "Servers18:eth0", + "fec": "rs", + "index": "20", + "lanes": "76,77,78,79", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet80": { + "admin_status": "up", + "alias": "etp21", + "description": "Servers19:eth0", + "fec": "rs", + "index": "21", + "lanes": "80,81,82,83", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet84": { + "admin_status": "up", + "alias": "etp22", + "description": "Servers20:eth0", + "fec": "rs", + "index": "22", + "lanes": "84,85,86,87", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet88": { + "admin_status": "up", + "alias": "etp23", + "description": "Servers21:eth0", + "fec": "rs", + "index": "23", + "lanes": "88,89,90,91", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet92": { + "admin_status": "up", + "alias": "etp24", + "description": "Servers22:eth0", + "fec": "rs", + "index": "24", + "lanes": "92,93,94,95", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet96": { + "admin_status": "up", + "alias": "etp25", + "description": "Servers23:eth0", + "fec": "rs", + "index": "25", + "lanes": "96,97,98,99", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet100": { + "alias": "etp26", + "description": "etp26", + "fec": "rs", + "index": "26", + "lanes": "100,101,102,103", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet104": { + "alias": "etp27", + "description": "etp27", + "fec": "rs", + "index": "27", + "lanes": "104,105,106,107", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet108": { + "alias": "etp28", + "description": "etp28", + "fec": "rs", + "index": "28", + "lanes": "108,109,110,111", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet112": { + "admin_status": "up", + "alias": "etp29", + "description": "ARISTA01T1:Ethernet1", + "fec": "rs", + "index": "29", + "lanes": "112,113,114,115", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet116": { + "admin_status": "up", + "alias": "etp30", + "description": "ARISTA02T1:Ethernet1", + "fec": "rs", + "index": "30", + "lanes": "116,117,118,119", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet120": { + "admin_status": "up", + "alias": "etp31", + "description": "ARISTA03T1:Ethernet1", + "fec": "rs", + "index": "31", + "lanes": "120,121,122,123", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + }, + "Ethernet124": { + "admin_status": "up", + "alias": "etp32", + "description": "ARISTA04T1:Ethernet1", + "fec": "rs", + "index": "32", + "lanes": "124,125,126,127", + "mtu": "9100", + "pfc_asym": "off", + "speed": "100000", + "tpid": "0x8100" + } + }, + "PORTCHANNEL": { + "PortChannel101": { + "admin_status": "up", + "lacp_key": "auto", + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100" + }, + "PortChannel102": { + "admin_status": "up", + "lacp_key": "auto", + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100" + }, + "PortChannel103": { + "admin_status": "up", + "lacp_key": "auto", + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100" + }, + "PortChannel104": { + "admin_status": "up", + "lacp_key": "auto", + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100" + } + }, + "PORTCHANNEL_INTERFACE": { + "PortChannel101": {}, + "PortChannel101|10.0.0.56/31": {}, + "PortChannel101|FC00::71/126": {}, + "PortChannel102": {}, + "PortChannel102|10.0.0.58/31": {}, + "PortChannel102|FC00::75/126": {}, + "PortChannel103": {}, + "PortChannel103|10.0.0.60/31": {}, + "PortChannel103|FC00::79/126": {}, + "PortChannel104": {}, + "PortChannel104|10.0.0.62/31": {}, + "PortChannel104|FC00::7D/126": {} + }, + "PORTCHANNEL_MEMBER": { + "PortChannel101|Ethernet112": {}, + "PortChannel102|Ethernet116": {}, + "PortChannel103|Ethernet120": {}, + "PortChannel104|Ethernet124": {} + }, + "SNMP": { + "LOCATION": { + "Location": "public" + } + }, + "SNMP_COMMUNITY": { + "public": { + "TYPE": "RO" + } + }, + "SYSLOG_SERVER": { + "3.3.3.3": {} + }, + "VERSIONS": { + "DATABASE": { + "VERSION": "version_3_0_7" + } + }, + "VLAN": { + "Vlan1000": { + "dhcp_servers": [ + "192.0.0.1", + "192.0.0.2", + "192.0.0.3", + "192.0.0.4" + ], + "dhcpv6_servers": [ + "fc02:2000::1", + "fc02:2000::2", + "fc02:2000::3", + "fc02:2000::4" + ], + "vlanid": "1000" + } + }, + "VLAN_INTERFACE": { + "Vlan1000": {}, + "Vlan1000|192.168.0.1/21": {}, + "Vlan1000|fc02:1000::1/64": {} + }, + "VLAN_MEMBER": { + "Vlan1000|Ethernet4": { + "tagging_mode": "untagged" + }, + "Vlan1000|Ethernet8": { + "tagging_mode": "untagged" + }, + "Vlan1000|Ethernet12": { + "tagging_mode": "untagged" + }, + "Vlan1000|Ethernet16": { + "tagging_mode": "untagged" + } + } +} + diff --git a/dockers/docker-dhcp-server/rsyslog/rsyslog.conf.j2 b/src/sonic-config-engine/tests/sample_output/py3/rsyslog.conf similarity index 67% rename from dockers/docker-dhcp-server/rsyslog/rsyslog.conf.j2 rename to src/sonic-config-engine/tests/sample_output/py3/rsyslog.conf index 664a6a5fb9b..e08d33f847d 100644 --- a/dockers/docker-dhcp-server/rsyslog/rsyslog.conf.j2 +++ b/src/sonic-config-engine/tests/sample_output/py3/rsyslog.conf @@ -15,23 +15,14 @@ $ModLoad imuxsock # provides support for local system logging -{% set gconf = (SYSLOG_CONFIG | d({})).get('GLOBAL', {}) -%} -{% set rate_limit_interval = gconf.get('rate_limit_interval') %} -{% set rate_limit_burst = gconf.get('rate_limit_burst') %} -{% if rate_limit_interval is not none %} -$SystemLogRateLimitInterval {{ rate_limit_interval }} -{% endif %} -{% if rate_limit_burst is not none %} -$SystemLogRateLimitBurst {{ rate_limit_burst }} -{% endif %} $ModLoad imklog # provides kernel logging support #$ModLoad immark # provides --MARK-- message capability # provides UDP syslog reception $ModLoad imudp -$UDPServerAddress {{udp_server_ip}} #bind to localhost before udp server run +$UDPServerAddress 1.1.1.1 #bind to localhost before udp server run $UDPServerRun 514 # provides TCP syslog reception @@ -42,8 +33,6 @@ $UDPServerRun 514 ########################### #### GLOBAL DIRECTIVES #### ########################### -{% set format = gconf.get('format', 'standard') -%} -{% set fw_name = gconf.get('welf_firewall_name', hostname) -%} # # Use traditional timestamp format. # To enable high precision timestamps, comment out the following line. @@ -51,12 +40,12 @@ $UDPServerRun 514 #$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # Define a custom template -$template SONiCFileFormat,"%TIMESTAMP%.%timestamp:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% dhcp_server#%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" +$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" $ActionFileDefaultTemplate SONiCFileFormat template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\ :::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\ -:::date-second%\" fw=\"{{ fw_name }}\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n") +:::date-second%\" fw=\"kvm-host\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n") # # Set the default permissions for all log files. @@ -93,4 +82,7 @@ $RepeatedMsgReduction on # The omfwd plug-in provides the core functionality of traditional message # forwarding via UDP and plain TCP. It is a built-in module that does not need # to be loaded. -# TODO rsyslog issue in bridge mode container, don't update to remote server for now + +*.notice +action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCFileFormat") + diff --git a/src/sonic-config-engine/tests/sample_output/py3/rsyslog_with_docker0.conf b/src/sonic-config-engine/tests/sample_output/py3/rsyslog_with_docker0.conf new file mode 100644 index 00000000000..2ca80f454ad --- /dev/null +++ b/src/sonic-config-engine/tests/sample_output/py3/rsyslog_with_docker0.conf @@ -0,0 +1,90 @@ +############################################################################### +# Managed by Ansible +# file: ansible/roles/acs/templates/rsyslog.conf.j2 +############################################################################### +# +# /etc/rsyslog.conf Configuration file for rsyslog. +# +# For more information see +# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html + + +################# +#### MODULES #### +################# + +$ModLoad imuxsock # provides support for local system logging + + + +$ModLoad imklog # provides kernel logging support +#$ModLoad immark # provides --MARK-- message capability + +# provides UDP syslog reception +$ModLoad imudp +$UDPServerAddress 1.1.1.1 #bind to localhost before udp server run +$UDPServerRun 514 +$UDPServerAddress 2.2.2.2 +$UDPServerRun 514 + +# provides TCP syslog reception +#$ModLoad imtcp +#$InputTCPServerRun 514 + + +########################### +#### GLOBAL DIRECTIVES #### +########################### +# +# Use traditional timestamp format. +# To enable high precision timestamps, comment out the following line. +# +#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat + +# Define a custom template +$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n" +$ActionFileDefaultTemplate SONiCFileFormat + +template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\ +:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\ +:::date-second%\" fw=\"kvm-host\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n") + +# +# Set the default permissions for all log files. +# +$FileOwner root +$FileGroup adm +$FileCreateMode 0640 +$DirCreateMode 0755 +$Umask 0022 + +# +# Where to place spool and state files +# +$WorkDirectory /var/spool/rsyslog + +# +# Include all config files in /etc/rsyslog.d/ +# +$IncludeConfig /etc/rsyslog.d/*.conf + +# +# Suppress duplicate messages and report "message repeated n times" +# +$RepeatedMsgReduction on + +############### +#### RULES #### +############### + +# +# Remote syslog logging +# + +# The omfwd plug-in provides the core functionality of traditional message +# forwarding via UDP and plain TCP. It is a built-in module that does not need +# to be loaded. + +*.notice +action(type="omfwd" Target="3.3.3.3" Port="514" Protocol="udp" Template="SONiCFileFormat") + diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index 9e6cfaf2fbd..d411cad2536 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -723,6 +723,36 @@ def test_dns_template_render(self): def test_buffers_edgezone_aggregator_render_template(self): self._test_buffers_render_template('arista', 'x86_64-arista_7060_cx32s', 'Arista-7060CX-32S-D48C8', 'sample-arista-7060-t0-minigraph.xml', 'buffers.json.j2', 'buffer-arista7060-t0.json') + def test_rsyslog_conf(self): + if utils.PYvX_DIR != 'py3': + # Skip on python2 as the change will not be backported to previous version + return + + conf_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'rsyslog', + 'rsyslog.conf.j2') + config_db_json = os.path.join(self.test_dir, "data", "rsyslog", "config_db.json") + additional_data = "{\"udp_server_ip\": \"1.1.1.1\", \"hostname\": \"kvm-host\"}" + + argument = ['-j', config_db_json, '-t', conf_template, '-a', additional_data] + self.run_script(argument, output_file=self.output_file) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'rsyslog.conf'), + self.output_file)) + + def test_rsyslog_conf_docker0_ip(self): + if utils.PYvX_DIR != 'py3': + # Skip on python2 as the change will not be backported to previous version + return + + conf_template = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'rsyslog', + 'rsyslog.conf.j2') + config_db_json = os.path.join(self.test_dir, "data", "rsyslog", "config_db.json") + additional_data = "{\"udp_server_ip\": \"1.1.1.1\", \"hostname\": \"kvm-host\", " + \ + "\"docker0_ip\": \"2.2.2.2\"}" + + argument = ['-j', config_db_json, '-t', conf_template, '-a', additional_data] + self.run_script(argument, output_file=self.output_file) + self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, + 'rsyslog_with_docker0.conf'), self.output_file)) def tearDown(self): os.environ["CFGGEN_UNIT_TESTING"] = ""