diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-08-17 18:45:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 18:45:57 +0200 |
commit | 2357a5e412ee76b7aa0cdc0335a756a9ca71b1e9 (patch) | |
tree | b18603430faf622d3fd98138b864b09f52d8c862 | |
parent | 6fbc60b4fa09f65ab7f3c28adcdd65010df5873e (diff) | |
parent | d6992db2b79b2fd49707e5b0c23eb62421368f52 (diff) | |
download | vyos-1x-2357a5e412ee76b7aa0cdc0335a756a9ca71b1e9.tar.gz vyos-1x-2357a5e412ee76b7aa0cdc0335a756a9ca71b1e9.zip |
Merge pull request #527 from zdc/T2332-crux
Syslog: T2332: Added port to syslog server options
-rw-r--r-- | interface-definitions/syslog.xml | 31 | ||||
-rwxr-xr-x | src/conf_mode/syslog.py | 79 |
2 files changed, 67 insertions, 43 deletions
diff --git a/interface-definitions/syslog.xml b/interface-definitions/syslog.xml index 1b119bfcc..e462412d9 100644 --- a/interface-definitions/syslog.xml +++ b/interface-definitions/syslog.xml @@ -10,9 +10,9 @@ <children> <tagNode name="user"> <properties> - <help>Logging to specific user's terminal</help> + <help>Logging to specific terminal of given user</help> <constraint> - <regex>^[a-z_][a-z0-9_-]{1,31}[$]?</regex> + <regex>[a-z_][a-z0-9_-]{1,31}[$]?</regex> </constraint> <constraintErrorMessage>illegal characters in user</constraintErrorMessage> <valueHelp> @@ -184,7 +184,7 @@ <validator name="ip-address"/> <validator name="fqdn"/> </constraint> - <constraintErrorMessage>Invalid host FQDN or IP address</constraintErrorMessage> + <constraintErrorMessage>Invalid host (FQDN or IP address)</constraintErrorMessage> <valueHelp> <format>ipv4</format> <description>Remote syslog server IPv4 address</description> @@ -195,6 +195,19 @@ </valueHelp> </properties> <children> + <leafNode name="port"> + <properties> + <help>Destination port</help> + <valueHelp> + <format>1-65535</format> + <description>Destination port</description> + </valueHelp> + <constraint> + <validator name="numeric" argument="--range 1-65535"/> + </constraint> + <constraintErrorMessage>Invalid destination port value</constraintErrorMessage> + </properties> + </leafNode> <tagNode name="facility"> <properties> <help>Facility for logging</help> @@ -308,7 +321,7 @@ </valueHelp> <valueHelp> <format>tcp</format> - <description>send log messages to remote syslog server over tdp</description> + <description>send log messages to remote syslog server over tcp</description> </valueHelp> <completionHelp> <list>udp tcp</list> @@ -385,7 +398,7 @@ <properties> <help>Number of saved files (default is 5)</help> <constraint> - <regex>^[0-9]+</regex> + <regex>[0-9]+</regex> </constraint> <constraintErrorMessage>illegal characters in number of files</constraintErrorMessage> </properties> @@ -394,7 +407,7 @@ <properties> <help>Size of log files (in kbytes, default is 256)</help> <constraint> - <regex>^[0-9]+</regex> + <regex>[0-9]+</regex> </constraint> <constraintErrorMessage>illegal characters in size</constraintErrorMessage> </properties> @@ -582,7 +595,7 @@ <properties> <help>Logging to a file</help> <constraint> - <regex>^[a-zA-Z0-9\-_.]{1,255}</regex> + <regex>[a-zA-Z0-9\-_.]{1,255}</regex> </constraint> <constraintErrorMessage>illegal characters in filename or filename longer than 255 characters</constraintErrorMessage> </properties> @@ -596,7 +609,7 @@ <properties> <help>Number of saved files (default is 5)</help> <constraint> - <regex>^[0-9]+</regex> + <regex>[0-9]+</regex> </constraint> <constraintErrorMessage>illegal characters in number of files</constraintErrorMessage> </properties> @@ -605,7 +618,7 @@ <properties> <help>Size of log files (in kbytes, default is 256)</help> <constraint> - <regex>^[0-9]+</regex> + <regex>[0-9]+</regex> </constraint> <constraintErrorMessage>illegal characters in size</constraintErrorMessage> </properties> diff --git a/src/conf_mode/syslog.py b/src/conf_mode/syslog.py index c4f3d2c9c..b3876164c 100755 --- a/src/conf_mode/syslog.py +++ b/src/conf_mode/syslog.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2018 VyOS maintainers and contributors +# Copyright (C) 2018-2020 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -13,13 +13,12 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# -import sys + import os import re import jinja2 +from sys import exit from vyos.config import Config from vyos import ConfigError @@ -53,10 +52,18 @@ $outchannel {{file}},{{files[file]['log-file']}},{{files[file]['max-size']}},{{f ## remote logging {% for host in hosts %} {% if hosts[host]['proto'] == 'tcp' %} +{% if hosts[host]['port'] %} +{{hosts[host]['selectors']}} @@{{host}}:{{hosts[host]['port']}} +{% else %} {{hosts[host]['selectors']}} @@{{host}} +{% endif %} +{% else %} +{% if hosts[host]['port'] %} +{{hosts[host]['selectors']}} @{{host}}:{{hosts[host]['port']}} {% else %} {{hosts[host]['selectors']}} @{{host}} {% endif %} +{% endif %} {% endfor %} {% endif %} {% if user %} @@ -177,13 +184,14 @@ def get_config(): # set system syslog host if c.exists('host'): - proto = 'udp' rhosts = c.list_nodes('host') for rhost in rhosts: for fac in c.list_nodes('host ' + rhost + ' facility'): if c.exists('host ' + rhost + ' facility ' + fac + ' protocol'): proto = c.return_value( 'host ' + rhost + ' facility ' + fac + ' protocol') + else: + proto = 'udp' config_data['hosts'].update( { @@ -193,6 +201,9 @@ def get_config(): } } ) + if c.exists('host ' + rhost + ' port'): + config_data['hosts'][rhost][ + 'port'] = c.return_value('host ' + rhost + ' port') # set system syslog user if c.exists('user'): @@ -213,32 +224,31 @@ def generate_selectors(c, config_node): # protocols and security are being mapped here # for backward compatibility with old configs # security and protocol mappings can be removed later - if c.is_tag(config_node): - nodes = c.list_nodes(config_node) - selectors = "" - for node in nodes: - lvl = c.return_value(config_node + ' ' + node + ' level') - if lvl == None: - lvl = "err" - if lvl == 'all': - lvl = '*' - if node == 'all' and node != nodes[-1]: - selectors += "*." + lvl + ";" - elif node == 'all': - selectors += "*." + lvl - elif node != nodes[-1]: - if node == 'protocols': - node = 'local7' - if node == 'security': - node = 'auth' - selectors += node + "." + lvl + ";" - else: - if node == 'protocols': - node = 'local7' - if node == 'security': - node = 'auth' - selectors += node + "." + lvl - return selectors + nodes = c.list_nodes(config_node) + selectors = "" + for node in nodes: + lvl = c.return_value(config_node + ' ' + node + ' level') + if lvl == None: + lvl = "err" + if lvl == 'all': + lvl = '*' + if node == 'all' and node != nodes[-1]: + selectors += "*." + lvl + ";" + elif node == 'all': + selectors += "*." + lvl + elif node != nodes[-1]: + if node == 'protocols': + node = 'local7' + if node == 'security': + node = 'auth' + selectors += node + "." + lvl + ";" + else: + if node == 'protocols': + node = 'local7' + if node == 'security': + node = 'auth' + selectors += node + "." + lvl + return selectors def generate(c): @@ -261,7 +271,8 @@ def generate(c): def verify(c): if c == None: return None - # + + # may be obsolete # /etc/rsyslog.conf is generated somewhere and copied over the original (exists in /opt/vyatta/etc/rsyslog.conf) # it interferes with the global logging, to make sure we are using a single base, template is enforced here # @@ -273,6 +284,7 @@ def verify(c): # /var/log/vyos-rsyslog were the old files, we may want to clean those up, but currently there # is a chance that someone still needs it, so I don't automatically remove # them + # if c == None: return None @@ -289,7 +301,6 @@ def verify(c): for s in c[conf][item]['selectors'].split(";"): f = re.sub("\..*$", "", s) if f not in fac: - print (c[conf]) raise ConfigError( 'Invalid facility ' + s + ' set in ' + conf + ' ' + item) l = re.sub("^.+\.", "", s) @@ -317,4 +328,4 @@ if __name__ == '__main__': apply(c) except ConfigError as e: print(e) - sys.exit(1) + exit(1) |