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

syslog: T6858: bugfix remote syslog using TCP #4185

Merged
merged 2 commits into from
Nov 8, 2024
Merged
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
2 changes: 0 additions & 2 deletions data/templates/rsyslog/rsyslog.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ $outchannel {{ file_name }},/var/log/user/{{ file_name }},{{ file_options.archiv
{% endfor %}
{% endif %}
{% if host_options.protocol is vyos_defined('tcp') %}
{% if host_options.format.octet_counted is vyos_defined %}
{{ tmp | join(';') }} @@{{ '(o)' if host_options.format.octet_counted is vyos_defined }}{{ host_name | bracketize_ipv6 }}:{{ host_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if host_options.format.include_timezone is vyos_defined }}
{% endif %}
{% else %}
{{ tmp | join(';') }} @{{ host_name | bracketize_ipv6 }}:{{ host_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if host_options.format.include_timezone is vyos_defined }}
{% endif %}
Expand Down
35 changes: 30 additions & 5 deletions smoketest/scripts/cli/test_system_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from base_vyostest_shim import VyOSUnitTestSHIM

from vyos.utils.file import read_file
from vyos.utils.process import cmd
from vyos.utils.process import process_named_running
from vyos.xml_ref import default_value

PROCESS_NAME = 'rsyslogd'
RSYSLOG_CONF = '/etc/rsyslog.d/00-vyos.conf'
Expand Down Expand Up @@ -80,27 +80,52 @@ def test_syslog_basic(self):
self.assertTrue(process_named_running(PROCESS_NAME))

def test_syslog_global(self):
self.cli_set(['system', 'host-name', 'vyos'])
self.cli_set(['system', 'domain-name', 'example.local'])
hostname = 'vyos123'
domainname = 'example.local'
self.cli_set(['system', 'host-name', hostname])
self.cli_set(['system', 'domain-name', domainname])
self.cli_set(base_path + ['global', 'marker', 'interval', '600'])
self.cli_set(base_path + ['global', 'preserve-fqdn'])
self.cli_set(base_path + ['global', 'facility', 'kern', 'level', 'err'])

self.cli_commit()

config = cmd(f'sudo cat {RSYSLOG_CONF}')
config = read_file(RSYSLOG_CONF)
expected = [
'$MarkMessagePeriod 600',
'$PreserveFQDN on',
'kern.err',
'$LocalHostName vyos.example.local',
f'$LocalHostName {hostname}.{domainname}',
]

for e in expected:
self.assertIn(e, config)
# Check for running process
self.assertTrue(process_named_running(PROCESS_NAME))

def test_syslog_remote(self):
rhost = '169.254.0.1'
default_port = default_value(base_path + ['host', rhost, 'port'])

self.cli_set(base_path + ['global', 'facility', 'all', 'level', 'info'])
self.cli_set(base_path + ['global', 'facility', 'local7', 'level', 'debug'])
self.cli_set(base_path + ['host', rhost, 'facility', 'all', 'level', 'all'])
self.cli_set(base_path + ['host', rhost, 'protocol', 'tcp'])

self.cli_commit()

config = read_file(RSYSLOG_CONF)
self.assertIn(f'*.* @@{rhost}:{default_port}', config)

# Change default port and enable "octet-counting" mode
port = '10514'
self.cli_set(base_path + ['host', rhost, 'port', port])
self.cli_set(base_path + ['host', rhost, 'format', 'octet-counted'])
self.cli_commit()

config = read_file(RSYSLOG_CONF)
self.assertIn(f'*.* @@(o){rhost}:{port}', config)


if __name__ == '__main__':
unittest.main(verbosity=2)
Loading