Skip to content

Commit c8d5d47

Browse files
authored
Hardcode the hostname to use for syslogs (#24394)
* Hardcode the hostname to use for syslogs On the host rsyslog, hardcode the hostname to use for logging syslogs, and don't use the hostname that is sent from rsyslog in the container. The reason for this is that when the container is started, the hostname might not be set correctly (which is the case for the database container); rsyslog reads the hostname once at process startup, but doesn't reread it for each syslog message. This means that syslogs from those containers might have the default hostname or an old hostname if the rsyslogd process wasn't restarted after a hostname change. To work around this, on the host rsyslog, when we write it to `/var/log/syslog` or forward it out, use the hardcoded hostname that gets set in the config_db file in place of rsyslog determining the hostname or using the hostname passed down from the container rsyslog. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent fbf9dbb commit c8d5d47

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

files/image_config/rsyslog/rsyslog.conf.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ $UDPServerRun 514
5858
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
5959

6060
# Define a custom template
61-
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
61+
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% {{ hostname }} %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
6262
$ActionFileDefaultTemplate SONiCFileFormat
63-
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
64-
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% {{os_version}} %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
63+
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% {{ hostname }} %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
64+
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% {{ hostname }} {{os_version}} %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
6565

6666
{% if forward_with_osversion and forward_with_osversion == "true" %}
6767
$ActionForwardDefaultTemplate SONiCForwardFormatWithOsVersion

src/sonic-config-engine/tests/sample_output/py3/rsyslog.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ $UDPServerRun 514
4040
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
4141

4242
# Define a custom template
43-
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
43+
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
4444
$ActionFileDefaultTemplate SONiCFileFormat
45-
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
46-
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
45+
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
46+
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
4747

4848
$ActionForwardDefaultTemplate SONiCForwardFormat
4949

src/sonic-config-engine/tests/sample_output/py3/rsyslog_with_docker0.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ $UDPServerRun 514
4242
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
4343

4444
# Define a custom template
45-
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
45+
$template SONiCFileFormat,"%timegenerated:::date-year% %timegenerated%.%timegenerated:::date-subseconds% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
4646
$ActionFileDefaultTemplate SONiCFileFormat
47-
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
48-
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
47+
$template SONiCForwardFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
48+
$template SONiCForwardFormatWithOsVersion,"<%PRI%>%TIMESTAMP:::date-rfc3339% kvm-host %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
4949

5050
$ActionForwardDefaultTemplate SONiCForwardFormat
5151

0 commit comments

Comments
 (0)