diff options
author | Christian Poessinger <christian@poessinger.com> | 2018-05-21 19:52:40 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2018-06-04 19:19:29 +0200 |
commit | 0d72ed94a46a655cbc0ff9e32d258fbee3e9f330 (patch) | |
tree | d6f4be7da7f587160803b23d345b0291cbf885b4 /src/conf_mode | |
parent | f12cab5ed3ffeb8a4c34cb874cc05a1cd381ba14 (diff) | |
download | vyos-1x-0d72ed94a46a655cbc0ff9e32d258fbee3e9f330.tar.gz vyos-1x-0d72ed94a46a655cbc0ff9e32d258fbee3e9f330.zip |
snmp.py: refactor listen-address config generation
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-x | src/conf_mode/snmp.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py index 80f3bee8c..227c00335 100755 --- a/src/conf_mode/snmp.py +++ b/src/conf_mode/snmp.py @@ -92,7 +92,7 @@ SysDescr {{ description }} {% endif %} # Listen -agentaddress unix:/run/snmpd.socket{% for ip in listen_on %},{{ ip.prot }}:{{ ip.addr }}:{{ ip.port }}{% endfor %} +agentaddress unix:/run/snmpd.socket{% for li in listen_on %},{{ li }}{% endfor %} # SNMP communities @@ -172,20 +172,19 @@ def get_config(): if conf.exists('listen-address'): for addr in conf.list_nodes('listen-address'): - prot = "udp" - if ipaddress.ip_address(addr).version == 6: - # SNMP configuration file requires brackets on IPv6 addresses - addr = "[" + addr + "]" - prot = "udp6" - - listen = { - 'addr': addr, - 'prot': prot, - 'port': '161' - } - + listen = '' + port = '161' if conf.exists('listen-address {0} port'.format(addr)): - listen['port'] = conf.return_value('listen-address {0} port'.format(addr)) + port = conf.return_value('listen-address {0} port'.format(addr)) + + if ipaddress.ip_address(addr).version == 4: + # udp:127.0.0.1:161 + listen = 'udp:' + addr + ':' + port + elif ipaddress.ip_address(addr).version == 6: + # udp6:[::1]:161 + listen = 'udp6:' + '[' + addr + ']' + ':' + port + else: + raise ConfigError('Invalid IP address version') snmp['listen_on'].append(listen) |