Skip to content

Commit

Permalink
syslog: T6989: move up "preserve-fqdn" on level in CLI
Browse files Browse the repository at this point in the history
Move "global preserve-fqdn" one CLI level up, as it relates to all logging
targets (console, global and remote).
  • Loading branch information
c-po committed Jan 15, 2025
1 parent b7ad581 commit c72d417
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
8 changes: 4 additions & 4 deletions data/templates/rsyslog/rsyslog.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ global(workDirectory="/var/spool/rsyslog")
# Load the immark module for periodic --MARK-- message capability
module(load="immark" interval="{{ global.marker.interval }}")
{% endif %}
{% if global.preserve_fqdn is vyos_defined %}
{% if preserve_fqdn is vyos_defined %}
# Preserve the fully qualified domain name (FQDN) in log messages
global(preserveFQDN="on")
{% endif %}
{% if global.local_host_name is vyos_defined %}
{% if preserve_fqdn.host_name is vyos_defined and preserve_fqdn.domain_name is vyos_defined %}
# Set the local hostname for log messages
global(localHostname="{{ global.local_host_name }}")
global(localHostname="{{ preserve_fqdn.host_name }}.{{ preserve_fqdn.domain_name }}")
{% endif %}
{% endif %}

#### GLOBAL LOGGING ####
Expand Down
24 changes: 12 additions & 12 deletions interface-definitions/system_syslog.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<priority>400</priority>
</properties>
<children>
<node name="console">
<properties>
<help>Log to system console (/dev/console)</help>
</properties>
<children>
#include <include/syslog-facility.xml.i>
</children>
</node>
<tagNode name="remote">
<properties>
<help>Log to remote host</help>
Expand Down Expand Up @@ -84,22 +92,14 @@
</leafNode>
</children>
</node>
<leafNode name="preserve-fqdn">
<properties>
<help>uses FQDN for logging</help>
<valueless/>
</properties>
</leafNode>
</children>
</node>
<node name="console">
<leafNode name="preserve-fqdn">
<properties>
<help>Log to system console (/dev/console)</help>
<help>Always include domain portion in hostname</help>
<valueless/>
</properties>
<children>
#include <include/syslog-facility.xml.i>
</children>
</node>
</leafNode>
#include <include/source-address-ipv4-ipv6.xml.i>
#include <include/interface/vrf.xml.i>
</children>
Expand Down
2 changes: 1 addition & 1 deletion smoketest/scripts/cli/test_system_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_global(self):

self.cli_set(['system', 'host-name', hostname])
self.cli_set(['system', 'domain-name', domain_name])
self.cli_set(base_path + ['global', 'preserve-fqdn'])
self.cli_set(base_path + ['preserve-fqdn'])

for tmp, tmp_options in facility.items():
level = tmp_options['level']
Expand Down
23 changes: 13 additions & 10 deletions src/conf_mode/system_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,26 @@ def get_config(config=None):
if syslog.from_defaults(['global']):
del syslog['global']

if (
'global' in syslog
and 'preserve_fqdn' in syslog['global']
and conf.exists(['system', 'host-name'])
and conf.exists(['system', 'domain-name'])
):
hostname = conf.return_value(['system', 'host-name'])
domain = conf.return_value(['system', 'domain-name'])
fqdn = f'{hostname}.{domain}'
syslog['global']['local_host_name'] = fqdn
if 'preserve_fqdn' in syslog:
if conf.exists(['system', 'host-name']):
tmp = conf.return_value(['system', 'host-name'])
syslog['preserve_fqdn']['host_name'] = tmp
if conf.exists(['system', 'domain-name']):
tmp = conf.return_value(['system', 'domain-name'])
syslog['preserve_fqdn']['domain_name'] = tmp

return syslog

def verify(syslog):
if not syslog:
return None

if 'preserve_fqdn' in syslog:
if 'host_name' not in syslog['preserve_fqdn']:
Warning('No "system host-name" defined - cannot set syslog FQDN!')
if 'domain_name' not in syslog['preserve_fqdn']:
Warning('No "system domain-name" defined - cannot set syslog FQDN!')

if 'remote' in syslog:
for host, host_options in syslog['remote'].items():
if 'protocol' in host_options and host_options['protocol'] == 'udp':
Expand Down
7 changes: 7 additions & 0 deletions src/migration-scripts/system/28-to-29
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# T6989:
# - remove syslog arbitrary file logging
# - remove syslog user console logging
# - move "global preserve-fqdn" one CLI level up
# - rename "host" to "remote"

from vyos.configtree import ConfigTree
Expand All @@ -34,6 +35,12 @@ def migrate(config: ConfigTree) -> None:
if config.exists(base + ['user']):
config.delete(base + ['user'])

# Move "global preserve-fqdn" one CLI level up, as it relates to all
# logging targets (console, global and remote)
if config.exists(base + ['global', 'preserve-fqdn']):
config.delete(base + ['global', 'preserve-fqdn'])
config.set(base + ['preserve-fqdn'])

# Rename host x.x.x.x -> remote x.x.x.x
if config.exists(base + ['host']):
config.set(base + ['remote'])
Expand Down

0 comments on commit c72d417

Please sign in to comment.