summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-12-04 15:33:59 +0000
committerGitHub <noreply@github.com>2025-12-04 15:33:59 +0000
commit0544895af02cbc0ff882cded3c2774469a41cbc7 (patch)
treea8baf9717043549b0106f72984d1b887f6ceeb12
parenta6ab36aab78a0f5f9b1d3f58185b1f71cee41b3d (diff)
parent4b9a008b24eafbb3bc0f81578ed22e96e2d72b6f (diff)
downloadvyos-1x-0544895af02cbc0ff882cded3c2774469a41cbc7.tar.gz
vyos-1x-0544895af02cbc0ff882cded3c2774469a41cbc7.zip
Merge pull request #4886 from dmbaturin/T8059-migrate-syslog-ports
syslog: T8059: migrate host:port node names to the new syntax with a dedicated port option
-rw-r--r--smoketest/config-tests/basic-syslog3
-rw-r--r--smoketest/configs/basic-syslog7
-rw-r--r--src/migration-scripts/system/28-to-2945
3 files changed, 50 insertions, 5 deletions
diff --git a/smoketest/config-tests/basic-syslog b/smoketest/config-tests/basic-syslog
index 349d642fd..a8acc18e9 100644
--- a/smoketest/config-tests/basic-syslog
+++ b/smoketest/config-tests/basic-syslog
@@ -22,4 +22,7 @@ set system syslog remote syslog02.vyos.net format octet-counted
set system syslog remote syslog02.vyos.net port '8001'
set system syslog remote syslog02.vyos.net protocol 'tcp'
set system syslog remote syslog02.vyos.net vrf 'red'
+set system syslog remote syslog03.vyos.net facility local7 level 'notice'
+set system syslog remote syslog03.vyos.net port '9000'
+set system syslog remote syslog03.vyos.net vrf 'red'
set vrf name red table '12321'
diff --git a/smoketest/configs/basic-syslog b/smoketest/configs/basic-syslog
index 9336b73bc..1812adbcd 100644
--- a/smoketest/configs/basic-syslog
+++ b/smoketest/configs/basic-syslog
@@ -56,6 +56,11 @@ system {
protocol tcp
port 8001
}
+ host syslog03.vyos.net:9000 {
+ facility local7 {
+ level notice
+ }
+ }
vrf red
}
}
@@ -67,4 +72,4 @@ vrf {
// Warning: Do not remove the following line.
// vyos-config-version: "bgp@5:broadcast-relay@1:cluster@2:config-management@1:conntrack@5:conntrack-sync@2:container@2:dhcp-relay@2:dhcp-server@8:dhcpv6-server@1:dns-dynamic@4:dns-forwarding@4:firewall@15:flow-accounting@1:https@6:ids@1:interfaces@32:ipoe-server@3:ipsec@13:isis@3:l2tp@9:lldp@2:mdns@1:monitoring@1:nat@8:nat66@3:ntp@3:openconnect@3:ospf@2:pim@1:policy@8:pppoe-server@10:pptp@5:qos@2:quagga@11:reverse-proxy@1:rip@1:rpki@2:salt@1:snmp@3:ssh@2:sstp@6:system@27:vrf@3:vrrp@4:vyos-accel-ppp@2:wanloadbalance@3:webproxy@2"
-// Release version: 1.4.0
+// Release version: 1.3.8
diff --git a/src/migration-scripts/system/28-to-29 b/src/migration-scripts/system/28-to-29
index 310feaa2f..7d912b612 100644
--- a/src/migration-scripts/system/28-to-29
+++ b/src/migration-scripts/system/28-to-29
@@ -18,6 +18,16 @@
# - remove syslog user console logging
# - move "global preserve-fqdn" one CLI level up
# - rename "host" to "remote"
+#
+# T8059:
+# - if a syslog remote contains a port (like 192.0.2.1:9000),
+# migrate the port part to the new dedicated "port" option
+#
+# XXX: this script leads to data loss when a config
+# has multiple remotes with the same host address but different ports.
+# That issue needs to be addressed separately (T8058)
+
+import re
from vyos.configtree import ConfigTree
@@ -64,8 +74,35 @@ def migrate(config: ConfigTree) -> None:
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'])
- if vrf:
- config.set(base + ['remote', remote, 'vrf'], value=vrf)
+ # Check if the host address has a port
+ # to migrate the port part to the new dedicated "port" option
+ res = re.match(r'(?P<host>[^:]+):(?P<port>.*)', remote)
+ if res:
+ remote_host = res.group('host')
+ remote_port = res.group('port')
+ else:
+ remote_host = remote
+ remote_port = None
+
+ # XXX: the fact that it was possible to use node names like "192.0.2.1:9000"
+ # made it possible to create configurations that would send different messages
+ # to different ports on the same server.
+ # At the moment, such configurations are unsupported
+ # so the script only keeps one of such remotes.
+ if config.exists(base + ['remote', remote_host]):
+ # Skip the remote if it already exists
+ # XXX: This tacitly implies that if multiple remotes
+ # with the same address but different ports are used,
+ # only the first one of those makes it into the migrated config.
+ continue
+ else:
+ config.copy(base + ['host', remote], base + ['remote', remote_host])
+
+ if remote_port:
+ config.set(base + ['remote', remote_host, 'port'], value=remote_port)
+
+ config.set_tag(base + ['remote'])
+ if vrf:
+ config.set(base + ['remote', remote_host, 'vrf'], value=vrf)
+
config.delete(base + ['host'])