Skip to content

Commit 2b381b1

Browse files
authored
Revert "revert [syslog] Add remote syslog configuration (cherry-pick to 202305) (#15897) (#16179)" (#16549)
This reverts commit 164fa10.
1 parent 1355839 commit 2b381b1

File tree

7 files changed

+437
-82
lines changed

7 files changed

+437
-82
lines changed

files/image_config/rsyslog/rsyslog-config.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ if [[ ($NUM_ASIC -gt 1) ]]; then
1717
else
1818
udp_server_ip=$(ip -j -4 addr list lo scope host | jq -r -M '.[0].addr_info[0].local')
1919
fi
20+
hostname=$(hostname)
2021

21-
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 -a "{\"udp_server_ip\": \"$udp_server_ip\"}" >/etc/rsyslog.conf
22+
sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 \
23+
-a "{\"udp_server_ip\": \"$udp_server_ip\", \"hostname\": \"$hostname\"}" \
24+
> /etc/rsyslog.conf
2225

2326
systemctl restart rsyslog

files/image_config/rsyslog/rsyslog.conf.j2

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,14 @@
1515

1616
$ModLoad imuxsock # provides support for local system logging
1717

18-
{% if SYSLOG_CONFIG is defined %}
19-
{% if 'GLOBAL' in SYSLOG_CONFIG %}
20-
{% if 'rate_limit_interval' in SYSLOG_CONFIG['GLOBAL']%}
21-
{% set rate_limit_interval = SYSLOG_CONFIG['GLOBAL']['rate_limit_interval'] %}
22-
{% endif %}
23-
{% if 'rate_limit_burst' in SYSLOG_CONFIG['GLOBAL']%}
24-
{% set rate_limit_burst = SYSLOG_CONFIG['GLOBAL']['rate_limit_burst'] %}
25-
{% endif %}
26-
{% endif %}
27-
{% endif %}
18+
{% set gconf = (SYSLOG_CONFIG | d({})).get('GLOBAL', {}) -%}
19+
{% set rate_limit_interval = gconf.get('rate_limit_interval') %}
20+
{% set rate_limit_burst = gconf.get('rate_limit_burst') %}
2821

29-
{% if rate_limit_interval is defined %}
22+
{% if rate_limit_interval is not none %}
3023
$SystemLogRateLimitInterval {{ rate_limit_interval }}
3124
{% endif %}
32-
{% if rate_limit_burst is defined %}
25+
{% if rate_limit_burst is not none %}
3326
$SystemLogRateLimitBurst {{ rate_limit_burst }}
3427
{% endif %}
3528

@@ -49,6 +42,8 @@ $UDPServerRun 514
4942
###########################
5043
#### GLOBAL DIRECTIVES ####
5144
###########################
45+
{% set format = gconf.get('format', 'standard') -%}
46+
{% set fw_name = gconf.get('welf_firewall_name', hostname) -%}
5247
#
5348
# Use traditional timestamp format.
5449
# To enable high precision timestamps, comment out the following line.
@@ -59,6 +54,10 @@ $UDPServerRun 514
5954
$template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
6055
$ActionFileDefaultTemplate SONiCFileFormat
6156

57+
template(name="WelfRemoteFormat" type="string" string="%TIMESTAMP% id=firewall time=\"%timereported\
58+
:::date-year%-%timereported:::date-month%-%timereported:::date-day% %timereported:::date-hour%:%timereported:::date-minute%:%timereported\
59+
:::date-second%\" fw=\"{{ fw_name }}\" pri=%syslogpriority% msg=\"%syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\"\n")
60+
6261
#
6362
# Set the default permissions for all log files.
6463
#
@@ -91,25 +90,36 @@ $RepeatedMsgReduction on
9190
# Remote syslog logging
9291
#
9392

94-
# The omfwd plug-in provides the core functionality of traditional message forwarding via UDP and plain TCP.
95-
# It is a built-in module that does not need to be loaded.
93+
# The omfwd plug-in provides the core functionality of traditional message
94+
# forwarding via UDP and plain TCP. It is a built-in module that does not need
95+
# to be loaded.
9696

97-
{% if SYSLOG_SERVER is defined %}
98-
{% for server, data in SYSLOG_SERVER.items() %}
99-
{% set params_list = [] %}
100-
{% if 'source' in data %}
101-
{% set dummy = params_list.append('address=' + '"' + data.source|string + '"') %}
102-
{% endif %}
103-
{% if 'port' in data %}
104-
{% set dummy = params_list.append('port=' + '"' + data.port|string + '"') %}
105-
{% endif %}
106-
{% if 'vrf' in data and data['vrf'] != "default" %}
107-
{% set dummy = params_list.append('device=' + '"' + data.vrf|string + '"') %}
108-
{% endif %}
109-
{% if params_list %}
110-
*.* action(type="omfwd" target="{{ server }}" protocol="udp" {{ params_list|join(' ') }} template="SONiCFileFormat")
111-
{% else %}
112-
*.* action(type="omfwd" target="{{ server }}" protocol="udp" template="SONiCFileFormat")
97+
{% set servers = SYSLOG_SERVER | d({}) -%}
98+
{% for server in servers %}
99+
{% set conf = servers[server] | d({}) -%}
100+
101+
{% set source = conf.get('source') -%}
102+
{% set port = conf.get('port', 514) -%}
103+
{% set proto = conf.get('protocol', 'udp') -%}
104+
{% set vrf = conf.get('vrf', 'default') -%}
105+
{% set severity = conf.get('severity', gconf.get('severity', 'notice')) -%}
106+
{% set filter = conf.get('filter') -%}
107+
{% set regex = conf.get('filter_regex') -%}
108+
109+
{% set fmodifier = '!' if filter == 'exclude' else '' %}
110+
{% set device = 'eth0' if vrf == 'default' else vrf -%}
111+
{% set template = 'WelfRemoteFormat' if format == 'welf' else 'SONiCFileFormat' -%}
112+
113+
{# Server extra options -#}
114+
{% set options = '' -%}
115+
116+
{% if source -%}
117+
{% set options = options ~ ' Address="' ~ source ~ '"'-%}
118+
{% endif -%}
119+
120+
{% if filter %}
121+
:msg, {{ fmodifier }}ereregex, "{{ regex }}"
113122
{% endif %}
123+
*.{{ severity }}
124+
action(type="omfwd" Target="{{ server }}" Port="{{ port }}" Protocol="{{ proto }}" Device="{{ device }}" Template="{{ template }}"{{ options }})
114125
{% endfor %}
115-
{% endif %}

src/sonic-yang-models/doc/Configuration.md

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Table of Contents
5151
* [MUX_LINKMGR](#mux_linkmgr)
5252
* [NEIGH](#neigh)
5353
* [NTP Global Configuration](#ntp-global-configuration)
54-
* [NTP and SYSLOG servers](#ntp-and-syslog-servers)
54+
* [NTP Servers](#ntp-servers)
5555
* [Peer Switch](#peer-switch)
5656
* [Policer](#policer)
5757
* [Port](#port)
@@ -60,7 +60,8 @@ Table of Contents
6060
* [Scheduler](#scheduler)
6161
* [Port QoS Map](#port-qos-map)
6262
* [Queue](#queue)
63-
* [Syslog Rate Limit](#syslog-rate-limit)
63+
* [Syslog Global Configuration](#syslog-global-configuration)
64+
* [Syslog Servers](#syslog-servers)
6465
* [Sflow](#sflow)
6566
* [Restapi](#restapi)
6667
* [System Port](#system-port)
@@ -1517,7 +1518,7 @@ for that address.
15171518
}
15181519
```
15191520

1520-
### NTP and SYSLOG servers
1521+
### NTP servers
15211522

15221523
These information are configured in individual tables. Domain name or IP
15231524
address of the server is used as object key. Currently there are no
@@ -1540,35 +1541,6 @@ attributes in those objects.
15401541
}
15411542
```
15421543

1543-
***Syslog server***
1544-
```
1545-
{
1546-
"SYSLOG_SERVER": {
1547-
"10.0.0.5": {},
1548-
"10.0.0.6": {},
1549-
"10.11.150.5": {}
1550-
},
1551-
1552-
"SYSLOG_SERVER" : {
1553-
"2.2.2.2": {
1554-
"source": "1.1.1.1",
1555-
"port": "514",
1556-
"vrf": "default"
1557-
},
1558-
"4.4.4.4": {
1559-
"source": "3.3.3.3",
1560-
"port": "514",
1561-
"vrf": "mgmt"
1562-
},
1563-
"2222::2222": {
1564-
"source": "1111::1111",
1565-
"port": "514",
1566-
"vrf": "Vrf-Data"
1567-
}
1568-
}
1569-
}
1570-
```
1571-
15721544
### Peer Switch
15731545

15741546
Below is an exmaple of the peer switch table configuration.
@@ -1854,7 +1826,33 @@ key - name
18541826
| collector_port | Destination L4 port of the Sflow collector | | 6343 | |
18551827
| collector_vrf | Specify the Collector VRF. In this revision, it is either default VRF or Management VRF.| | | |
18561828

1857-
### Syslog Rate Limit
1829+
### Syslog Global Configuration
1830+
1831+
These configuration options are used to configure rsyslog utility and the way
1832+
the system generates logs.
1833+
1834+
***Configuration sample***
1835+
```
1836+
{
1837+
"SYSLOG_CONFIG": {
1838+
"GLOBAL": {
1839+
"rate_limit_interval": "5",
1840+
"rate_limit_burst": "100",
1841+
"format": "welf",
1842+
"welf_firewall_name": "bla",
1843+
"severity": "info"
1844+
}
1845+
}
1846+
}
1847+
```
1848+
1849+
* `rate_limit_interval` - determines the amount of time that is being measured for rate limiting: `unsigned integer`
1850+
* `rate_limit_burst` - defines the amount of messages, that have to occur in the time limit: `unsigned integer`
1851+
* `format` - syslog log format: `{standard, welf}`
1852+
* `welf_firewall_name` - WELF format firewall name: `string`
1853+
* `severity` - global log severity: `{emerg, alert, crit, error, warning, notice, info, debug}`
1854+
1855+
***Syslog Rate Limit***
18581856

18591857
Host side configuration:
18601858

@@ -1886,6 +1884,50 @@ Container side configuration:
18861884
}
18871885
```
18881886

1887+
### Syslog servers
1888+
1889+
These information are configured in individual tables. Domain name or IP
1890+
address of the server is used as object key. Each server can be configurable.
1891+
1892+
***Configuration sample***
1893+
```
1894+
{
1895+
"SYSLOG_SERVER": {
1896+
"10.0.0.5": {},
1897+
"10.0.0.6": {},
1898+
"10.11.150.5": {}
1899+
},
1900+
1901+
"SYSLOG_SERVER" : {
1902+
"4.4.4.4": {
1903+
"source": "3.3.3.3",
1904+
"port": "514",
1905+
"vrf": "mgmt"
1906+
},
1907+
"2222::2222": {
1908+
"source": "1111::1111",
1909+
"port": "514",
1910+
"vrf": "Vrf-Data"
1911+
},
1912+
"somehostname": {
1913+
"filter": "include",
1914+
"filter_regex": "ololo",
1915+
"port": "514",
1916+
"protocol": "tcp",
1917+
"severity": "notice",
1918+
"vrf": "default"
1919+
}
1920+
}
1921+
}
1922+
```
1923+
1924+
* `filter` - determines if syslog will include or exclude messages specified by regex: `{include, exclude}`
1925+
* `filter_regex` - filter messages by this regex: `string`
1926+
* `port` - network port to use to connect to remote server: `integer: 1..65535`
1927+
* `protocol` - network protocol to use to connect to remote server: `{tcp, udp}`
1928+
* `severity` - per-server log severity, overrifes global one: `{emerg, alert, crit, error, warning, notice, info, debug}`
1929+
1930+
18891931
### System Port
18901932
Every port on the system requires a global representation, known as a System Port,
18911933
and is listed in this table.

src/sonic-yang-models/tests/files/sample_config_db.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,23 @@
499499
"source": "1111::1111",
500500
"port": "514",
501501
"vrf": "Vrf_blue"
502+
},
503+
"somehostname": {
504+
"filter": "include",
505+
"filter_regex": "ololo",
506+
"port": "514",
507+
"protocol": "tcp",
508+
"severity": "notice",
509+
"vrf": "default"
502510
}
503511
},
504512
"SYSLOG_CONFIG" : {
505513
"GLOBAL": {
506514
"rate_limit_interval": "5",
507-
"rate_limit_burst": "100"
515+
"rate_limit_burst": "100",
516+
"format": "welf",
517+
"welf_firewall_name": "bla",
518+
"severity": "info"
508519
}
509520
},
510521
"SYSLOG_CONFIG_FEATURE" : {

src/sonic-yang-models/tests/yang_model_tests/tests/syslog.json

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
"desc": "Load syslog server table with empty address as syslog server.",
3030
"eStrKey": "InvalidValue"
3131
},
32-
"SYSLOG_SERVER_INVALID_IPADDR_TEST": {
33-
"desc": "Load syslog server table with invalid ipv4 address as syslog server.",
34-
"eStrKey": "InvalidValue"
35-
},
3632
"SYSLOG_SERVER_INVALID_IPV6_ADDR_TEST": {
3733
"desc": "Load syslog server table with invalid ipv6 address as syslog server.",
3834
"eStrKey": "InvalidValue"
@@ -62,5 +58,60 @@
6258
"SYSLOG_CONFIG_FEATURE_INVALID_BURST": {
6359
"desc": "Configure invalid rate_limit_burst in SYSLOG_CONFIG_FEATURE.",
6460
"eStrKey": "InvalidValue"
61+
},
62+
"SYSLOG_SERVER_HOSTNAME": {
63+
"desc": "Load syslog server table with hostname"
64+
},
65+
"SYSLOG_SERVER_HOSTNAME_INVALID": {
66+
"desc": "Load syslog server table with invalid hostname",
67+
"eStrKey": "InvalidValue"
68+
},
69+
"SYSLOG_SERVER_FILTER_TYPE": {
70+
"desc": "Valid filter type for syslog server"
71+
},
72+
"SYSLOG_SERVER_FILTER_TYPE_INVALID": {
73+
"desc": "Invalid filter type for syslog server",
74+
"eStrKey": "InvalidValue"
75+
},
76+
"SYSLOG_SERVER_FILTER_REGEX": {
77+
"desc": "Valid filter regex"
78+
},
79+
"SYSLOG_SERVER_PROTOCOL": {
80+
"desc": "Valid syslog server protocol"
81+
},
82+
"SYSLOG_SERVER_PROTOCOL_INVALID": {
83+
"desc": "Invalid syslog server protocol",
84+
"eStrKey": "InvalidValue"
85+
},
86+
"SYSLOG_SERVER_SEVERITY": {
87+
"desc": "Syslog server valid severity"
88+
},
89+
"SYSLOG_SERVER_SEVERITY_INVALID": {
90+
"desc": "Syslog server invalid severity",
91+
"eStrKey": "InvalidValue"
92+
},
93+
"SYSLOG_CONFIG_GLOBAL_VALID": {
94+
"desc": "Global syslog configuration"
95+
},
96+
"SYSLOG_CONFIG_FORMAT": {
97+
"desc": "Syslog format type"
98+
},
99+
"SYSLOG_CONFIG_FORMAT_INVALID": {
100+
"desc": "Invalid syslog format",
101+
"eStrKey": "InvalidValue"
102+
},
103+
"SYSLOG_CONFIG_FORMAT_WELF_FW_NAME": {
104+
"desc": "Syslog format WELF firewall name"
105+
},
106+
"SYSLOG_CONFIG_FORMAT_WELF_FW_NAME_INVALID": {
107+
"desc": "Syslog format WELF invalid firewall name",
108+
"eStrKey": "Must"
109+
},
110+
"SYSLOG_CONFIG_SEVERITY": {
111+
"desc": "Global syslog severity"
112+
},
113+
"SYSLOG_CONFIG_SEVERITY_INVALID": {
114+
"desc": "Global invalid syslog severity",
115+
"eStrKey": "InvalidValue"
65116
}
66117
}

0 commit comments

Comments
 (0)