diff options
-rw-r--r-- | data/templates/rsyslog/rsyslog.conf.j2 | 14 | ||||
-rw-r--r-- | interface-definitions/system_syslog.xml.in | 2 | ||||
-rw-r--r-- | smoketest/config-tests/basic-vyos | 8 | ||||
-rw-r--r-- | smoketest/config-tests/bgp-azure-ipsec-gateway | 4 | ||||
-rw-r--r-- | smoketest/config-tests/dialup-router-complex | 2 | ||||
-rw-r--r-- | smoketest/config-tests/dialup-router-medium-vpn | 4 | ||||
-rw-r--r-- | smoketest/config-tests/dialup-router-wireguard-ipv6 | 2 | ||||
-rwxr-xr-x | smoketest/scripts/cli/test_system_syslog.py | 103 | ||||
-rw-r--r-- | src/migration-scripts/system/28-to-29 | 9 |
9 files changed, 90 insertions, 58 deletions
diff --git a/data/templates/rsyslog/rsyslog.conf.j2 b/data/templates/rsyslog/rsyslog.conf.j2 index 21bfbf822..2e3d19afd 100644 --- a/data/templates/rsyslog/rsyslog.conf.j2 +++ b/data/templates/rsyslog/rsyslog.conf.j2 @@ -33,19 +33,19 @@ $outchannel global,/var/log/messages,262144,/usr/sbin/logrotate {{ logrotate }} {{ tmp | join(';') }} /dev/console {% endif %} -{% if host is vyos_defined %} +{% if remote is vyos_defined %} # Remote logging -{% for host_name, host_options in host.items() %} +{% for remote_name, remote_options in remote.items() %} {% set tmp = [] %} -{% if host_options.facility is vyos_defined %} -{% for facility, facility_options in host_options.facility.items() %} +{% if remote_options.facility is vyos_defined %} +{% for facility, facility_options in remote_options.facility.items() %} {% set _ = tmp.append(facility.replace('all', '*') + '.' + facility_options.level.replace('all', '*')) %} {% endfor %} {% endif %} -{% if host_options.protocol is vyos_defined('tcp') %} -{{ 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 }} +{% if remote_options.protocol is vyos_defined('tcp') %} +{{ tmp | join(';') }} @@{{ '(o)' if remote_options.format.octet_counted is vyos_defined }}{{ remote_name | bracketize_ipv6 }}:{{ remote_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if remote_options.format.include_timezone is vyos_defined }} {% else %} -{{ tmp | join(';') }} @{{ host_name | bracketize_ipv6 }}:{{ host_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if host_options.format.include_timezone is vyos_defined }} +{{ tmp | join(';') }} @{{ remote_name | bracketize_ipv6 }}:{{ remote_options.port }}{{ ';RSYSLOG_SyslogProtocol23Format' if remote_options.format.include_timezone is vyos_defined }} {% endif %} {% endfor %} {% endif %} diff --git a/interface-definitions/system_syslog.xml.in b/interface-definitions/system_syslog.xml.in index df9536c3b..68cb11423 100644 --- a/interface-definitions/system_syslog.xml.in +++ b/interface-definitions/system_syslog.xml.in @@ -8,7 +8,7 @@ <priority>400</priority> </properties> <children> - <tagNode name="host"> + <tagNode name="remote"> <properties> <help>Logging to remote host</help> <constraint> diff --git a/smoketest/config-tests/basic-vyos b/smoketest/config-tests/basic-vyos index 6ff28ec2e..b6bb6ac67 100644 --- a/smoketest/config-tests/basic-vyos +++ b/smoketest/config-tests/basic-vyos @@ -96,8 +96,8 @@ set system syslog global facility all level 'info' set system syslog global facility auth level 'info' set system syslog global facility local7 level 'debug' set system syslog global preserve-fqdn -set system syslog host syslog.vyos.net facility auth level 'warning' -set system syslog host syslog.vyos.net facility local7 level 'notice' -set system syslog host syslog.vyos.net format octet-counted -set system syslog host syslog.vyos.net port '8000' +set system syslog remote syslog.vyos.net facility auth level 'warning' +set system syslog remote syslog.vyos.net facility local7 level 'notice' +set system syslog remote syslog.vyos.net format octet-counted +set system syslog remote syslog.vyos.net port '8000' set system time-zone 'Europe/Berlin' diff --git a/smoketest/config-tests/bgp-azure-ipsec-gateway b/smoketest/config-tests/bgp-azure-ipsec-gateway index bbd7b961f..91ec057a9 100644 --- a/smoketest/config-tests/bgp-azure-ipsec-gateway +++ b/smoketest/config-tests/bgp-azure-ipsec-gateway @@ -137,8 +137,8 @@ set system logs logrotate messages rotate '10' set system name-server '192.0.2.254' set system syslog global facility all level 'info' set system syslog global facility local7 level 'debug' -set system syslog host 10.0.9.188 facility all level 'info' -set system syslog host 10.0.9.188 protocol 'udp' +set system syslog remote 10.0.9.188 facility all level 'info' +set system syslog remote 10.0.9.188 protocol 'udp' set system time-zone 'Europe/Berlin' set vpn ipsec authentication psk peer_51-105-0-1 id '51.105.0.1' set vpn ipsec authentication psk peer_51-105-0-1 id '192.0.2.189' diff --git a/smoketest/config-tests/dialup-router-complex b/smoketest/config-tests/dialup-router-complex index c693cc382..404bf342c 100644 --- a/smoketest/config-tests/dialup-router-complex +++ b/smoketest/config-tests/dialup-router-complex @@ -736,5 +736,5 @@ set system option reboot-on-panic set system option startup-beep set system syslog global facility all level 'debug' set system syslog global facility local7 level 'debug' -set system syslog host 172.16.100.1 facility all level 'warning' +set system syslog remote 172.16.100.1 facility all level 'warning' set system time-zone 'Europe/Berlin' diff --git a/smoketest/config-tests/dialup-router-medium-vpn b/smoketest/config-tests/dialup-router-medium-vpn index d6b00c678..b7187887b 100644 --- a/smoketest/config-tests/dialup-router-medium-vpn +++ b/smoketest/config-tests/dialup-router-medium-vpn @@ -315,8 +315,8 @@ set system static-host-mapping host-name host109.vyos.net inet '192.168.0.109' set system sysctl parameter net.core.default_qdisc value 'fq' set system sysctl parameter net.ipv4.tcp_congestion_control value 'bbr' set system syslog global facility all level 'info' -set system syslog host 192.168.0.252 facility all level 'debug' -set system syslog host 192.168.0.252 protocol 'udp' +set system syslog remote 192.168.0.252 facility all level 'debug' +set system syslog remote 192.168.0.252 protocol 'udp' set system task-scheduler task Update-Blacklists executable path '/config/scripts/vyos-foo-update.script' set system task-scheduler task Update-Blacklists interval '3h' set system time-zone 'Pacific/Auckland' diff --git a/smoketest/config-tests/dialup-router-wireguard-ipv6 b/smoketest/config-tests/dialup-router-wireguard-ipv6 index 3e298fb82..e4b8bcac4 100644 --- a/smoketest/config-tests/dialup-router-wireguard-ipv6 +++ b/smoketest/config-tests/dialup-router-wireguard-ipv6 @@ -693,5 +693,5 @@ set system option reboot-on-panic set system option startup-beep set system syslog global facility all level 'debug' set system syslog global facility local7 level 'debug' -set system syslog host 172.16.100.1 facility all level 'warning' +set system syslog remote 172.16.100.1 facility all level 'warning' set system time-zone 'Europe/Berlin' diff --git a/smoketest/scripts/cli/test_system_syslog.py b/smoketest/scripts/cli/test_system_syslog.py index a86711119..961b7a6f4 100755 --- a/smoketest/scripts/cli/test_system_syslog.py +++ b/smoketest/scripts/cli/test_system_syslog.py @@ -53,31 +53,10 @@ class TestRSYSLOGService(VyOSUnitTestSHIM.TestCase): # Check for running process self.assertFalse(process_named_running(PROCESS_NAME)) - def test_syslog_basic(self): - host1 = '127.0.0.10' - host2 = '127.0.0.20' - - self.cli_set(base_path + ['host', host1, 'port', '999']) - self.cli_set(base_path + ['host', host1, 'facility', 'all', 'level', 'all']) - self.cli_set(base_path + ['host', host2, 'facility', 'kern', 'level', 'err']) + def test_syslog_console(self): self.cli_set(base_path + ['console', 'facility', 'all', 'level', 'warning']) - self.cli_commit() - # verify log level and facilities in config file - # *.warning /dev/console - # *.* @198.51.100.1:999 - # kern.err @192.0.2.1:514 - config = [ - get_config_value('\*.\*'), - get_config_value('kern.err'), - get_config_value('\*.warning'), - ] - expected = [f'@{host1}:999', f'@{host2}:514', '/dev/console'] - - for i in range(0, 3): - self.assertIn(expected[i], config[i]) - # Check for running process - self.assertTrue(process_named_running(PROCESS_NAME)) + self.assertIn('/dev/console', get_config_value('\*.warning')) def test_syslog_global(self): hostname = 'vyos123' @@ -100,32 +79,76 @@ class TestRSYSLOGService(VyOSUnitTestSHIM.TestCase): 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']) + rhosts = { + '169.254.0.1': { + 'facility': {'name' : 'auth', 'level': 'info'}, + 'protocol': 'udp', + }, + '169.254.0.2': { + 'port': '1514', + 'protocol': 'udp', + }, + '169.254.0.3': { + 'format': ['include-timezone', 'octet-counted'], + 'protocol': 'tcp', + }, + } + default_port = default_value(base_path + ['remote', next(iter(rhosts)), 'port']) + + for remote, remote_options in rhosts.items(): + remote_base = base_path + ['remote', remote] + + if 'port' in remote_options: + self.cli_set(remote_base + ['port', remote_options['port']]) + + if ('facility' in remote_options and + 'name' in remote_options['facility'] and + 'level' in remote_options['facility'] + ): + facility = remote_options['facility']['name'] + level = remote_options['facility']['level'] + self.cli_set(remote_base + ['facility', facility, 'level', level]) + + if 'format' in remote_options: + for format in remote_options['format']: + self.cli_set(remote_base + ['format', format]) + + if 'protocol' in remote_options: + protocol = remote_options['protocol'] + self.cli_set(remote_base + ['protocol', protocol]) self.cli_commit() config = read_file(RSYSLOG_CONF) - self.assertIn(f'*.* @@{rhost}:{default_port}', config) + for remote, remote_options in rhosts.items(): + tmp = ' ' + if ('facility' in remote_options and + 'name' in remote_options['facility'] and + 'level' in remote_options['facility'] + ): + facility = remote_options['facility']['name'] + level = remote_options['facility']['level'] + tmp = f'{facility}.{level} ' - # 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() + tmp += '@' + if 'protocol' in remote_options and remote_options['protocol'] == 'tcp': + tmp += '@' - config = read_file(RSYSLOG_CONF) - self.assertIn(f'*.* @@(o){rhost}:{port}', config) + if 'format' in remote_options and 'octet-counted' in remote_options['format']: + tmp += '(o)' + + port = default_port + if 'port' in remote_options: + port = remote_options['port'] + + tmp += f'{remote}:{port}' + + if 'format' in remote_options and 'include-timezone' in remote_options['format']: + tmp += ';RSYSLOG_SyslogProtocol23Format' + self.assertIn(tmp, config) if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/src/migration-scripts/system/28-to-29 b/src/migration-scripts/system/28-to-29 index b8439100a..2f55d425a 100644 --- a/src/migration-scripts/system/28-to-29 +++ b/src/migration-scripts/system/28-to-29 @@ -30,3 +30,12 @@ def migrate(config: ConfigTree) -> None: if config.exists(base + ['user']): config.delete(base + ['user']) + + # rename host -> remote + if config.exists(base + ['host']): + config.set(base + ['remote']) + config.set_tag(base + ['remote']) + for remote in config.list_nodes(base + ['host']): + config.copy(base + ['host', remote], base + ['remote', remote]) + config.set_tag(base + ['remote']) + config.delete(base + ['host']) |